Error in simple calculations

6 visualizaciones (últimos 30 días)
Ahmed
Ahmed el 17 de Abr. de 2015
Comentada: Ahmed el 18 de Abr. de 2015
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

Respuestas (1)

Sebastian Castro
Sebastian Castro el 17 de Abr. de 2015
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 comentario
Ahmed
Ahmed el 18 de Abr. de 2015
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

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by