7

I would like to plot the function x2(1 − x2) − y2 = 0 in LaTeX.

I tried running following code

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm}



\begin{document}

\begin{tikzpicture}
  \begin{axis}[
      view={0}{90},
      no markers,
    ]

    \addplot3+[
      contour gnuplot={
        levels=0,
        labels=false,
      }
    ]
    {x^2(1-x^2)-y^2};

  \end{axis}
\end{tikzpicture}


\end{document}

but the output is enter image description here

But should be

enter image description here

Thanks for helping.

7

enter image description here

@Superuser27 is correct about the missing *. Additionally, I don't understand why you're using \addplot3. Finally, that's not a function.

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm}



\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    ]
    \addplot[domain=-1:1,samples=1000]{ sqrt(x*x*(1-x*x)) * -1 };
    \addplot[domain=-1:1,samples=1000]{ (x*x*(1-x*x))^0.5 * 1 };
    \draw (axis cs:1,-0.07,1)--(axis cs:1,0.07);
  \end{axis}
\end{tikzpicture}


\end{document}
  • I used addplot for the contour gnuplot. So i don‘t have to calculate the function equal 0 for y. – Aris Martin Accola Mar 15 at 14:44
5

math

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
  \begin{axis}[
    ]
    \addplot[no marks,variable=\t,domain=0:360,samples=100] ({cos(\t)}, {0.5*sin(2*\t)});
  \end{axis}
\end{tikzpicture}

\end{document}

demo

  • Best answer.... – JPi Mar 17 at 21:51
2

I had some trouble running your code (compatibility issues) but now it should work. I think the answer is simply that you missed a * in {x^2(1-x^2)-y^2};.

enter image description here

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{width=10cm}
\pgfplotsset{compat=1.15}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[
      view={0}{90},
      no markers,
    ]
    \addplot3[
      contour gnuplot={
        levels=0,
        labels = false,
        },
      domain=-2:2,
      domain y=-1.3:1.3,
    ]
    {x^2*(1-x^2)-y^2};

  \end{axis}
\end{tikzpicture}
\end{document}
  • how did you manage to compile it, I am having hard-time compiling it with the error being: Package pgfplots Error: sorry, plot file{texstudio_Ml6192_contourtmp0.table} could not be opened. {x^2*(1-x^2)-y^2};. If you have some idea, let me know. – Raaja Mar 14 at 13:24
  • 2
    I got the same error. I had to look around online and found that Overleaf also complains but still gives you an output. @Raaja – Superuser27 Mar 14 at 13:27
  • 2
    Usually x^2 is implemented using exp(2*log(x)) which can't handle negative numbers. – John Kormylo Mar 14 at 13:55
  • @JohnKormylo Eventhough, as per your comment, I change it to x*x*(1-x*x)-y*y, I still encounter the same issue. – Raaja Mar 14 at 14:05
  • 1
    @Raaja I had the same problem first compiling it on my computer. So make sure you have installed gnuplot on your computer and then you need to add it to your path so that the program can find gnuplot. You also need to enable —shell-escape. – Aris Martin Accola Mar 15 at 14:41

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.