I need some help plotting y^2=x^2(x+1) in pgfplots. I want to print it in the domain -10 to 10. I tried for sometime, but it did not work. Also it should be a smooth curve and not a dotted one.
- 231,401
- 63
-
Welcome to TeX-sx! Please edit into your question what you have tried to date: this seems relatively straight-forward to me as expressed. – Joseph Wright Apr 05 '15 at 21:03
-
BTW, a smaller range seems more helpful, say -1:1. – Joseph Wright Apr 05 '15 at 21:09
3 Answers
Another approach: you can parametrize. I remembered that I had done a parametrization for exactly this curve on TeXwelt.de.
I set y=(xt)^(3/2) in order to simplify when taking to the square. So, I get
xt^3 = x+1 (or x=0)
and thus
x = 1 / (t^3-1) and y = (t/(t^3-1))^(3/2)
which I can plot now, letting t run (here I name t to x):
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=middle,
axis equal,
xlabel = {$x$},
ylabel = {$y$},
restrict y to domain = -4:4,
restrict x to domain = -1:1.6,
]
\addplot [domain = -4:4, samples = 300]
({1/(x^3 - 1)}, { (x/(x^3 - 1))^1.5});
\addplot [domain = -4:4, samples = 300]
({1/(x^3 - 1)}, {-(x/(x^3 - 1))^1.5});
\end{axis}
\end{tikzpicture}
\end{document}

My original post is in German: Wie kann man eine nicht eindeutige Funktion plotten.
- 231,401
You can make two plots, one for the positive part of y and one for the negative. Here's a compilable example. I chose the domain -1.5 to 1.5 for a better view, of course you can change that.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal,
axis x line = middle,
axis y line = middle,
xlabel = {$x$},
ylabel = {$y$},
]
\addplot [domain = -1.5:1.5,samples=300, unbounded coords=jump]
{sqrt(x^2*(x+1))};
\addplot [domain = -1.5:1.5,samples=300, unbounded coords=jump]
{-sqrt(x^2*(x+1))};
\end{axis}
\end{tikzpicture}
\end{document}

- 231,401
For comparison with an Asymptote
// Run on http://asymptote.ualberta.ca/
unitsize(1cm);
import contour;
import graph;
real f(real x, real y) { return y^2-x^3-x^2; }
pair A=(-2.5,-2.5), B=(2.5,2.5);
limits(A,B);
guide[][] g = contour(f,A,B, new real[] {0});
draw(g[0],blue+1pt);
real[] x={-2,-1,1,2};
real[] y={-2,-1,1,2};
xaxis(Label("$x$",EndPoint,align=.5N),Ticks(x,1mm,red));
yaxis(Label("$y$",EndPoint,align=.5E),Ticks(y,1mm,red));
shipout(bbox(5mm,invisible));
- 17,569
