3

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)

  • Please have a look at the pgfplots package. I guess that you are a total beginner. In that case, I recommend reading an introduction to LaTex first (I recommend a recent book). – Dr. Manuel Kuehner Dec 5 '17 at 9:39
  • @MarwaHashem is your question solved? Would you accept an answer? – Bobyandbob Sep 24 '18 at 9:11
3
\documentclass[a4paper]{article}
 \usepackage{tikz}


\begin{document}
\begin{tikzpicture}
\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}$};


\end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||
  • i tried but it in -5(x + 3)(x-1)(x-2)(x-7) but it didn't work – Marwa Hashem Dec 5 '17 at 8:30
  • @MarwaHashem You need to have * between them to express multiplication, i.e. -5*(x+3)*(x-1)*(x-2)*(x-7). – user156344 Apr 1 '19 at 10:44
3

A simple way using pgfplots for your function -5(x + 3)(x-1)(x-2)(x-7):

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.8}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        domain     = -5:8,
        ymin       = -2000,
        ymax       =  2000,
        samples    = 50,
        axis lines = middle
      ]
    \addplot [mark = none, color = blue]
      {-5*(x + 3)*(x-1)*(x-2)*(x-7)};
  \end{axis}
\end{tikzpicture}
\end{document}

Plot

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.