Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Thomas Marullo
Thomas Marullo le 21 Sep 2015
Commenté : Walter Roberson le 24 Sep 2015
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.

Réponses (1)

Sebastian Castro
Sebastian Castro le 21 Sep 2015
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 commentaires
Thomas Marullo
Thomas Marullo le 24 Sep 2015
Thank you. I guess I just have to deal with the slight differences.
Walter Roberson
Walter Roberson le 24 Sep 2015
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.

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by