# TiKZtikz graph of y^3−3y^2−x−x^3+2=0, |x|<1

#### karush

##### Well-known member
ok i tried to plot $y^3−3y^2−x−x^3+2=0, |x|<1$ but could not do so
spent about an hour trying to find a useable example but didn't

i am new to tikz but this is not a function...

here is the code I tried. just borrowed a previos on i thot I could just replace the expression but no
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\begin{axis}[xmin=-1.8, xmax=1.8, ymin=-3, ymax=3, axis lines=middle, ticks=none]
draw=red, smooth, ultra thick, dashed,
domain=-1.5:1.5,
smooth
]{-x-x^3+2}
%{y^3−3y^2−x−x^3+2=0}
\foreach \x in {-1,0,1} { (axis cs:{\x},0) node[below right] {\x} };
\end{axis}
\end{tikzpicture}

#### Klaas van Aarsen

##### MHB Seeker
Staff member
TikZ does not support plotting graphs of equations natively.

Instead we can for instance parametrize the equation as:
\begin{cases}
x = r(\phi)\cos\phi \\
y = r(\phi)\sin\phi + 1
\end{cases}
where $r(\phi)=\sqrt{\frac{3\sin\phi+\cos\phi}{\sin^3\phi - \cos^3\phi}}$.

Then we can draw:
\begin{tikzpicture}[
declare function = {
},
]
\draw[help lines] (-3,-2) grid (3,4);
\draw[->] (-3,0) -- (3.4,0);
\draw[->] (0,-2) -- (0,4.2);
\draw foreach \i in {-3,...,3} {(\i,-0.1) node[fill=black!5,below] {$\i$}};
\draw foreach \i in {-2,...,4} {(-0.1,\i) node[fill=black!5,left] {$\i$}};
\draw[domain=50:{atan(-1/3)+179.99}, variable=\phi, red, smooth, ultra thick] plot ({radius(\phi) * cos(\phi)}, {1 + radius(\phi) * sin(\phi)});
\draw[domain=-130:{atan(-1/3)-0.01}, variable=\phi, red, smooth, ultra thick] plot ({radius(\phi) * cos(\phi)}, {1 + radius(\phi) * sin(\phi)});
\end{tikzpicture}

Last edited:

#### karush

##### Well-known member
ok i was thinking doing that but wasn't sure how to set it up

i think many of the DE graphs will be like that

mahalo

#### Klaas van Aarsen

##### MHB Seeker
Staff member
For reference, I derived the parametrization as follows.

We can see the point symmetry around (0,1) in the Desmos graph.
Shift the point of symmetry to the origin by introducing $\tilde y = y-1 \implies y = \tilde y + 1$.
Consequently we get:
\begin{aligned}y^3-3y^2-x-x^3+2&=
(\tilde y+1)^3-3(\tilde y+1)^2-x-x^3+2 \\
&=\tilde y^3+3\tilde y^2 +3\tilde y + 1 -3\tilde y^2 - 6\tilde y-3-x-x^3+2 \\
&=\tilde y^3-3\tilde y-x-x^3 \\
& = 0\end{aligned}

Substitute polar coordinates $x=r\cos\phi,\,\tilde y=r\sin\phi$ to get:
$\tilde y^3-3\tilde y-x-x^3=0 \\ (r\sin\phi)^3-3(r\sin\phi)-(r\cos\phi)-(r\cos\phi)^3=0 \\ r^3(\sin^3\phi - \cos^3\phi)=r(3\sin\phi+\cos\phi) \\ r=\pm \sqrt{\frac{3\sin\phi+\cos\phi}{\sin^3\phi - \cos^3\phi}} \quad\lor\quad r=0$

In polar coordinates we have that $r\ge 0$, so we will only have the $+$ solution.

Putting it together we get:
\begin{cases}x = r(\phi)\cos\phi \\ y=r(\phi)\sin\phi +1
\end{cases}
where $r(\phi)=\sqrt{\frac{3\sin\phi+\cos\phi}{\sin^3\phi - \cos^3\phi}}$.

Last edited:

#### Klaas van Aarsen

##### MHB Seeker
Staff member
The question included the condition $|x|<1$, which we did not address yet.

