1

Good morning, I have a problem using pgfplots. I tried to draw the function y=arctan(1/x), but I obtain an inexact result. Where is the problem? The code is:

\documentclass{article}
\usepackage{pgfplots,relsize}
\begin{document}
\begin{tikzpicture}
\begin{axis} [
width=12cm,height=6cm,
axis lines=middle,
enlargelimits,
xtick={-5,5},ytick={-1.57,1.57},
xticklabels={$-5$, $5$},
yticklabels={$-\pi/2$, $\pi/2$},
xlabel=$x$,ylabel=$y$]
\addplot [domain=-10:10,
samples=200,smooth,thick,blue]
{rad(atan(1/x))};
\end{axis}
\end{tikzpicture}
\end{document}
long
  • 53
  • What is your exact problem? Show a picture of what you expect and a picture of what you get. – pschulz Feb 25 '17 at 10:24
  • Sometimes the problem with trigonometric functions is that rad instated of degree (or vice versa) are used. Have you made sure that this is not the case? See also http://tex.stackexchange.com/questions/12951 \begin{axis}[trig format plots=rad] – Dr. Manuel Kuehner Feb 25 '17 at 10:30

1 Answers1

4

I hope it is what you wanted.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis} [
  width=12cm,
  height=6cm,
  axis lines=middle,
  enlargelimits,
  xtick={-5,5},
  ytick={-1.57,1.57},
  xticklabels={$-5$, $5$},
  yticklabels={$-\pi/2$, $\pi/2$},
  xlabel=$x$,
  ylabel=$y$
]
\addplot[
  mark=none,
  domain=-10:0,
  samples=200,
  smooth,
  thick
] {rad(atan(1/x))};
\addplot[
  mark=none,
  domain=0:10,
  samples=200,
  smooth,
  thick,
] {rad(atan(1/x))};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

egreg
  • 1,121,712
Sebastiano
  • 54,118