1

I am drawing an elliptic curve on LaTeX using tikzpicture. I have got the graph on the picture, the curve is defined at -2 but I don't know why the graph is not finished.

enter image description here

Here there is the code:

\begin{tikzpicture}
\begin{axis}[
        xmin=-4,
        xmax=5,
        ymin=-5,
        ymax=5,
        xlabel={$x$},
        ylabel={$y$},
        scale only axis,
        axis lines=middle,
        domain=-1.912931:3,      
        samples=200,
        smooth,   
        clip=false,
        % use same unit vectors on the axis
        axis equal image=true,
    ]
\addplot[blue] {sqrt(x^3-3*x+5)} node[right] {$E$};
\addplot[blue] {-sqrt(x^3-3*x+5)};
\coordinate[label={10:$P$}] (P) at (axis cs:-1,2.64);
\end{axis}
\end{tikzpicture}
Hind Dev
  • 641
  • 3
    What do you mean with "is not finished"? Does not close at -2? Maybe your specified domain does not fit (WolframAlpha means something at about -2.279 as approximation). – TeXnician Dec 22 '17 at 21:08
  • I mean the blue curve is not displayed near -2 – Hind Dev Dec 22 '17 at 21:10
  • 2
    at x=-2 the valur of your function is sqrt{3} which is approximately 1,7320508075688772935274463415059 ..., so your result on selected domain is complete. – Zarko Dec 22 '17 at 21:11
  • that is right, but on the graph it is not, why ? – Hind Dev Dec 22 '17 at 21:13

2 Answers2

8

just illustration what you doing:

enter image description here

blue lines belong to your mwe, red one is on not defined domain:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
        xmin=-3,    xmax=5,
        ymin=-5,    ymax=5,
        xlabel={$x$},
        ylabel={$y$},
        scale only axis,
        axis lines=middle,
        clip=false,
        domain=-2.279:3,    % <-- as sugested by TeXnician
        samples=101,
        % use same unit vectors on the axis
        axis equal image=true,
    ]
\addplot[red,domain=-2.279:-2]  {sqrt(x^3-3*x+5)};
\addplot[blue,domain=-2:3]      {sqrt(x^3-3*x+5)} node[right] {$E$};
\addplot[red,domain=-2.279:-2]  {-sqrt(x^3-3*x+5)};
\addplot[blue,domain=-2:3]      {-sqrt(x^3-3*x+5)};
\coordinate[pin=120:{$(-2.279,0)$}]     (aux) at (-2.279,0);
\coordinate[pin=120:{$(-2,\sqrt{3})$}]  (aux) at (-2,1.73205);
\draw[densely dashed, very thin] (-2,-5) -- (-2,5);
\coordinate[label={10:$P$}] (P) at (-1,2.64);
\end{axis}
\end{tikzpicture}
\end{document}
Zarko
  • 296,517
6

You selected a domain of -1.912931:3. With a corrected domain it (nearly) works (result from https://www.wolframalpha.com/input/?i=abs(sqrt(x^3-3*x%2B5))+%3D+0).

function

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
        xmin=-4,
        xmax=5,
        ymin=-5,
        ymax=5,
        xlabel={$x$},
        ylabel={$y$},
        scale only axis,
        axis lines=middle,
        domain=-2.279018:3,      
        samples=201,
        smooth,   
        clip=false,
        % use same unit vectors on the axis
        axis equal image=true,
    ]
\addplot[blue] {sqrt(x^3-3*x+5)} node[right] {$E$};
\addplot[blue] {-sqrt(x^3-3*x+5)};
\coordinate[label={10:$P$}] (P) at (axis cs:-1,2.64);
\end{axis}
\end{tikzpicture}
\end{document}
TeXnician
  • 33,589
  • thank you @TeXnician, it works, but how do I know the correct domain ad sample to use for each function plot ? I can't find a tutorial on that. – Hind Dev Dec 22 '17 at 21:22
  • 1
    @HindDev That's math. I've just asked WolframAlpha to calculate abs(sqrt(x^3-3*x+5))=0 and then got the domain. For the samples you were not bad with 200 (I've chosen the 201 just to see if it changes the last unclosed bit, but it didn't work out). – TeXnician Dec 22 '17 at 21:27