Is this a bug? different results when performing simple math operation (A * (B - C)) with scalars or variables
1 view (last 30 days)
Show older comments
Programmer x.0
on 11 Jan 2022
Commented: Programmer x.0
on 12 Jan 2022
Hello everybody,
I am performing same operation A * (B - C) two times. First with variables, then with numbers (scalars). I get different results.
I am providing the output from the command window.
Can somebody please help on this issue?
Thank you,

0 Comments
Accepted Answer
Walter Roberson
on 11 Jan 2022
If you use
format long g
you will see that ptfDur is not exactly the same as the constant 4.5501 . For example, test
ptfDur - 4.5501
and you will see that the result is non-zero.
Working backwards
C1 = 3 - (-134684353.5829 / 86885000)
C2 = 3 - (-134680438.5 / 86885000)
C1 - C2
Your actual value is about 4E-5 larger than was being displayed, because the default format short only displays 4 digits.
More Answers (0)
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!