简体   繁体   中英

arctan2 discrepancy in NumPy

I have come across a puzzling issue when using arctan2 in Numpy. Searching for atan2 errors did not answer the question, but someone might know the reason for this.

f = np.arange(0,100)
w = 2*np.pi*f/50
x = np.arctan2(sin(-w*d/2)*cos(w*d/2), cos(w*d/2)*cos(w*d/2))

gives different results to

f = np.arange(0,100)
w = 2*np.pi*f/50
x = np.arctan2(sin(-w*d/2), cos(w*d/2))

The former is out by an offset of $pi$ every period. Looks like a numeric issue but I have not seen any notes on this particular case.

Note that the error seems to be induced by a negative value in the cos() factor. This gets calculated correctly.

H = np.arctan2(sin(-w*d/2)*abs(cos(w*d/2)), cos(w*d/2)*abs(cos(w*d/2)))

atan2( y, x) gives the angle between the x axis and the vector x,y. Therefore atan2( y, x) and atan2( a y, a x) are the same if and only if a>0. For example atan2( y, x) is pi/4 but atan2( -1*y, -1*x) is -3pi/4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM