cross product is wrong

10 ビュー (過去 30 日間)
savas yilmaz
savas yilmaz 2021 年 8 月 5 日
編集済み: Paul 2021 年 8 月 6 日
>> A
A =
-2159/277
-27/2
0
>> B
B=
-579/104
-135/14
0
>> cross(A,B)
ans =
0
0
-1/70368744177664
A and B vectors are parallel. cross product must "0". But answer is wrong. Can you help me?
  3 件のコメント
savas yilmaz
savas yilmaz 2021 年 8 月 6 日
A =[ -2159/277 ; -27/2 ; 0] and A=sym([-2159/277 -27/2 0]) are not equal.
Paul
Paul 2021 年 8 月 6 日
編集済み: Paul 2021 年 8 月 6 日
In the first instance, A is a double and in the second instance A is a sym object. I was using the Symbolic Math Toolbox to determine if the problem you're seeing is just a rounding error. But the data provided in the question for A and B doesn't yield the result in the question using either symbolic or numeric math:
syms A B
A = sym([-2159/277 -27/2 0]);
B = sym([-579/104 -135/14 0]);
vpa(cross(A,B))
ans = 
cross(double(A),double(B))
ans = 1×3
1.0e+-4 * 0 0 -0.6695
So the symbolic math and the numeric math basically give the same result, neither of which match the result in the question:
-1/70368744177664
ans = -1.4211e-14

サインインしてコメントする。

回答 (2 件)

Rik
Rik 2021 年 8 月 5 日
編集済み: Rik 2021 年 8 月 5 日
1/70368744177664
ans = 1.4211e-14
eps
ans = 2.2204e-16
This number is so small that you can assume this is a rounding error.
The root cause of this rounding error is that it is not possible to store infinite decimals in finite computer memory.
Imagine you can only store decimal numbers, and only 4 digits after the decimal point.
(1/3)*3 = (0.3333)*3 = 0.9999
Is * wrong? Or /? Yes and no. You just need to be aware of the limitations of the tools you're using.
  2 件のコメント
savas yilmaz
savas yilmaz 2021 年 8 月 6 日
This number is so small but I will use this for "if" function. That's why it's important to me that the result is zero.
The answer to the same question is zero in geogebra program. But I need this for matlab.
Rik
Rik 2021 年 8 月 6 日
Then compare to a tolerance:
val=1/70368744177664;
target=0;
tol=1e-10;
if abs(val-target)<=tol

サインインしてコメントする。


Jan
Jan 2021 年 8 月 6 日
Geogebra treats the dta as symbolical expressions. Matlab converts -2159/277 to a numericalvalues as default. If you want to use symbolic calculations, use sym().
Do not check numerical floating point values to be exactly 0 in a condition of an if command. Calculations with numerical values include rounding effects, which cannot be neglected:
1e17 + 1 - 1e17 % 0
1e17 - 1e17 + 1 % 1
sin(2 * pi) % -2.4493e-16
...
There are no well defined fixed limits and it depends on the application what you have to "consider as 0".
A numerical algorithm requires an analysis of the rounding effects to estimate the reliability of the result.

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by