Is there a way to guaranteed floating point accuracy between MATLAB and SIMULINK?

I run the same code in MATLAB and SIMULINK (MATLAB Embedded Block) and at times get slightly different results. I notice it is because of floating point accuracy where at times I may get a 1e-30 difference in a calculation and then that propagates through. I've read a little about variable precision arithmetic but it isn't supported in code generation for SIMULINK. So I am stuck with a problem where I cannot reliably produce the same answers in two environments using the same initial conditions and algorithm.

回答 (1 件)

Sebastian Castro
Sebastian Castro 2015 年 9 月 21 日

0 投票

The discrepance should depend on the numerical solver you are using in MATLAB vs. Simulink. This includes the type of solver, step-size options, tolerances, and so on.
For example, if you are using variable-step solvers like ode45, you should match the model configuration parameters against the odeset options in the programmatic approach.
If you configure them to be identical to each other, the results should match up too.
- Sebastian

5 件のコメント

Thomas Marullo
Thomas Marullo 2015 年 9 月 22 日
編集済み: Thomas Marullo 2015 年 9 月 22 日
I use Fixed-Step and Discrete. I have no continuous states in my model. I expected the solvers to be the same between MATLAB and SIMULINK.
John D'Errico
John D'Errico 2015 年 9 月 22 日
No, because there are many possible solvers, with many possible options.
Walter Roberson
Walter Roberson 2015 年 9 月 22 日
Even if exactly the same solvers were used with the same configuration, unless the exact same code is used, the values can be different.
Thomas Marullo
Thomas Marullo 2015 年 9 月 24 日
Thank you. I guess I just have to deal with the slight differences.
Walter Roberson
Walter Roberson 2015 年 9 月 24 日
Your other question about this dealt with calling the same inv() routine, on the same data, so the explanation for it is something different, such as the state of the floating point rounding controls.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConfigure Simulation Conditions についてさらに検索

質問済み:

2015 年 9 月 21 日

コメント済み:

2015 年 9 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by