我正在尝试将一些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以单元格方式应用于第一个参数除以第二个参数的商。我在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。其他细胞似乎也错了。我错过了什么吗?
答案 0 :(得分:0)
自己找到答案。 atan2
不仅仅是atan
单元格应用。操作数的标志也很重要。
有关详细信息,请参阅:http://sunsite.univie.ac.at/textbooks/octave/octave_17.html
然后关于如何自己实施atan2
(正如我正在做的那样)请参阅:http://en.wikipedia.org/wiki/Atan2
答案 1 :(得分:0)