How does Simulink/MATLAB decide on the precision of its output?
8 views (last 30 days)
Show older comments
I'm in the process of doing a comparison between a simple Simulink model and an in house simulator. The results are very close to each other (within machine precision), however I am a little perplexed by the patterns which arise in the differences between the two simulations. In the attached image it looks like are patterns which arises in the differences. As t increases, the differences alternate between patches of small differences and patches of differences exactly equal to 0.
This is because the in house software always outputs 15 digits of accuracy, however Simulink only sometimes does this, other times it outputs with many more digits (over 30) of accuracy - these are the patches of small errors. Does anyone know why this might be? The accuracy issue doesn't concern me, but I would like to be able to explain the patterns in the differences.
For reference, this is a simple model involving an integrator (RK4) and a couple of gain operations. More details can be provided if needed.
Edit: I wrote my own RK4 solver in MATLAB and I notice the same results. Namely at some points the output is 15 digits, and at other points the output is over 30 digits.
0 Comments
Answers (1)
Sebastian Castro
on 21 Jul 2015
My guess would be the following:
Simulink uses a combination of absolute and relative tolerances to determine whether or not to reduce the integration time step. As shown in the links I pointed to, this can be set in the Model Configuration Parameters for all variable-step solvers.
Relative tolerance is, as its name suggests, proportional to the magnitude of the state. So, the bigger your state (positive or negative), the more error is allowed.
Absolute tolerance is a lower bound on this tolerance. You can imagine that relative tolerance starts breaking if the value of an integrator state is very small. 5% of 0.00000000000000001 is a really small number, and a relative tolerance alone would have a hard time getting out of such a spot.
When Simulink integrates a state "X", it therefore checks whether the integration error is less than the MAXIMUM of (absolute tolerance) and (relative tolerance times the magnitude of the state).
- Sebastian
0 Comments
See Also
Categories
Find more on Model Verification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!