How Simulink handles calls to discrete blocks
1 次查看(过去 30 天)
显示 更早的评论
I have a Simulink model which includes a Matlab System Block for which I have defined a discrete sample time following this guide.
Indeed, if in Simulink I enable the sample time information (from Debug/Information Overlays panel), I see that the output signals are characterized by that sample time.
Instead, as inputs to this block I have signals with different sample times or multirate.
I am simulating with a ode45 Variable-Step solver.
Let's denote with
the simulation end time. The initial time is 0.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1554557/image.png)
If I run the Simulink profiler I see that this Matlab System Block, characerized by a sample time
, gets called n times.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1554562/image.png)
Though, I notice that
. What I see is that
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1554567/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1554572/image.png)
Could you help me understand why?
0 个评论
回答(1 个)
Fangjun Jiang
2023-11-28
That is right. Read this. For every integration step, the derivative function needs to be called between 4 times (for RK4) and 6 times (for RK5).
6 个评论
Paul
2023-11-29
According to the linked doc page in your comment:
------------------------------------
Discrete Sample Times
Given a block with a discrete sample time, Simulink® software executes the block output or update method at times .... (emphasis added)
---------------------------------
I realize that a few lines later that same doc page says " executes the output method." Nevertheless, a block with discrete sample time is only executed (update and output methods) at the integer multiples of the sample time (pluss offset if nonzero).
"dy/dt=f(u,y,t)+d(u,y,t) " with u and y continuous.
In this case, dy/dt is computed at the major and minor time steps of the ODE solver, but d(u,y,t) is only executed as its discrete sameple time hits. If using a variable step solver, Simulink ensures that each sample time hit occurs on a major time step. If using a fixed step solver, the step size has to be the sample time of the d(u,y,t) block divided by an ineger >= 1. In either case, the d(u,y,t) block is executed on the major step prior to the start of the integration, i.e., d(u,y,t) is computed at t_n and held constant over all of the dy/dt calculations that are needed to step from t_n to t_n + dt. More precisely, even if t_n + dt = t_(n+1) the d(u,y,t) block is not executed on the final minor time step of the integration. At least that's my understanding based on Simulation Loop Phase
What did you see on that linked doc page that "might explain why discrete systems could be called more times."?
Based on your comment above, it sounds like your model is strictly discrete-time, and therefore should be using a discrete-time solver. But your original question mentions using ode45, which is a continuous-time solver? However, even if the solver is set to ode45, Simulink will automatically change it the to the variabie-step discrete-time solver if there are no continuous states. Can you clarify whether or not the model has continuous states? Is the solver is fixed- or variable-step? If the former, what is the step size? In either case, what's the sample time of of the Matlab System Block?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!