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}
cpage
  • 559

1 Answers1

7

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 02: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 06:36
  • How do I update it since I have \usepackage{pgfplots}? – cpage Dec 11 '15 at 06: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 07:02
  • @PaoloBrasolin Wouldn't it be different (at least in general) when it's argument is 0? sign(...) returns 0, abs(...)/... errors. (AFAIK) – Solomon Ucko Jan 20 '19 at 16:23
  • 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 '19 at 04:44