Challenge - 5 Problems
Discrete State-Space Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Discrete State-Space Simulation
Given a discrete state-space model with matrices:
A = [[0.7, 0.2], [0, 0.9]]
B = [[0.1], [0.05]]
C = [[1, 0]]
D = [[0]]
Initial state x0 = [1, 0]
Input u = 1 (constant)
Simulate for 3 steps.
What is the output y at step 3?
A = [[0.7, 0.2], [0, 0.9]]
B = [[0.1], [0.05]]
C = [[1, 0]]
D = [[0]]
Initial state x0 = [1, 0]
Input u = 1 (constant)
Simulate for 3 steps.
What is the output y at step 3?
Simulink
import numpy as np A = np.array([[0.7, 0.2],[0,0.9]]) B = np.array([[0.1],[0.05]]) C = np.array([[1,0]]) D = np.array([[0]]) x = np.array([[1],[0]]) u = 1 for _ in range(3): x = A @ x + B * u y = C @ x + D * u print(float(y))
Attempts:
2 left
💡 Hint
Calculate the state x at each step using x(k+1) = A*x(k) + B*u, then output y(k) = C*x(k) + D*u.
✗ Incorrect
At each step, the state updates by multiplying with A and adding B*u. The output y is C times the state plus D times input. After 3 steps, y = 1.045.
❓ data_output
intermediateNumber of States in Discrete State-Space Model
You have a discrete state-space system defined by matrices:
A is 4x4
B is 4x2
C is 3x4
D is 3x2
How many states does this system have?
A is 4x4
B is 4x2
C is 3x4
D is 3x2
How many states does this system have?
Attempts:
2 left
💡 Hint
The number of states equals the dimension of the square matrix A.
✗ Incorrect
Matrix A is square and its size determines the number of states. Since A is 4x4, the system has 4 states.
❓ visualization
advancedPlotting State Trajectories
You simulate a discrete state-space system with 2 states over 10 steps. The states evolve as:
x(k+1) = A*x(k) + B*u(k)
where A = [[0.5, 0],[0, 0.8]], B = [[1],[0]], u(k) = 1 for all k, and x(0) = [0, 0].
Which plot correctly shows the state trajectories over time?
x(k+1) = A*x(k) + B*u(k)
where A = [[0.5, 0],[0, 0.8]], B = [[1],[0]], u(k) = 1 for all k, and x(0) = [0, 0].
Which plot correctly shows the state trajectories over time?
Simulink
import numpy as np import matplotlib.pyplot as plt A = np.array([[0.5,0],[0,0.8]]) B = np.array([[1],[0]]) x = np.array([[0],[0]]) u = 1 states = [] for _ in range(10): x = A @ x + B * u states.append(x.flatten()) states = np.array(states) plt.plot(range(1,11), states[:,0], label='State 1') plt.plot(range(1,11), states[:,1], label='State 2') plt.xlabel('Step') plt.ylabel('State value') plt.legend() plt.show()
Attempts:
2 left
💡 Hint
State 1 is influenced by input u(k)=1, so it grows initially then halves. State 2 has no input, so it decays by 0.8 each step.
✗ Incorrect
State 1 updates as x1(k+1) = 0.5*x1(k) + 1*1, so it grows initially and then halves the previous value plus 1. State 2 updates as x2(k+1) = 0.8*x2(k) + 0, so it decays from zero. The plot shows State 1 increasing and State 2 starting at zero and remaining zero since no input.
🔧 Debug
advancedIdentify the Error in Discrete State-Space Update Code
Consider this Python code simulating a discrete state-space system:
import numpy as np
A = np.array([[0.9, 0.1],[0, 0.95]])
B = np.array([[0.05],[0.02]])
x = np.array([0, 0])
u = 1
for i in range(5):
x = A * x + B * u
print(x)
What error does this code produce or what is wrong with it?
import numpy as np
A = np.array([[0.9, 0.1],[0, 0.95]])
B = np.array([[0.05],[0.02]])
x = np.array([0, 0])
u = 1
for i in range(5):
x = A * x + B * u
print(x)
What error does this code produce or what is wrong with it?
Simulink
import numpy as np A = np.array([[0.9, 0.1],[0, 0.95]]) B = np.array([[0.05],[0.02]]) x = np.array([0, 0]) u = 1 for i in range(5): x = A * x + B * u print(x)
Attempts:
2 left
💡 Hint
Check how matrix multiplication is done in numpy. '*' does element-wise multiplication, '@' does matrix multiplication.
✗ Incorrect
The code uses '*' which performs element-wise multiplication, not matrix multiplication. This causes incorrect state updates. The correct operator is '@' for matrix multiplication.
🚀 Application
expertPredict Output Sequence from Discrete State-Space Model
A discrete state-space system has:
A = [[0.6, 0.3], [0.1, 0.7]]
B = [[0.2], [0.1]]
C = [[1, -1]]
D = [[0]]
Initial state x0 = [2, 1]
Input u(k) = 0 for all k
What is the output y at step 2?
A = [[0.6, 0.3], [0.1, 0.7]]
B = [[0.2], [0.1]]
C = [[1, -1]]
D = [[0]]
Initial state x0 = [2, 1]
Input u(k) = 0 for all k
What is the output y at step 2?
Simulink
import numpy as np A = np.array([[0.6, 0.3],[0.1, 0.7]]) B = np.array([[0.2],[0.1]]) C = np.array([[1,-1]]) D = np.array([[0]]) x = np.array([[2],[1]]) u = 0 for _ in range(2): x = A @ x + B * u y = C @ x + D * u print(float(y))
Attempts:
2 left
💡 Hint
Calculate x at step 1 and 2, then compute y = C*x at step 2.
✗ Incorrect
Step 1: x1 = A*x0 + B*0 = [[0.6,0.3],[0.1,0.7]]*[[2],[1]] = [[0.6*2+0.3*1],[0.1*2+0.7*1]] = [[1.5],[0.9]]
Step 2: x2 = A*x1 + B*0 = [[0.6,0.3],[0.1,0.7]]*[[1.5],[0.9]] = [[0.6*1.5+0.3*0.9],[0.1*1.5+0.7*0.9]] = [[0.9+0.27],[0.15+0.63]] = [[1.17],[0.78]]
Output y2 = C*x2 + D*0 = [1,-1]*[[1.17],[0.78]] = 1.17 - 0.78 = 0.39 (rounded 0.4 matches option B).
