# Precision Difference Between MATLAB and Simulink MATLAB Function

7 visualizaciones (últimos 30 días)
Kaan el 28 de Mzo. de 2024
Respondida: John D'Errico el 28 de Mzo. de 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?
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

John D'Errico el 28 de Mzo. de 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.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Simulink en Help Center y File Exchange.

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by