I added that and improved the TikZ picture a bit:
\begin{tikzpicture}[
declare function = {
tilde_y(\q) = sign(\q)*sqrt(abs(\q) / (1 - (abs(\q)-3)^3));
},
pics/coordinates/.style args={(#1,#2),(#3,#4)}{ code={
\draw[help lines] (#1,#2) grid (#3,#4);
\draw[-latex] (#1,0) -- (#3,0);
\draw[-latex] (0,#2) -- (0,#4);
\node foreach \i in {#1,...,#3} at (\i,-0.1) [ below ] {$\i$};
\node foreach \i in {#2,...,#4} at (-0.1,\i) [ left ] {$\i$};
}},
every node/.style={fill=black!5},
fill=black!5,
]
\pic {coordinates={(-3,-2),(3,4)}};
\begin{scope}[draw=blue, ultra thick]
\draw[domain=-3.5:3.5, variable=\q, smooth] plot ({(abs(\q) - 3) * tilde_y(\q)}, {1 + tilde_y(\q)});
\filldraw foreach \p in {(1,3),(-1,2),(1,0),(-1,-1)} { \p circle (0.06) };
\end{scope}
\end{tikzpicture}

Just for fun, it uses a different parametrization that is based on slope.
We can find it by substituting $x=p\tilde y$ and solving for $\tilde y$ as function of $p$. It has $-3\le p<1$.
Afterwards I've reparametrized with $p=q-3$ to get a connected domain.

It is:
\begin{cases}x = (|q|-3)\cdot \tilde y(q) \\
y = \tilde y(q) + 1
\end{cases}
where $\tilde y(q)=\operatorname{sign}(q) \sqrt{\frac{|q|}{1-(|q|-3)^3}}$ and $-4<q<4$.

Last edited:

#### karush

##### Well-known member
TikZ does not support plotting graphs of equations natively.

Instead we can for instance parametrize the equation as:
\begin{cases}
x = r(\phi)\cos\phi \\
y = r(\phi)\sin\phi + 1
\end{cases}
where $r(\phi)=\sqrt{\frac{3\sin\phi+\cos\phi}{\sin^3\phi - \cos^3\phi}}$.

Then we can draw:
\begin{tikzpicture}[
declare function = {
},
]
\draw[help lines] (-3,-2) grid (3,4);
\draw[->] (-3,0) -- (3.4,0);
\draw[->] (0,-2) -- (0,4.2);
\draw foreach \i in {-3,...,3} {(\i,-0.1) node[fill=black!5,below] {$\i$}};
\draw foreach \i in {-2,...,4} {(-0.1,\i) node[fill=black!5,left] {$\i$}};
\draw[domain=50:{atan(-1/3)+179.99}, variable=\phi, red, smooth, ultra thick] plot ({radius(\phi) * cos(\phi)}, {1 + radius(\phi) * sin(\phi)});
\draw[domain=-130:{atan(-1/3)-0.01}, variable=\phi, red, smooth, ultra thick] plot ({radius(\phi) * cos(\phi)}, {1 + radius(\phi) * sin(\phi)});
\end{tikzpicture}
The question included the condition $|x|<1$, which we did not address yet.

I added that and improved the TikZ picture a bit:
\begin{tikzpicture}[
declare function = {
tilde_y(\q) = sign(\q)*sqrt(abs(\q) / (1 - (abs(\q)-3)^3));
},
pics/coordinates/.style args={(#1,#2),(#3,#4)}{ code={
\draw[help lines] (#1,#2) grid (#3,#4);
\draw[-latex] (#1,0) -- (#3,0);
\draw[-latex] (0,#2) -- (0,#4);
\node foreach \i in {#1,...,#3} at (\i,-0.1) [ below ] {$\i$};
\node foreach \i in {#2,...,#4} at (-0.1,\i) [ left ] {$\i$};
}},
every node/.style={fill=black!5},
fill=black!5,
]
\pic {coordinates={(-3,-2),(3,4)}};
\begin{scope}[draw=blue, ultra thick]
\draw[domain=-3.5:3.5, variable=\q, smooth] plot ({(abs(\q) - 3) * tilde_y(\q)}, {1 + tilde_y(\q)});
\filldraw foreach \p in {(1,3),(-1,2),(1,0),(-1,-1)} { \p circle (0.06) };
\end{scope}
\end{tikzpicture}

Just for fun, it uses a different parametrization that is based on slope.
We can find it by substituting $x=p\tilde y$ and solving for $\tilde y$ as function of $p$. It has $-3\le p<1$.
Afterwards I've reparametrized with $p=q-3$ to get a connected domain.

It is:
\begin{cases}x = (|q|-3)\cdot \tilde y(q) \\
y = \tilde y(q) + 1
\end{cases}
where $\tilde y(q)=\operatorname{sign}(q) \sqrt{\frac{|q|}{1-(|q|-3)^3}}$ and $-4<q<4$.
wow yeah that adds a lot
there was a lot of code I haven't tried yet so mahalo
I did notice when it rendered in Overleaf that it was about twice the size needed by not sure if a scale down would be that easy
tying to avoid scaled images of graphs
usually don't put in grid just a few tics at critical points of intersection
also be nice to show both y and y' and their equations as labels

I am sure I can figure this out but would have not been able to do the parametric at my level

#### Klaas van Aarsen

##### MHB Seeker
Staff member
wow yeah that adds a lot
there was a lot of code I haven't tried yet so mahalo
I did notice when it rendered in Overleaf that it was about twice the size needed by not sure if a scale down would be that easy
tying to avoid scaled images of graphs
usually don't put in grid just a few tics at critical points of intersection
also be nice to show both y and y' and their equations as labels

I am sure I can figure this out but would have not been able to do the parametric at my level
I see where $|x|<1$ comes from now.
However, it is not enough to just restrict $x$. It also means that we have to restrict $y$ to the interval $(0,2)$.
That is because the top and bottom parts of the previous graph do not have $y(0)=1$, so they have to be left out.

Since $y'$ has a very different y-range, I guess it is best to put it in a separate graph.

Here's how we might do it with pgfplots:
\begin{tikzpicture}[
declare function = {
tilde_y(\q) = sign(\q)*sqrt(abs(\q) / (1 - (abs(\q) - 3)^3));
sol_x(\q) = (abs(\q)-3)*tilde_y(\q);
sol_y(\q) = tilde_y(\q) + 1;
derivative_y(\x,\y) = (1+3(\x)^2) / (3(\y)^2 - 6*(\y));
},
]
%preamble \usepackage{pgfplots}
\begin{axis}[
axis lines=middle,
ymax=2.4,
]
\addplot[red, domain=-2:2, smooth, ultra thick] ({sol_x(x)}, {sol_y(x)});
\addlegendentry{$y^3-3y^2=x^3+x-2$}
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[
declare function = {
tilde_y(\q) = sign(\q)*sqrt(abs(\q) / (1 - (abs(\q) - 3)^3));
sol_x(\q) = (abs(\q)-3)*tilde_y(\q);
sol_y(\q) = tilde_y(\q) + 1;
derivative_y(\x,\y) = (1+3(\x)^2) / (3(\y)^2 - 6*(\y));
},
]
%preamble \usepackage{pgfplots}
\begin{axis}[
axis lines=middle,
ymax=1.5,
]
\addplot[blue, domain=-2:2, smooth, ultra thick] ({sol_x(x)}, {derivative_y(sol_x(x), sol_y(x))});
\addlegendentry{$y'=\frac{1+3x^2}{3y^2-6y}$}
\end{axis}
\end{tikzpicture}

#### Klaas van Aarsen

##### MHB Seeker
Staff member
Or alternatively we can do:
\begin{tikzpicture}[
declare function = {
tilde_y(\q) = sign(\q)*sqrt(abs(\q) / (1 - (abs(\q) - 3)^3));
sol_x(\q) = (abs(\q)-3)*tilde_y(\q);
sol_y(\q) = tilde_y(\q) + 1;
derivative_y(\x,\y) = (1+3(\x)^2) / (3(\y)^2 - 6*(\y));
},
]
\begin{scope}
\draw[-latex] (-1.5,0) -- (1.5,0);
\draw[-latex] (0,-8.5) -- (0,2.5);
\draw foreach \i in {-1} { (\i,0.1) -- (\i,-0.1) node[ below ] {$\i$} };
\draw foreach \i in {-8,-5,1,2} { (0.1,\i) -- (-0.1,\i) node[ left ] {$\i$} };
\begin{scope}[blue, thick]
\draw[domain=-2:2, variable=\q, smooth] plot ({sol_x(\q)}, {derivative_y(sol_x(\q),sol_y(\q))});
\draw[fill=black!5] foreach \p in {(-1,-8),(1,0)} { \p circle (0.06) } node[below right] {$y'$};
\end{scope}
\begin{scope}[red, thick]
\draw[domain=-2:2, variable=\q, smooth] plot ({sol_x(\q)}, {sol_y(\q)});
\draw[fill=black!5] foreach \p in {(-1,2),(1,0)} { \p circle (0.06) } node[above right] {$y$};
\end{scope}
\end{scope}
\end{tikzpicture}

It should scale just fine if you want to scale it.

#### karush

##### Well-known member
Or alternatively we can do:
\begin{tikzpicture}[
declare function = {
tilde_y(\q) = sign(\q)*sqrt(abs(\q) / (1 - (abs(\q) - 3)^3));
sol_x(\q) = (abs(\q)-3)*tilde_y(\q);
sol_y(\q) = tilde_y(\q) + 1;
derivative_y(\x,\y) = (1+3(\x)^2) / (3(\y)^2 - 6*(\y));
},
]
\begin{scope}
\draw[-latex] (-1.5,0) -- (1.5,0);
\draw[-latex] (0,-8.5) -- (0,2.5);
\draw foreach \i in {-1} { (\i,0.1) -- (\i,-0.1) node[ below ] {$\i$} };
\draw foreach \i in {-8,-5,1,2} { (0.1,\i) -- (-0.1,\i) node[ left ] {$\i$} };
\begin{scope}[blue, thick]
\draw[domain=-2:2, variable=\q, smooth] plot ({sol_x(\q)}, {derivative_y(sol_x(\q),sol_y(\q))});
\draw[fill=black!5] foreach \p in {(-1,-8),(1,0)} { \p circle (0.06) } node[below right] {$y'$};
\end{scope}
\begin{scope}[red, thick]
\draw[domain=-2:2, variable=\q, smooth] plot ({sol_x(\q)}, {sol_y(\q)});
\draw[fill=black!5] foreach \p in {(-1,2),(1,0)} { \p circle (0.06) } node[above right] {$y$};
\end{scope}
\end{scope}
\end{tikzpicture}

It should scale just fine if you want to scale it.
yes I definitively like that one

mahalo for all the help,,, I'm going to continue more with these tikz graphs demos is really nice but there are features you want that it doesn't offer