1

I have the following code

\begin{tikzpicture}[domain=0:10]
    \begin{scope}[xshift=4cm, scale=1]

\draw[->] (-0.2,0) -- (10.5,0) node[right] {$x$}; 
\draw[->] (0,-0.5) -- (0,6.5) node[above] {$f(x)$}; 
\draw[color=red] plot (\x,{0.0018 *pow(\x,3)-0.0728* pow(\x,2)+0.8947
*\x+1.0173}) ;
 \draw[color=blue,domain=8:10] plot (\x,{-0.0001109 *(\x)^5+0.0041994*(\x)^4-

0.060293* (\x)^3+0.43576 *(\x)^2-1.80134* (\x)+5.3364}) ;


\end {scope}
\end{tikzpicture}

It gives me the following picture:

enter image description here

It just doesn't make sense, it it supposed to look like that:

enter image description here

Can somebody help me?

1
  • can you add the matlab version of the code?
    – percusse
    Commented Nov 23, 2017 at 16:16

1 Answer 1

1

You should use PGFPlots instead of drawing the coordinate system on your own.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

    \begin{tikzpicture}
    \begin{axis}[domain=0:10, axis y line = middle, axis x line = middle]
    \addplot[red] {0.0018 * pow(x,3)-0.0728* pow(x,2)+0.8947
        *x+1.0173};
    \addplot[blue, domain=8:10] {-0.0001109 *(x)^5+0.0041994*(x)^4-0.060293* (x)^3+0.43576 *(x)^2-1.80134* (x)+5.3364};
    \end{axis}
    \end{tikzpicture}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .