Precision Difference Between MATLAB and Simulink MATLAB Function
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
John D'Errico
am 28 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!