Mixed continuous-discrete models in Simulink - Time & Space Complexity
We want to understand how the time to run a mixed continuous-discrete Simulink model changes as the model size grows.
How does adding more blocks or steps affect the total work done?
Analyze the time complexity of the following Simulink model snippet.
% Continuous block: Integrator
y = integrator(u);
% Discrete block: Unit Delay with sample time Ts
y_d = unit_delay(y, Ts);
% Loop over N steps
for k = 1:N
y = integrator_step(u(k));
y_d = unit_delay_step(y_d, Ts);
end
This snippet shows a model with continuous integration and discrete delay updated over N time steps.
Look for repeated calculations in the model.
- Primary operation: The loop runs N times, updating continuous and discrete blocks each step.
- How many times: Each step performs fixed work once, repeated N times.
As the number of steps N increases, the total work grows proportionally.
| Input Size (N) | Approx. Operations |
|---|---|
| 10 | 10 units of work |
| 100 | 100 units of work |
| 1000 | 1000 units of work |
Pattern observation: Doubling N doubles the work, showing a steady linear growth.
Time Complexity: O(N)
This means the time to run the model grows directly in proportion to the number of simulation steps.
[X] Wrong: "The continuous and discrete parts run independently, so time doesn't grow with steps."
[OK] Correct: Each simulation step updates both parts, so total work adds up with more steps.
Understanding how simulation time grows helps you design efficient models and explain performance clearly.
"What if the discrete block updated every M steps instead of every step? How would that change the time complexity?"
Practice
Solution
Step 1: Understand model types in Simulink
Continuous models change smoothly over time, discrete models change at specific time steps.Step 2: Define mixed continuous-discrete model
It combines both smooth continuous changes and stepwise discrete changes in one system.Final Answer:
A system combining smooth continuous changes and stepwise discrete changes -> Option AQuick Check:
Mixed model = continuous + discrete changes [OK]
- Thinking mixed means only continuous
- Confusing discrete with continuous
- Believing Simulink can't simulate mixed models
Solution
Step 1: Identify discrete memory blocks
Discrete memory stores previous values at discrete time steps.Step 2: Match block to function
Unit Delay block holds the input value for one discrete time step, acting as memory.Final Answer:
Unit Delay -> Option BQuick Check:
Discrete memory = Unit Delay [OK]
- Choosing Integrator which is continuous
- Confusing Gain with memory
- Selecting Sum which adds signals
Solution
Step 1: Understand signal timing
The step input changes from 0 to 1 at 1s.Step 2: Analyze Unit Delay output at 1.5s
Unit Delay outputs the input value from the previous discrete time step. Assuming sample time 1s, at 1.5s it outputs input at 1s, which is 1 after the step.Final Answer:
1 -> Option CQuick Check:
Unit Delay outputs previous step input [OK]
- Assuming Unit Delay outputs current input
- Ignoring sample time effect
- Confusing Integrator output with Unit Delay
Solution
Step 1: Check connections
If Integrator not connected, output would be undefined, not zero.Step 2: Verify Unit Delay sample time
If sample time is incorrect or continuous, Unit Delay may output zero because it never updates.Final Answer:
Sample time of Unit Delay is not set correctly -> Option AQuick Check:
Incorrect sample time causes zero output [OK]
- Assuming connection issue without checking sample time
- Ignoring input signal values
- Thinking Gain block affects Unit Delay output
Solution
Step 1: Identify continuous and discrete parts
Temperature sensor is continuous, controller logic updates discretely every 0.1s.Step 2: Choose appropriate blocks
Integrator models continuous sensor output; Unit Delay with sample time 0.1s models discrete controller updates.Final Answer:
Use an Integrator for temperature and a Unit Delay with sample time 0.1s for controller updates -> Option DQuick Check:
Continuous sensor + discrete controller = Integrator + Unit Delay [OK]
- Using only discrete blocks for continuous sensor
- Ignoring sample time for discrete controller
- Reversing block roles
Ready to prove it?
Pass the test and this pattern moves unknown
