1

I'm trying to plot simple Bode plots using pgfplots. After much research, I discarded the package Bodegraph due to its bad documentation and a lot of troubles with the gnuplot. So, I'm using an axis environment with the logarithmic x-axis activated. The next code is sample example of a tikzpicture that shows the problem.

\begin{tikzpicture} \begin{axis}[ width=0.8\linewidth, height = 3cm, xmode = log, axis x line*=box, axis y line*=box, xmin=1e-2, xmax=1e2,% range for the x axis ymin=-100, ymax = 100, scale only axis , ytick distance=40, xmajorgrids = true, ymajorgrids = true, title = Fase, ylabel = $\phi$, xlabel = $\omega$ ] \addplot[smooth, blue, ultra thick, mark=none, domain=1e-2:1e2, samples=400, trig format plots = deg] {atan((2*0.1*(x/2))/(1-(x/2)^2))}; \end{axis} \end{tikzpicture} 

The problem is that I get the following wrong plot: The bad result

What I'm expecting to get is something like: What should be plotted

Please, notice that I'm using the trig format plots=true to set degrees for the trigonometric functions. Can anybody help me out? This is just the phase angle plot of a second order system.

Thanks in advance

6
  • 1
    Use the restrict y to domain=[min,max] keyword. You need to have at least one point outside the clip region to interpolate correctly. See tex.stackexchange.com/questions/324646/… Commented Jun 27, 2017 at 19:29
  • 1
    Why is that wrong/unexpected? You divide by 1-x/2 in argument to atan, so near x=2 you're approaching the limit of infinity, and arctan(+/- inf) is +/-90 degrees. (I have no idea what a phase angle plot of a second order system is.) Commented Jun 27, 2017 at 20:24
  • Use atan2 not atan Commented Jun 27, 2017 at 23:30
  • Yes, I'm trying to use atan2 but I get several errors while using atan2 with pgfplots. Commented Jun 28, 2017 at 7:53
  • It seems like atan2 is undefined so a default value 1 is substituted. It raise errors because 1 is not a floating number. Commented Jul 2, 2017 at 14:19

1 Answer 1

2

The plot you show is correct I think, in the sense that it correctly displays the formula you entered. As mentioned in a comment, you divide by 1-x/2 in the argument to atan, and the limit of atan(x) as x approaches infinity is 90 degrees.

percusse mentions in a another comment that you want to use atan2 instead. atan2 takes two values, atan2(y,x). I have no idea exactly what kind of expression you're supposed to use, but as an example (atan2(1,x)-45)*2 gives you something similar to what you expect, though with a less steep curve in the middle part. I'm not familiar with these things though, so I cannot help you find a more appropriate formula.

enter image description here

\documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ width=0.8\linewidth, height = 3cm, xmode = log, axis x line*=box, axis y line*=box, xmin=1e-2, xmax=1e2,% range for the x axis ymin=-100, ymax = 100, scale only axis , ytick distance=40, xmajorgrids = true, ymajorgrids = true, title = Fase, ylabel = $\phi$, xlabel = $\omega$ ] \addplot[smooth, blue, ultra thick, mark=none, domain=1e-2:1e2, samples=400, trig format plots = deg] {(atan2(1,x)-45)*2}; \end{axis} \end{tikzpicture} \end{document} 

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.