Technical Solutions
Why do my numbers not add up correctly in MATLAB?
Date Last Modified: Friday, June 26, 2009
| Solution ID: | 1-536M9L | |
| Product: | MATLAB | |
| Reported in Release: | No Release | |
| Platform: | All Platforms | |
| Operating System: | All OS |
Subject:
Why do my numbers not add up correctly in MATLAB?
Problem Description:
When I add numbers together, and then compare the result to a number that I think is the correct result using "==" or the ISEQUAL function, the comparison returns as "false" or 0.
For example:
a = 0.1 + 0.1 +0.1;
b = 0.3;
a == b
ans =
0
Solution:This behavior is related to floating-point arithmetic and the way numbers are represented in a computer. For more information on this subject, see the related Solution below. |
Related Solutions:
|
|
Store

