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}
  • 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 tex.stackexchange.com/questions/12951 \begin{axis}[trig format plots=rad] – Dr. Manuel Kuehner Feb 25 '17 at 10:30
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

  • I've taken the liberty of fixing the function. – egreg Feb 25 '17 at 10:38
  • @egreg You have done very well and you are always authorized to do so in my case. There was no need for me to ask. – Sebastiano Feb 25 '17 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.