Error in simple calculations

6 次查看(过去 30 天)
Ahmed
Ahmed 2015-4-17
评论: Ahmed 2015-4-18
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

回答(1 个)

Sebastian Castro
Sebastian Castro 2015-4-17
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
  1 个评论
Ahmed
Ahmed 2015-4-18
Dear Sebastian I'm really grateful for the answer but I wonder if there is a simpler way to do it. Actually these number are indecies for voxel cells and they are in millions multiply that by 8 for each cube. Using such approach yields the execution time to explode. I want to avoid this. Besides, the geniuses and huge minds that created such sophisticated scientific package should address and fix this annoying problem. Any calculator, windows calc or a free calc, can perform such operation flawlessly. Also, we as user should have full confidence in Matlab's results not wondering if there was a bug or round-off error may cause the results to be like this. I know it is a precision and word length problem but honostly I saw this for the first time with Matlab and I'm a C++ user.
Any way is there another approach less time consuming and more direct to solve it? I would appreciate it.
Thanx alot

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by