I am having some trouble to draw the equation $y^4 - y^2 = x$. Can someone help me? Thanks a lot!
-
7Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – Stefan Pinnow Jul 22 '18 at 20:27
-
1Implicit equations are not possible to handle in TikZ based packages without nontrivial reformulations or level sets. You might have some luck in PSTricks, Metapost or Asymptote. Or you can call an external program. – percusse Jul 22 '18 at 20:28
-
You may plot $y=x^4-x^2$ and rename the axes ... – Michael Hoppe Jul 22 '18 at 20:31
-
Can you not only rename the axises but also swith their positions? – Charles Jul 22 '18 at 20:35
-
@Charles You should edit the tags and insert pstricks-add or pst-func. – Sebastiano Jul 22 '18 at 20:48
Here is a PGF solution. Responding to your request for plotting multiple functions of the form y^4 - y^2 = x - n
, I've added a \foreach
loop.
Updated with axis labels
\documentclass[border=0.5cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=-5, xmax=5,
ymin=-2, ymax=2,
axis lines=center,
xlabel={$x$},
ylabel={$y$},
samples=100]
\foreach \n in {-3,...,3}
\addplot[red] (x^4 - x^2 +\n,x);
\end{axis}
\end{tikzpicture}
\end{document}
An animated version...
\documentclass[tikz,border=0.5cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\foreach \n in {-3,...,3,2,1,...,-2}
{
\begin{tikzpicture}
\begin{axis}[
xmin=-5, xmax=9,
ymin=-3, ymax=3,
axis lines=center,
xlabel={$x$},
ylabel={$y$},
samples=100]
\addplot[red] (x^4 - x^2 +\n,x);
\node [fill=red!20!white,text width=1.2cm,anchor=base,minimum height=0.5cm,minimum width=1.5cm,align=left] at (-3,-2.5) {$n=\n$};
\end{axis}
\end{tikzpicture}
}
\end{document}
-
2
-
I can kindly ask you if you could slow down the animation :-)? Is it very fast. What is the part that generates animation? – Sebastiano Jul 23 '18 at 7:35
-
2@Sebastiano to generate the animation I use an online .pdf to .gif service. The
\foreach
loop makes each 'frame' in an individual pdf page. This is way I do it. – Milo Jul 23 '18 at 17:15
This answer can be a possible solution for to draw $y^4 - y^2 = x$
.
\documentclass[10pt]{article}
\usepackage{pstricks-add}
\usepackage{pst-func}
\begin{document}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dimen=middle,dotstyle=o,dotsize=5pt 0,linewidth=1pt,arrowsize=3pt 2,arrowinset=0.15}
\begin{pspicture*}(-1,-2)(4,3)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=1.,Dy=1.,ticksize=-2pt 0,subticks=2]{->}(0,0)(-1,-1.5)(4,2)
\psplotImp[linecolor=red,stepFactor=0.1,algebraic](-2.0,-3.0)(4.0,3.0){-1.0*y^2+1.0*y^4-1.0*x^1}
\rput[tl](1,2){$-x + y^{4} - y^{2} = 0$}
\rput[tl](3.8,.4){$x$}
\rput[tl](.2,2){$y$}
\end{pspicture*}
\end{document}
ADDENDUM
Inserting new codes \psplotImp[linecolor=yellow,stepFactor=0.1,algebraic](-4.0,-3.0)(4.0,2.0){-2.0-1.0*y^2+1.0*y^4-1.0*x^1}
you can plot new implicit functions, and with \rput[tl](1,1){\small $ -x +1+ y^{4} - y^{2} = 0$}
you can, for example, place labels in the specific location you like using Cartesian coordinates.
\documentclass[10pt]{article}
\usepackage{pstricks-add}
\usepackage{pst-func}
\begin{document}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dimen=middle,dotstyle=o,dotsize=5pt 0,linewidth=1pt,arrowsize=3pt 2,arrowinset=0.15}
\begin{pspicture*}(-3,-2)(4,3)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=1.,Dy=1.,ticksize=-2pt 0,subticks=2]{->}(0,0)(-4,-1.5)(4,2)
\psplotImp[linecolor=red,stepFactor=0.1,algebraic](-4.0,-3.0)(4.0,3.0){-1.0*y^2+1.0*y^4-1.0*x^1}
\psplotImp[linecolor=green,stepFactor=0.1,algebraic](-4.0,-3.0)(4.0,2.0){1.0-1.0*y^2+1.0*y^4-1.0*x^1}
\psplotImp[linecolor=yellow,stepFactor=0.1,algebraic](-4.0,-3.0)(4.0,2.0){-2.0-1.0*y^2+1.0*y^4-1.0*x^1}
\rput[tl](1,2){\small $-x + y^{4} - y^{2} = 0$}
\rput[tl](1,1){\small $ -x +1+ y^{4} - y^{2} = 0$}
\rput[tl](3.8,.4){$x$}
\rput[tl](.2,2){$y$}
\end{pspicture*}
\end{document}
-
@Charles Don't thank me otherwise I could get excited :-). I am here simply to help others and I believe the same for other users. – Sebastiano Jul 22 '18 at 20:47
-
-
-
I am trying to draw several curves in one picture .Equations like y^4 - y^2 = x - n, which n is -3, -2, -1, 0, 1, 2, 3. – Charles Jul 22 '18 at 20:53
-
@Charles I apologise so much but I was without a line. I'll send you an addendum to your comment. – Sebastiano Jul 23 '18 at 1:12
As @percusse suggested, here is the Asymptote version:
//
// yx.asy
//
// run
// asy yx.asy
//
// to get yx.pdf
//
settings.tex="pdflatex";
import graph; import math; import palette;
size(12cm);
import fontsize;defaultpen(fontsize(8pt));
real xmin=-3.6, xmax=5;
real ymax=1.6, ymin=-ymax;
real dxmin=0, dxmax=0.1;
real dymin=0.1, dymax=dymin;
xaxis("$x$",xmin-dxmin,xmax+dxmax,RightTicks(Step=1,step=0.2,OmitTick(0,2.2)),above=true);
yaxis("$y$",ymin-dymin,ymax+dymax,LeftTicks (Step=1,step=0.2,OmitTick(0,1.4)),above=true);
real[] n={-3, -2, -1, 0, 1, 2, 3};
pen[] p=Gradient(n.length, blue,red);
for(int i=0;i<n.length;++i){
pair f(real y){return (y^4-y^2+n[i], y);}
draw(graph(f,ymin,ymax), p[i]+0.7bp);
label("$\scriptstyle{n="+string(n[i])+"}$",f(1.15), p[i],UnFill);
}
clip(box((xmin-dxmin,ymin-dymin),(xmax+dxmax,ymax+dymax)));
label("$y^4-y^2=x-n$",point(dir(80)),plain.N);
-
Very very good. I like also your approach. Pity I don't know how to use Asymptote. – Sebastiano Jul 23 '18 at 1:21
-
-
This is a very simple parametric plot which can be done with TikZ only.
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[-latex] (-1,0) -- (8,0);
\draw[-latex] (0,-2) -- (0,2);
\draw[blue,thick] plot[variable=\y,domain=-1.8:1.8,smooth,samples=50] ({\y*\y*\y*\y-\y*\y},\y);
\end{tikzpicture}
\end{document}
Refactoring Sebastiano's answer.
\documentclass[pstricks]{standalone}
\usepackage{pst-func}
\begin{document}
\begin{pspicture}(-1.5,-2.5)(6,3)
\psaxes{->}(0,0)(-1,-2)(5.5,2.5)[$x$,-90][$y$,180]
\psplotImp[linecolor=red,stepFactor=.1,algebraic](-2,-2)(5,2){y^4-y^2-x}
\rput[tl](1,2){$y^4 - y^2 = x$}
\end{pspicture}
\end{document}
Edit
You can also use one of the following options instead of using \psplotImp
.
\rput{-90}(0,0){\psplot[linecolor=red,algebraic]{-1.65}{1.65}{x^4-x^2}}
or
\psparametricplot[linecolor=red]{-1.65}{1.65}{t^4-t^2|t}
-
2Perfectly reduced to the minimum :-) Maybe some hint to be given to add the labels via \psaxes{->}(0,0)(-1,-2)(5.5,2.5)[$x$,-90][$y$,180] to save some lines. Maybe the intention of Sebastiano was to show of some options on how to layout the axes, although he took mostly the default ones ... – user151328 Jul 22 '18 at 22:14
-
You are very good and I am obviously voting in favour of all of you. – Sebastiano Jul 23 '18 at 1:20