Error in simple calculations
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Sebastian Castro
2015-4-17
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!