Second-order system simulation in Simulink - Time & Space Complexity
We want to understand how the time to simulate a second-order system changes as we increase the simulation length or resolution.
How does the simulation time grow when we use more steps or longer time?
Analyze the time complexity of the following MATLAB simulation setup.
% Define system parameters
wn = 5; % natural frequency
zeta = 0.7; % damping ratio
% Create transfer function for second-order system
sys = tf([wn^2], [1 2*zeta*wn wn^2]);
% Simulate system response to step input
t = 0:0.01:10; % time vector
[y, t_out] = step(sys, t);
This code simulates the step response of a second-order system over a time vector with fixed step size.
Look for repeated calculations or loops in the simulation.
- Primary operation: Calculating system output at each time step.
- How many times: Once for every time point in the vector
t.
The simulation calculates output values for each time step, so more steps mean more calculations.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 calculations |
| 100 | 100 calculations |
| 1000 | 1000 calculations |
Pattern observation: The number of operations grows directly with the number of time steps.
Time Complexity: O(n)
This means the simulation time grows linearly as you increase the number of time steps.
[X] Wrong: "The simulation time stays the same no matter how many time steps I use."
[OK] Correct: Each time step requires a calculation, so more steps mean more work and longer simulation time.
Understanding how simulation time grows helps you design efficient models and manage resources well in real projects.
"What if we changed the fixed time step to a variable step solver? How would the time complexity change?"
Practice
Solution
Step 1: Understand damping ratio role
The damping ratio controls how oscillations decay in the system response.Step 2: Connect damping ratio to response behavior
A higher damping ratio reduces overshoot and speeds settling time, affecting speed and overshoot.Final Answer:
The speed and overshoot of the system's response -> Option BQuick Check:
Damping ratio = speed and overshoot control [OK]
- Confusing damping ratio with input amplitude
- Thinking damping ratio changes block size
- Assuming damping ratio affects plot color
Solution
Step 1: Recall second-order transfer function form
The standard form is numerator = [1], denominator = [1 2*zeta*wn wn^2].Step 2: Match options to standard form
Numerator: [1], Denominator: [1 2*zeta*wn wn^2] matches the correct numerator and denominator coefficients for a second-order system.Final Answer:
Numerator: [1], Denominator: [1 2*zeta*wn wn^2] -> Option CQuick Check:
Standard form = Numerator: [1], Denominator: [1 2*zeta*wn wn^2] [OK]
- Swapping numerator and denominator
- Using wrong powers for wn
- Missing damping term 2*zeta*wn
Solution
Step 1: Identify denominator coefficients
Denominator is [1 4 4], which matches [1 2*zeta*wn wn^2].Step 2: Calculate wn and ζ from coefficients
wn^2 = 4 -> wn = 2; 2*zeta*wn = 4 -> ζ = 4/(2*2) = 1.Final Answer:
wn=2, ζ=1 -> Option AQuick Check:
wn=2, ζ=1 from denominator [OK]
- Confusing wn^2 with wn
- Dividing damping term incorrectly
- Ignoring coefficient order
Solution
Step 1: Analyze denominator coefficients
Denominator [1 0 4] means 2*zeta*wn = 0, so damping ratio ζ = 0.Step 2: Understand effect on oscillations
Zero damping ratio means undamped oscillations, but the system denominator form is incorrect for natural frequency 2 (since wn^2=4).Step 3: Identify correct denominator form
Correct denominator should be [1 0 4] only if system is undamped, but zero middle term can cause simulation issues.Final Answer:
The denominator coefficients are incorrect for oscillations -> Option DQuick Check:
Incorrect denominator = no oscillations [OK]
- Assuming zero damping means no oscillations
- Swapping numerator and denominator
- Ignoring input signal presence
Solution
Step 1: Calculate denominator coefficients
Given wn=5, ζ=0.3, calculate 2*ζ*wn = 2*0.3*5 = 3 and wn^2 = 25.Step 2: Form denominator array
Denominator coefficients are [1, 3, 25].Final Answer:
[1 3 25] -> Option AQuick Check:
2*zeta*wn=3, wn^2=25 [OK]
- Using wn instead of wn squared
- Mixing damping ratio with wn
- Incorrect multiplication order
Ready to prove it?
Pass the test and this pattern moves unknown
