Discrete state-space in Simulink - Time & Space Complexity
We want to understand how the time needed to run a discrete state-space model changes as the size of the system grows.
How does the number of calculations grow when we increase the number of states?
Analyze the time complexity of the following code snippet.
% Discrete state-space update
x_next = A * x + B * u;
y = C * x + D * u;
x = x_next;
This code updates the system state and output at each time step using matrix multiplication.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Matrix multiplication of A by x and C by x.
- How many times: Once per time step, repeated for each update.
As the number of states (n) grows, the number of calculations grows roughly with the square of n because of matrix multiplication.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 100 operations |
| 100 | About 10,000 operations |
| 1000 | About 1,000,000 operations |
Pattern observation: When n increases ten times, operations increase about one hundred times.
Time Complexity: O(n2)
This means the time to update the state grows roughly with the square of the number of states.
[X] Wrong: "The time grows linearly with the number of states because we just update each state once."
[OK] Correct: Each state update involves multiplying matrices, which requires combining all states together, causing the time to grow faster than just counting states.
Understanding how matrix operations affect time helps you explain performance in control systems and simulations clearly and confidently.
"What if the matrix A was sparse (mostly zeros)? How would the time complexity change?"
Practice
Solution
Step 1: Understand discrete state-space concept
Discrete state-space models describe systems using matrices that update the system's state at each time step.Step 2: Compare options
Only a system described by matrices that updates states step-by-step correctly describes this concept; others describe unrelated tools or continuous systems.Final Answer:
A system described by matrices that updates states step-by-step -> Option CQuick Check:
Discrete state-space = step-by-step matrix system [OK]
- Confusing discrete with continuous systems
- Thinking state-space is only for continuous models
- Mixing up state-space with graphical tools
Solution
Step 1: Recall syntax for discrete state-space
In MATLAB/Simulink, discrete state-space systems use ss(A,B,C,D,Ts) where Ts is the sample time.Step 2: Evaluate options
sys = ss(A, B, C, D, Ts); matches the correct syntax. sys = ss(A, B, C, D); misses Ts (sample time), C and D use incorrect function names.Final Answer:
sys = ss(A, B, C, D, Ts); -> Option BQuick Check:
Discrete ss needs sample time Ts [OK]
- Omitting the sample time Ts
- Using wrong function names like discrete()
- Confusing continuous and discrete syntax
A = [[0.7, 0.2], [0, 0.9]];B = [[0.1], [0.05]];and initial state
x0 = [1; 0], what is the state x[1] after one step with input u[0] = 2?Solution
Step 1: Calculate next state using formula
Next state x[1] = A * x0 + B * u[0]. Calculate:
A * x0 = [0.7*1 + 0.2*0; 0*1 + 0.9*0] = [0.7; 0]
B * u[0] = [0.1*2; 0.05*2] = [0.2; 0.1]Step 2: Add results to get x[1]
x[1] = [0.7; 0] + [0.2; 0.1] = [0.9; 0.1]Final Answer:
[0.9; 0.1] -> Option DQuick Check:
Use x[1] = A*x0 + B*u[0] [OK]
- Forgetting to multiply input u by B
- Mixing matrix multiplication order
- Adding instead of multiplying matrices
A = [[1, 0], [0, 1]];B = [[0], [0]];C = [[1, 0]];D = [[0]];Why does the output never change regardless of input?
Solution
Step 1: Analyze matrix B effect on input
Matrix B is zero, so input u does not affect state update: x[k+1] = A*x[k] + B*u[k] = A*x[k].Step 2: Understand output behavior
Output y = C*x + D*u depends only on state x and input u. Since input doesn't change state, output depends only on initial state and does not change with input.Final Answer:
Because matrix B is zero, input has no effect on state -> Option AQuick Check:
Zero B means input can't change state [OK]
- Confusing zero D with zero B effect
- Assuming identity A means output changes
- Ignoring input effect on state update
A = [[0.8, 0.1], [0, 0.9]];B = [[0.05], [0.02]];Which sample time should you specify to correctly model this system?
Solution
Step 1: Understand sample time meaning
Sample time Ts defines how often the discrete system updates its state. Here, states update every 0.1 seconds.Step 2: Choose correct sample time
Ts must be positive and equal to the update interval, so Ts = 0.1 seconds.Final Answer:
0.1 -> Option AQuick Check:
Sample time = update interval = 0.1 [OK]
- Using zero or negative sample time
- Confusing sample time with continuous time
- Choosing wrong units for sample time
Ready to prove it?
Pass the test and this pattern moves unknown
