What determines how many times a function is called in simulink?

26 views (last 30 days)
Dear,
I have a very simple question:
As shown in the screenshot, I am using fixed-step ODE2 in my simulation and I am checking how many times my function (which is just a sample disp() function) is called during the simulation.
Based on my understanding on the ODE2, my function is supposed to be called twice per time step. However, I found that the number of times that the function is called changes by putting an integrator block, even if it is not connected to anywhere.
Can anyone help me to understand why this is happening? I will appreciate your help.
Best,
Elena

Answers (1)

Darshan Ramakant Bhat
Darshan Ramakant Bhat on 18 Apr 2017
Edited: Walter Roberson on 18 Apr 2017
This is a very interesting question. This will help to understand how the Simulink solver will work.
The main reason behind this behavior is continous(ODE) solvers will optionally employ minor time steps. A minor time step represents a subdivision of the major time step. The solver produces a result at each major time step. It uses results at the minor time steps to improve the accuracy of the result at the major time step.
Particularly for your case, when you introduce an integrator the solver will decide to go for minor time steps. The internal algorithm will decide what should be the next minor time step adoptively. Each block is getting evaluated for the minor time step. For your example the following will be the execution time steps:
0(major)
0.2(minor)
0.2(major)
0.4(minor)
0.4(major)....so on
If you change the solver to ODE5 the time steps will be as follows
0(major)
0.0400(minor)
0.0600(minor)
0.1600(minor)
0.1778(minor)
0.2000(minor)
0.2000(major)
0.2400(minor)
0.2600(minor)
0.3600(minor)
0.3778(minor)
0.4000(minor)
0.4000(major)
At each major and minor time steps the MATLAB function block is evaluated and it will display the output.
You can observe all these things happening by executing your model in the debug mode. Go to simulation->debug->debug model. Do a step by step execution of the model, observe the status tab for the major and minor time step details. Following doc explains about the solver
I hope the above points will answer your query.
Regards,
Darshan Bhat

Community Treasure Hunt

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

Start Hunting!