Calculation Error sum float
Mostrar comentarios más antiguos
I Write This Code:
clc;
clear;
format long
a=1;
for n=1:1:100
a=a+.1;
end
a
and answer is:
a =
10.999999999999979
!!!!! Why not: a= 11
How I Can Solve it?
1 comentario
James Tursa
el 16 de Mayo de 2014
See Azzi's link below. But for your particular case this is the decimal equivalent of the closest number to 0.1 in IEEE double format:
>> num2strexact(0.1)
ans =
0.1000000000000000055511151231257827021181583404541015625
You can find num2strexact here:
Respuestas (1)
Azzi Abdelmalek
el 16 de Mayo de 2014
1 voto
2 comentarios
Maha dasra
el 16 de Mayo de 2014
José-Luis
el 16 de Mayo de 2014
- Use a computer that doesn't use the binary system. There are a few such strange base 10 machines out there.
- Try variable precision arithmetic. Either with the symbolic toolbox or the excellent vpa from the file exchange.
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!