subtract two identical float number it gives a very small number not a zero

suposed I have matrix A
A =
0.9500 0 0
0.9500 0 0
0.9500 0 0
0.9500 0 0
0.9500 0 0
0.9500 0 0
0.9500 0 0
0.9500 0 0
and I calculate the mean of A as
AA =mean(A)
AA =
0.9500 0 0
When I do that AA(1,1) - AA(1)
ans =
-1.1102e-16
Why I get this number and not zero ?? Please could you please help?

답변 (3개)

Matlab's double precision numbers are in binary form, and therefore cannot represent the quantity 0.9500 exactly. Using binary notation the closest it could come to that number would be:
.11110011001100110011001100110011001100110011001100110
since it is restricted to a maximum significand (mantissa) of 53 bits. The exact binary expression for 0.9500 would be an infinitely long string analogous to, say, the infinite string for 1/3 in decimal: 1/3 = 0.33333333333333333 ....
When eight such inexact numbers representing 0.9500 are added together one-at-a-time with rounding to 53 bits at each step and the sum divided by 8 the accumulated error is sufficient to show up as a difference in the least significant bit:
.11110011001100110011001100110011001100110011001100111
That least significant bit has a value of 1.1102e-16, which is what you observed.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2014년 12월 8일

답변:

2014년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by