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}
2
  • What is your exact problem? Show a picture of what you expect and a picture of what you get.
    – pschulz
    Commented Feb 25, 2017 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] Commented Feb 25, 2017 at 10:30

1 Answer 1

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

2
  • I've taken the liberty of fixing the function.
    – egreg
    Commented Feb 25, 2017 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
    Commented Feb 25, 2017 at 10:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.