12

How would I plot the equation x^6+y^5cos(x)=1 and make a graph? I usually use pgfplots, but I am not sure how to work around the equals sign in this equation. When I solve for x and plot the function I get a result that differs from when I use Apple's Grapher application. Even when I extend the domain, the graph won't stretch beyond. Apple GrapherLatex Result

\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
xlabel=$x$,
ylabel=$y$,
xmin=-3.5,
xmax=3.5,
ymax=3,
ymin=-2.5
]
\addplot[samples=100,domain=-3.5:3.5] {((1-x^6)/(cos(deg(x)))^.2};  
\end{axis}
\end{tikzpicture}
\end{center}
  • Plot y against x, rewriting the equation as y=...? y is just a function of x here, isn't it? What's the problem exactly? – cfr Dec 7 '15 at 2:29
  • @cfr, indicte roots of this equation? I'm guessing. – Zarko Dec 7 '15 at 3:52
  • @Zarko Could be! Who knows? – cfr Dec 7 '15 at 4:08
  • 1
    If you have gnuplot available, you could use this solution. – Thruston Dec 7 '15 at 11:06
  • 3
    PGFplots uses degrees instead of radians for trigonometric functions. Set trig format plots=rad to switch to radians – Jake Dec 8 '15 at 6:08
7
+100

There are three problems.

  1. fpu cannot handle odd roots of negative numbers. This causes a hole between 1, -1 and the respective nearby asymptotes.
  2. The curve to draw is steep around the asymptotes, so low sampling make it wonky. If it's low enough the asymptotic behaviour disappears altogether.
  3. The curve is drawn as a continuous path, so if there is a(n approximated) vertical asymptote of the kind you are drawing the jump from -\infty to +\infty gets drawn.

And there are three solutions.

  1. A simple algebraic manipulation.
  2. Increasing the sampling.
  3. Giving pgfplots a cutoff on the y domain.

Here is the code, with numbers marking the solutions:

\documentclass[tikz,border=9]{standalone}
\usepackage{pgfplots}
\begin{document}\begin{tikzpicture}

\begin{axis} [ axis lines=center,
    xlabel=$x$, xmin=-pi,  xmax= pi,
    ylabel=$y$, ymin=-2.5, ymax= 4.5,
    restrict y to domain=-5:10,]          % (3)

  \def\f{(1-x^6)*sec(deg(x))}

  \addplot [samples=1000]                 % (2)
    {sign(\f)*pow(abs(\f),1/5)};          % (1)

\end{axis}

\end{tikzpicture}\end{document}

Here is the result:

hop!

  • I am still getting an error unknown error: sign. – cpage Dec 11 '15 at 2:36
  • That's a basic arithmetic function, see §89.3.1 of manual. You are using an outdated (<3.0.1) version of TiKz. Update it and it will compile. – Paolo Brasolin Dec 11 '15 at 6:36
  • How do I update it since I have \usepackage{pgfplots}? – cpage Dec 11 '15 at 6:58
  • 1
    Update your TeX distribution. If you want to keep it simple use algebra and write abs(\f)/(\f) instead of sign(\f). – Paolo Brasolin Dec 11 '15 at 7:02
  • 1
    @SolomonUcko Yes, you are right. A correct custom implementation of the sign function would be along the lines of \tikzset{declare function={sgn(\x) = greater(\x,0) - less(\x,0);}} or something equivalent using the logical operators that are available in your pgf version. – Paolo Brasolin Jan 23 at 4:44

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.