4

The following code generates the wrong plot:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[domain = 0:1, samples = 500]
    \addplot[color = black]  {pi/((pi/2)+atan(x/sqrt(1-x^2)))};
  \end{axis}
\end{tikzpicture}
\end{document}

Obviously, for x tending to 1 the function tends to 1 and not to 0 as in the plot. See also

plot on WA

What am I doing wrong?

lpdbw
  • 8,330

2 Answers2

4

The good old degrees vs. radians issue I think. atan in pgf returns degrees, while Wolfram Alpha probably uses radians.

enter image description here

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[domain = 0:1, samples = 100]
    \addplot[color = black]  {pi/(((pi/2)+atan(x/sqrt(1-x^2))*pi/180)};
  \end{axis}
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
2

Plot it as a function:

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[domain = 0:1, samples = 500]
    \addplot[color = black] function {pi/((pi/2)+atan(x/sqrt(1-x^2)))};
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • 3
    Works (+1), but uses gnuplot, so that is required, as well as enabling --shell-escape, so perhaps you could mention that. – Torbjørn T. Oct 16 '15 at 14:19