I am trying to set up ymin and ymax to a `tikzpicture`. In this code, I input by hand
```
ymin=-1 ; ymax=max(y1,y2) + 1;
```
```
\documentclass[12pt,a4paper]{article}
\usepackage[left=2cm, right=2cm, top=2cm, bottom=2cm]{geometry}
\usepackage{fouriernc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18
}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amsthm}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}[>=stealth,scale =1,declare function={a=1;b=-6;c=9;d=2;
f(\x)=(a*\x*\x*\x+b*\x*\x+c*\x+d);
x1=(-b - sqrt(b^2 - 3* a* c))/(3*a);
x2=(-b + sqrt(b^2 - 3* a* c))/(3*a);
y1=(2* b^3 - 9* a* b *c + 2* b^2 *sqrt(b^2 - 3 *a *c) -
6* a* c* sqrt(b^2 - 3* a *c) + 27* a^2 *d)/(27 *a^2);
y2=(2* b^3 - 9* a* b *c - 2* b^2 *sqrt(b^2 - 3 *a *c) +
6* a* c* sqrt(b^2 - 3* a *c) + 27* a^2 *d)/(27 *a^2);
x0=(x1+x2)/2;
y0=(y1+y2)/2;
xr=2*x2-x0;
xl=2*x1-x0;
xmin=xl-1;xmax=xr+1;
ymin=-1 ; ymax=max(y1,y2) + 1;
}]
\draw[gray!30] (xmin,ymin) grid (xmax,ymax); % grid
\draw[->, thick] (xmin,0)--(xmax,0) node [below left]{$x$};
\draw[->,thick] (0,ymin)--(0,ymax) node [below right]{$y$}; %vẽ trục tung
\foreach \X in {x1,x2,xr,xl,x0} {\draw[dashed] (\X,0) |- (0,{f(\X)}); }
\node[below right] at (0, 0) {$O$};
\foreach \Y in {x1,x2,0,x0,xr} \fill (\Y,{f(\Y)}) circle(2pt);
\foreach \p/\g [evaluate=\p] in {x1/-90,x2/-90,xr/-90,x0/-90}{%
\draw(\p,0)node[shift={(\g:.3)}]{$\pgfmathroundto{\p}\pgfmathresult$};}
\foreach \p/\g in {x1/180,x2/180,x0/180}{%
\pgfmathparse{f(\p)}
\draw(0,\pgfmathresult)node[shift={(\g:.3)}]{$\pgfmathroundto{\pgfmathresult}\pgfmathresult$};
}
\clip (xmin,ymin) rectangle (xmax,ymax);
\draw[smooth,samples=500,very thick,blue,domain=xmin:xmax] plot(\x,{f(\x)});
\end{tikzpicture}
\end{figure}
\end{document}
```
![image.png](/image?hash=1de173ebd9ef8ce009110f9550e91333edec70c5c59a21d76118a2085c8af1b5)
In general, I want to make a code `\ifnum` like this
* If `min(y1,y2) > 0` or `min(y1,y2) =0` then `ymin=-1 ; ymax=max(y1,y2) + 1;`
* If `max(y1,y2) < 0` then `ymin = min(y1,y2) - 1`, ` ymax= 1;`
* If `y1*y2<0` then `ymin = min(y1,y2) - 1` and `ymax=max(y1,y2) + 1;`
How can I write that code and input to my document?