필터 지우기
필터 지우기

Precision Difference Between MATLAB and Simulink MATLAB Function

조회 수: 1 (최근 30일)
Kaan
Kaan 2024년 3월 28일
답변: John D'Errico 2024년 3월 28일
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?

답변 (1개)

John D'Errico
John D'Errico 2024년 3월 28일
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.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by