Matlab gives different results summing a few numbers with and without parentheses

4 views (last 30 days)
I was trying to find discrete integrate of a function using trapz but I kept gettin NaN for results. Searching for the issue I found out that the last point exceeds the fcuntion's range. In my case the last point should be exactly 10.424 but as you can see below Matlab gives different results by just adding or removing parentheses. Can anybody tell if something is wrong with my Matlab ??? How can I avoid that 1e-15 at the end ??
R=10.644;
A=0.507;
B=0.22;
R - A + A - B
ans =
10.423999999999999
R - A + (A - B)
ans =
10.424000000000001

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 7 Nov 2013

More Answers (0)

Community Treasure Hunt

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

Start Hunting!