我正在尝试将一些 Octave 代码移植到 Java。我正在尝试 atan2 所以我有以下尝试
octave3.2:53> m1 = [1,2;3,4]
m1 =
1 2
3 4
octave3.2:54> m2=[5,6;7,8]
m2 =
5 6
7 8
octave3.2:55> atan2(m1,m2)
ans =
0.19740 0.32175
0.40489 0.46365
octave3.2:56> atan(1/5)
ans = 0.19740
octave3.2:57> atan(2/6)
ans = 0.32175
octave3.2:58> atan(3/7)
ans = 0.40489
octave3.2:59> atan(4/8)
ans = 0.46365
所以在我看来, atan2 将 atan 单元格应用于第一个参数除以第二个参数的商。我在 Java 中做得很好。但是,下面的代码给出了一些奇怪的东西......
y
x
theta = atan2(y,x)
我得到了类似的痕迹,
y =
-0.50000 -0.50000 -0.50000 -0.50000 -0.50000 -0.50000 -0.50000 -0.50000 -0.50000 -0.50000
-0.40000 -0.40000 -0.40000 -0.40000 -0.40000 -0.40000 -0.40000 -0.40000 -0.40000 -0.40000
-0.30000 -0.30000 -0.30000 -0.30000 -0.30000 -0.30000 -0.30000 -0.30000 -0.30000 -0.30000
-0.20000 -0.20000 -0.20000 -0.20000 -0.20000 -0.20000 -0.20000 -0.20000 -0.20000 -0.20000
-0.10000 -0.10000 -0.10000 -0.10000 -0.10000 -0.10000 -0.10000 -0.10000 -0.10000 -0.10000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.10000 0.10000 0.10000 0.10000 0.10000 0.10000 0.10000 0.10000 0.10000 0.10000
0.20000 0.20000 0.20000 0.20000 0.20000 0.20000 0.20000 0.20000 0.20000 0.20000
0.30000 0.30000 0.30000 0.30000 0.30000 0.30000 0.30000 0.30000 0.30000 0.30000
0.40000 0.40000 0.40000 0.40000 0.40000 0.40000 0.40000 0.40000 0.40000 0.40000
x =
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
-0.50000 -0.40000 -0.30000 -0.20000 -0.10000 0.00000 0.10000 0.20000 0.30000 0.40000
theta =
-2.35619 -2.24554 -2.11122 -1.95130 -1.76819 -1.57080 -1.37340 -1.19029 -1.03038 -0.89606
-2.46685 -2.35619 -2.21430 -2.03444 -1.81577 -1.57080 -1.32582 -1.10715 -0.92730 -0.78540
-2.60117 -2.49809 -2.35619 -2.15880 -1.89255 -1.57080 -1.24905 -0.98279 -0.78540 -0.64350
-2.76109 -2.67795 -2.55359 -2.35619 -2.03444 -1.57080 -1.10715 -0.78540 -0.58800 -0.46365
-2.94420 -2.89661 -2.81984 -2.67795 -2.35619 -1.57080 -0.78540 -0.46365 -0.32175 -0.24498
3.14159 3.14159 3.14159 3.14159 3.14159 0.00000 0.00000 0.00000 0.00000 0.00000
2.94420 2.89661 2.81984 2.67795 2.35619 1.57080 0.78540 0.46365 0.32175 0.24498
2.76109 2.67795 2.55359 2.35619 2.03444 1.57080 1.10715 0.78540 0.58800 0.46365
2.60117 2.49809 2.35619 2.15880 1.89255 1.57080 1.24905 0.98279 0.78540 0.64350
2.46685 2.35619 2.21430 2.03444 1.81577 1.57080 1.32582 1.10715 0.92730 0.78540
那是怎么回事?我认为 theta 的第一个单元格应该〜0.785398。其他细胞似乎也错了。有什么我错过的吗?