Precision Difference Between MATLAB and Simulink MATLAB Function
5 views (last 30 days)
Show older comments
I have a MATLAB script which increments a value by a 0.0312194854736328. I also have the same function on Simulink. However after 4048 iterations, the MATLAB and Simulink compute different values. Is this because MATLAB and Simulink are using different precisions? If so, how can I match the Simulink precision with MATLAB?
0 Comments
Answers (1)
John D'Errico
on 28 Mar 2024
No. This is not a difference in the precision used. Both tools will use double preicsion arithmetic to store all numbers.
Instead, it may be due to the same reason that computations like
0.3 - 0.2 - 0.1
do not yield an exact zero, and other mathematically equivalent sequences of operations may result in a different result.
-0.1 - 0.2 + 0.3
In either case, you should get zero, but neither gave zero, and they were not even the same non-zero.
There may be other causes too. What is the source of this number? How did you enter it? The problem is, MATLAB does not even store EXACTLY that number as a double.
num2str(0.0312194854736328,70)
In fact, what I show above is the actual number stored, when you stuff that number into a double.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!