3

我正在将一些函数从 Excel 电子表格翻译成 python。我需要根据 numpy 文档使用 atan2,它是 arctan2: arctan2。问题是这两个结果甚至不接近:

oc = 23.4384863405
sal = 89.7814630647
sra = np.arctan2(np.cos(np.deg2rad(sal)),
         np.cos(np.deg2rad(oc))*np.sin(np.deg2rad(sal)))
results: Excel = 1.566714757 Numpy = 0.00415720646  ??

我相信 Excel 结果是正确的。这是错误的numpy。

现在要么我没有正确使用 arctan2,要么 atan2 不是 numpy 中的 arctan2,要么 numpy 中存在错误,要么我完全迷失在这里。

我正在使用 python 版本 2.7.2 和 numpy 1.6.2

请问有什么想法吗?谢谢

4

1 回答 1

14

From the Excel docs:

The syntax for the ATAN2 function is:

ATAN2( x-coordinate, y-coordinate )

From the numpy docs:

numpy.arctan2(x1, x2[, out])

Element-wise arc tangent of x1/x2 choosing the quadrant correctly.

The quadrant (i.e., branch) is chosen so that arctan2(x1, x2) is the signed angle in radians between the ray ending at the origin and passing through the point (1,0), and the ray ending at the origin and passing through the point (x2, x1). (Note the role reversal: the “y-coordinate” is the first function parameter, the “x-coordinate” is the second.)

They take their arguments in opposite order. Thus:

In [31]: arctan2(cos(deg2rad(sal)), cos(deg2rad(oc))*sin(deg2rad(sal)))
Out[31]: 0.0041572064598812417

In [32]: arctan2(cos(deg2rad(oc))*sin(deg2rad(sal)), cos(deg2rad(sal)))
Out[32]: 1.5666391203350154
于 2012-11-09T13:18:06.353 回答