Problem about rounding to 0

I have a function w=u_1*u_2-u_3*u_4.
u_i's are also functions that return complex double numbers.
For some inputs i get the result w=0 (in workspace, not only in command window) which is a result that i dont like for my analysis (cause later i have to devide some numbers with it).
But when i compute the u_i's seperately and i do the operation u_1*u_2-u_3*u_4 (using the u_i results from workspace) i get a result like ''1.6941e-20 - 2.1684e-19i'' which is of course very small but different to 0.
Why dont i see this result for w instead of 0? How can i fix this ? Is it a rounding to 0 problem ?

1 件のコメント

James Tursa
James Tursa 2020 年 7 月 30 日
Please provide an example set of inputs and desired output.

回答 (1 件)

madhan ravi
madhan ravi 2020 年 7 月 30 日

1 投票

w = u_1 * u_2 - u_3 * sym(u_4)
Click on the tag floating-point.

2 件のコメント

Dimitris Sarvanis
Dimitris Sarvanis 2020 年 7 月 30 日
thank u very much.
w = u_1 * u_2 - u_3 * sym(u_4) (or w = sym(u_1) * sym(u_2) - sym(u_3) * sym(u_4) for bigger accuracy) really give me results different than 0 !
The truth is i wanted to avoid sym(x) or vpa(x) cause they are very slow.
Can i do anything else ?
madhan ravi
madhan ravi 2020 年 7 月 30 日
Set tolerance.
w(real(w) < 1e-2 & imag(w) < 1e-2) = 0

この質問は閉じられています。

質問済み:

2020 年 7 月 30 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by