5

I try to plot a elliptic curve with this code:

\documentclass{article}

\usepackage{amssymb} \usepackage{tikz} \usepackage{pgfplots}

\begin{document}

\begin{figure}[htp] \centering \begin{tikzpicture} \begin{axis}[ xmin=-2, xmax=2, ymin=-2, ymax=2, axis lines=center, xlabel={$x$}, ylabel={$y$}, samples=200] \addplot [blue] {sqrt(x^3 - x + 1}; \addplot [blue] {-sqrt(x^3 - x + 1)}; \end{axis} \end{tikzpicture} \caption{Elliptische Kurve in der Form $x^3-x+1$ im $\mathbb{R}2$} \label{fig:Elliptische Kurve} \end{figure}

\end{document}

Screenshot of the plot

My problem is that in the plot is a visible gap. Does exists a solution for this issue?

2 Answers2

14

Adaptations

  • Use samples at to define specific values that should be calculated and different sampling rates for different areas.

Code

\documentclass{article}

\usepackage{amssymb} \usepackage{tikz} \usepackage{pgfplots}

\begin{document}

\begin{figure}[htp] \centering \begin{tikzpicture} \begin{axis}[ xmin=-2, xmax=2, ymin=-2, ymax=2, axis lines=center, xlabel={$x$}, ylabel={$y$}, samples at={-1.3247, -1.32, -1.31, ..., -1.1, -1.05, -1, ..., 2.0}, ] \addplot [blue] {sqrt(x^3 - x + 1}; \addplot [blue] {-sqrt(x^3 - x + 1)}; \end{axis} \end{tikzpicture} \caption{Elliptische Kurve in der Form $x^3-x+1$ im $\mathbb{R}2$} \label{fig:Elliptische Kurve} \end{figure}

\end{document}

Result

enter image description here

dexteritas
  • 9,161
6

With a short iterative method, we see that (the nonnegative) branch of your cubic is defined for x ≥ −1.3247179572…

Using the method proposed in https://tex.stackexchange.com/a/639053/4427

\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfmath-xfp}

\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture} \pgfmxfpdeclarefunction{cubic}{1}{sqrt((#1)^3-(#1)+1)} \begin{axis}[ xmin=-2, xmax=2, ymin=-2, ymax=2, xlabel={$x$}, ylabel={$y$}, scale only axis, axis lines=middle, domain=-1.3247179572:1.5, samples=200, smooth, % to avoid that the "plot node" is clipped (partially) clip=false, % use same unit vectors on the axis axis equal image=true, ] \addplot [red] {cubic(x)}; \addplot [red] {-cubic(x)}; \end{axis} \end{tikzpicture}

\end{document}

No gap.

enter image description here

egreg
  • 1,121,712