I have the following function:
$$f(\omega) = \arctan\left(\frac{-\omega\cdot R / L}{-w^2 + 1/(C\cdot L)}\right)$$
When I try to plot it (atan(f(w))), I get the following:
This is clearly not an atan plot. I investigated a bit and found atan2. When I use it instead (atan2(-w*R/L, -w**2 + 1/(C*L))), I obtain:
That does look like a atan plot. My question is: is it correct to provide numerator and denominator as first and second arguments of atan2 as I did?
Also, about atan2, my understanding is that the tan function doesn't have information about the sign of cos and sin, so it can't know if the angle comes from the first or third quadrant if the result is positive, or from the second or fourth quadrant if the result was negative. I don't understand very well why is this; how can not knowing the angle quadrants lead to the 'wrong' plot above?
SageMath code to test the above
R = 100
L = 1.5e-3
C = 1.6e-9
abs_H(w) = 1/(C*L) / sqrt( (-w**2 + 1/(C*L))**2 + (R/L*w)**2 )
# phase_H(w) = atan( -(w*R/L) / (-w**2 + 1/(C*L)) ) * 180/pi
phase_H(w) = atan2( -(w*R/L) , (-w**2 + 1/(C*L)) ) * 180/pi # Notice atan2; otherwise it doesn't work
p = plot(abs_H, w, (10, 1e7), scale='loglog')
q = plot(phase_H, w, (10, 1e7), ymin=-180, scale='semilogx')
show(p)
print('')
show(q)
print('')


φ = atan(m)converts the slopemof a line into the bearing angle. If the slope is zero, the angle is zero (by convention). If the slope is-∞then the angle is-π/2and if the slope is+∞the angle is+π/2.The result is limited to the 1st and 4th quadrants.
φ = atan(dy,dx)converts the direction defined by(dx,dy)into the bearing angle. If the direction points to the 2nd or 3rd quadrants (based on the signs of the arguments) then the angle result will vary between-πand+π.Some environments define
φ = atan(dx,dy)so care must be taken to get the correct order of arguments.You must choose which function you need, as you pointed out when
m=dy/dxthe results are not always the same. There are cases whenatan2()is preferred and cases where it is not. There are other cases you need positive angles only between0andπand there you useφ = acos(dx/sqrt(dx**2+dy**2)).There is no universally proper way to do the conversion, as it depends on your assumptions related to the angle result.
Here is a graph of
atan(m)and the graph of
acos(1/sqrt(1+m^2))Both produce identical values for positive slope
m, but the second one returns only the positive branch of angles for negative slopem.and here is
atan2(dx=1, dy=m)which is identical to
atan()as the direction information is lost sincedxis always positive.