TransWikia.com

TikZ won't show the good curve?

TeX - LaTeX Asked on December 17, 2021

Hello wonderful people,

TikZ doesn’t seem to display the function it should be, I might be missing a dumb point, but here’s the problem:

First, let’s take a look at this marvellous function:
Plot with GeoGebra
polynomial, arousing curves, cuts the x-axis in (almost) integer points, this function just seems too good to be true.

Now, look at this smooth code :

documentclass{article}

usepackage{tikz}

begin{document}

begin{tikzpicture}
  draw [gray,dotted] (-6,-5) grid (5,5) ;
  draw[->,>=latex] (-6,0) -- (5,0) node[below]{$x$} ;
  draw[->,>=latex] (0,-5) -- (0,5) node[left]{$y$} ;

  draw [domain=-5:4,samples=200] plot (x,-0.0012*x^5-0.0131*x^4+0.0893*x^3+0.3988*x^2-0.5881*x-0.8857) ;
end{tikzpicture}

end{document}

simple, efficient, should do the work and show us this gorgeous function we’ve been talking about for minutes now.

But, alas! Look at the disastrous result it produces:
Plot with TikZ

Does anyone know why TikZ would want to crush my dreams of happiness like this? A "funny" thing is that it seems to be ok with the positive values of x(?)

Thanks a lot!

One Answer

I am not quite sure why, but for some reason the even powers seem to be acting weird. When using the function as follows, the graph looks fine:

begin{tikzpicture}
  draw [gray,dotted] (-6,-5) grid (5,5) ;
  draw[->,>=latex] (-6,0) -- (5,0) node[below]{$x$} ;
  draw[->,>=latex] (0,-5) -- (0,5) node[left]{$y$} ;

  draw [domain=-5:4,samples=200] plot (x,-0.0012*x^5-0.0131*x*x*x*x+0.0893*x^3+0.3988*x*x-0.5881*x-0.8857) ;
end{tikzpicture}

EDIT: fixed it using the following post: How can I work around this TikZ bug: (x)^2 and x^2 produce different results in TikZ plot?. Using the following code fixes it completely.

begin{tikzpicture}
  draw [gray,dotted] (-6,-5) grid (5,5) ;
  draw[->,>=latex] (-6,0) -- (5,0) node[below]{$x$} ;
  draw[->,>=latex] (0,-5) -- (0,5) node[left]{$y$} ;

  draw [domain=-5:4,samples=200] plot (x,{-0.0012*x^5-0.0131*(x)^4+0.0893*x^3+0.3988*(x)^2-0.5881*x-0.8857}) ;
end{tikzpicture}

Answered by G. de Man on December 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP