
Temos esse código TikZ e foi dito que isso dá um resultado diferente do geogebra (https://artofproblemsolving.com/community/c68h3228155_need_help_with_tikz):
\begin{tikzpicture}[scale=.5]
\draw[->] (-3,0)--(5,0) node[below]{$x$};
\draw[->] (0,-7)--(0,3) node[left]{$y$};
\draw[thick, domain=-1.5:2] plot(\x, {2.8*\x^4+4.77*\x^3-5.47*\x^2-7.61*\x});
\end{tikzpicture}
Além disso, a assíntota dá outro resultado como o TikZ, veja a postagem nº 2 no link acima.
O que pode ser melhorado no TikZ?
Responder1
O problema está na expansão/precedência do -
ao expandir \x
. Você pode usarA solução da @Skillmonou adicione parênteses:
\documentclass[border=3.14,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5]
\draw[->] (-3,0)--(5,0) node[below]{$x$};
\draw[->] (0,-7)--(0,3) node[left]{$y$};
\draw[thick, red, domain=-1.5:2] plot(\x, {2.8*(\x)^4+4.77*(\x)^3-5.47*(\x)^2-7.61*(\x)});
\draw[thick, dotted, domain=-1.5:2] plot(\x, {2.8*\x*\x*\x*\x+4.77*\x*\x*\x-5.47*\x*\x-7.61*\x});
\end{tikzpicture}
\end{document}
O problema da precedência do sinal fica ainda mais evidente se você fizer isso:
\documentclass[border=3.14,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5]
\draw[->] (-3,0)--(5,0) node[below]{$x$};
\draw[->] (0,-7)--(0,3) node[left]{$y$};
\draw[thick, red, domain=-1.5:2] plot(\x, {\x^2});
\draw[thick, dotted, domain=-1.5:2] plot(\x, {(\x)^2});
\end{tikzpicture}
\end{document}
Parece que quando, digamos, \x^2
é expandido e o valor é negativo, digamos -2, você obtém -2^2
, que é interpretado como -4
.
Responder2
TikZ tem problemas com a função expoente, use \x*\x*\x*\x
em vez de \x^4
, etc.:
\documentclass[border=3.14,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5]
\draw[->] (-3,0)--(5,0) node[below]{$x$};
\draw[->] (0,-7)--(0,3) node[left]{$y$};
\draw[thick, domain=-1.5:2] plot(\x, {2.8*\x*\x*\x*\x+4.77*\x*\x*\x-5.47*\x*\x-7.61*\x});
\end{tikzpicture}
\end{document}
Para melhorar ainda mais: reduza domain
(sua função avaliada em x = 2 é igual a 45,86), aumente samples
e talvez use smooth
.
\documentclass[border=3.14,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5]
\draw[->] (-3,0)--(5,0) node[below]{$x$};
\draw[->] (0,-7)--(0,3) node[left]{$y$};
\draw[thin, red, domain=-1.5:1.5, samples=101, smooth] plot(\x, {2.8*\x*\x*\x*\x+4.77*\x*\x*\x-5.47*\x*\x-7.61*\x});
\end{tikzpicture}
\end{document}
Se você ainda tiver problemas numéricos com sua função (não é o caso desta função, mas pode acontecer), você pode querer usar o pgfmath-xfp
pacote. Isso torna seus gráficos um pouco mais lentos, mas o uso de funções definidas com ele fornece uma resolução muito melhor:
\documentclass[border=3.14,tikz]{standalone}
\usepackage{pgfmath-xfp}
\begin{document}
\begin{tikzpicture}[scale=.5]
\draw[->] (-3,0)--(5,0) node[below]{$x$};
\draw[->] (0,-7)--(0,3) node[left]{$y$};
\draw[red, domain=-1.5:1.5, samples=101, smooth] plot(\x, {2.8*\x*\x*\x*\x+4.77*\x*\x*\x-5.47*\x*\x-7.61*\x});
\pgfmxfpdeclarefunction{myfunction}{1}
{2.8*(#1)^4+4.77*(#1)^3-5.47*(#1)^2-7.61*(#1)}
\draw[very thin, blue, domain=-1.5:1.5, samples=101,smooth] plot(\x, {myfunction(\x)});
\end{tikzpicture}
\end{document}