[Tex/LaTex] Tikz drawing with function


I wanna know a clear way to code the function while drawing with it, for ex. how to write this f(x)= -(x+1)(x-2)(x-4)

how to code it in the below command?

\draw [red,ultra thick,domain=-1:2,samples=400,latex-latex] plot (\x,---);

Please there is any clear coding way for these cases?

i tried but it in -5(x + 3)(x-1)(x-2)(x-7) but it didn't work

please wanna coding way for the functions like sin(x) or tan(x)

Best Answer


\draw[very thin,color=black] (-0,-0) grid (4,4);

\draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};

\draw[blue] (0,0) plot[domain=2:4] (\x,{-(\x+1)*(\x-2)*(\x-4)}) node[anchor=south west] {$V_{p}$};


enter image description here