Precision Difference Between MATLAB and Simulink MATLAB Function

11 vues (au cours des 30 derniers jours)
Kaan
Kaan le 28 Mar 2024
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?

Réponses (1)

John D'Errico
John D'Errico le 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
ans = -2.7756e-17
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
ans = -5.5511e-17
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)
ans = '0.0312194854736328013256052571477994206361472606658935546875'
In fact, what I show above is the actual number stored, when you stuff that number into a double.

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by