Error in simple calculations
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone I'm really having a very weird and silly problem with Matlab. A very simple calculation which is z=(x-y). That's all, but when x= 0.327999967200000 and y=0.319999968000000 then z=0.00799999920000000 which is correct. But when x=0.311999968800000 and y=0.303999969600000 then z=0.00799999920000005 which is wrong as the answer should stay 0.00799999920000000. It is a simple silly stupid operation nevertheless the Matlab is unable to solve it correctly. I used everything, the format the cast the eps() non of them worked and the error is still persistent. What shall I do so the Matlab would perform such calculation without errors. Is it a bug or something? I'm using Matlab 2014b.
Thanx in advanced
0 Commenti
Risposte (1)
Sebastian Castro
il 17 Apr 2015
Definitely not a bug -- just floating-point error: http://www.mathworks.com/matlabcentral/answers/57444-faq-why-is-0-3-0-2-0-1-not-equal-to-zero
If you care about that level of precision, it might be feasible to work with fixed-point data. This way, you can choose a good fixed-point implementation that can exactly represent a particular set of numbers.
- Sebastian
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!