Bird
Raised Fist0
Simulinkdata~20 mins

State-space block in Simulink - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
State-Space Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the State-Space Block Inputs and Outputs

In Simulink, the State-space block models a system using matrices A, B, C, and D. Which of the following correctly describes the inputs and outputs of this block?

AInput is the control vector u, output is the state vector x.
BInput is the state vector x, output is the control vector u.
CInput is the control vector u, output is the system output y.
DInput is the system output y, output is the control vector u.
Attempts:
2 left
💡 Hint

Think about what the State-space block represents: it takes inputs that affect the system and produces outputs based on the system's state.

❓ Predict Output
intermediate
2:00remaining
Output of a State-Space System Simulation

Given the state-space system defined by matrices:

A = [[0,1],[ -2,-3]], B = [[0],[1]], C = [[1,0]], D = [[0]]

and input u(t) = 1 for t ≥ 0, what is the output y at t=0?

Simulink
import numpy as np
A = np.array([[0,1],[-2,-3]])
B = np.array([[0],[1]])
C = np.array([[1,0]])
D = np.array([[0]])
u0 = 1
x0 = np.array([[0],[0]])
y0 = C @ x0 + D * u0
print(y0[0,0])
A0.0
B-1.0
C1.0
DNone (error)
Attempts:
2 left
💡 Hint

At time zero, the state vector x is zero, so output depends on x0 and input u0.

❓ data_output
advanced
2:00remaining
State Vector Evolution After One Time Step

Using the same system as before, with A, B, and input u=1, initial state x0 = [0, 0], and time step dt=1, what is the state vector x after one step using Euler integration?

Simulink
import numpy as np
A = np.array([[0,1],[-2,-3]])
B = np.array([[0],[1]])
u = 1
x0 = np.array([[0],[0]])
dt = 1
x1 = x0 + dt * (A @ x0 + B * u)
print(x1.flatten().tolist())
A[0, 1]
B[1, -3]
C[0, 0]
D[-1, 0]
Attempts:
2 left
💡 Hint

Euler integration: x_next = x_current + dt * (A*x_current + B*u).

❓ visualization
advanced
3:00remaining
Plotting the Output Response of a State-Space System

Which code snippet correctly plots the output y(t) of the state-space system with matrices A, B, C, D and step input u(t)=1 over 5 seconds using Euler integration with dt=0.1?

A
import numpy as np
import matplotlib.pyplot as plt
A = np.array([[0,1],[-2,-3]])
B = np.array([[0],[1]])
C = np.array([[1,0]])
D = np.array([[0]])
dt = 0.1
x = np.array([[0],[0]])
y = []
for _ in range(50):
    u = 1
    y.append((C @ x + D * u)[0,0])
    x = x + dt * (B * u)
plt.plot(np.arange(0,5,dt), y)
plt.xlabel('Time (s)')
plt.ylabel('Output y')
plt.title('Output response')
plt.show()
B
import numpy as np
import matplotlib.pyplot as plt
A = np.array([[0,1],[-2,-3]])
B = np.array([[0],[1]])
C = np.array([[1,0]])
D = np.array([[0]])
dt = 0.1
x = np.array([[0],[0]])
y = []
for _ in range(50):
    u = 1
    x = x + dt * (A @ x + B * u)
    y.append((C @ x + D * u)[0,0])
plt.plot(np.arange(0,5,dt), y)
plt.xlabel('Time (s)')
plt.ylabel('Output y')
plt.title('Output response')
plt.show()
C
import numpy as np
import matplotlib.pyplot as plt
A = np.array([[0,1],[-2,-3]])
B = np.array([[0],[1]])
C = np.array([[1,0]])
D = np.array([[0]])
dt = 0.1
x = np.array([[0],[0]])
y = []
for _ in range(50):
    u = 1
    y.append((C @ x + D * u)[0,0])
    x = x + dt * (A @ x)
plt.plot(np.arange(0,5,dt), y)
plt.xlabel('Time (s)')
plt.ylabel('Output y')
plt.title('Output response')
plt.show()
D
import numpy as np
import matplotlib.pyplot as plt
A = np.array([[0,1],[-2,-3]])
B = np.array([[0],[1]])
C = np.array([[1,0]])
D = np.array([[0]])
dt = 0.1
x = np.array([[0],[0]])
y = []
for _ in range(50):
    u = 1
    y.append((C @ x + D * u)[0,0])
    x = x + dt * (A @ x + B * u)
plt.plot(np.arange(0,5,dt), y)
plt.xlabel('Time (s)')
plt.ylabel('Output y')
plt.title('Output response')
plt.show()
Attempts:
2 left
💡 Hint

Remember to update output y before updating state x in each loop iteration.

🔧 Debug
expert
3:00remaining
Identifying the Cause of Incorrect Output in State-Space Simulation

A user simulates a state-space system but notices the output y remains zero for all time steps despite a non-zero input u. Which code snippet below contains the bug causing this behavior?

A
for _ in range(50):
    u = 0
    y.append((C @ x + D * u)[0,0])
    x = x + dt * (A @ x + B * u)
B
for _ in range(50):
    u = 1
    y.append((C @ x + D * u)[0,0])
    x = x + dt * (A @ x)
C
for _ in range(50):
    u = 1
    x = x + dt * (A @ x + B * u)
    y.append((C @ x + D * u)[0,0])
D
for _ in range(50):
    u = 1
    y.append((C @ x + D * u)[0,0])
    x = x + dt * (A @ x + B * u)
Attempts:
2 left
💡 Hint

Check if the input u affects the state update in each option.

Practice

(1/5)
1. What does the State-space block in Simulink primarily represent?
easy
A. a mathematical model using matrices to describe system dynamics
B. A graphical user interface for designing circuits
C. A tool to generate random numbers
D. A block to display system output only

Solution

  1. Step 1: Understand the purpose of the State-space block

    The State-space block models systems using matrices that describe how states change over time.
  2. Step 2: Compare options with the block's function

    Only a mathematical model using matrices to describe system dynamics correctly describes the use of matrices to represent system dynamics.
  3. Final Answer:

    a mathematical model using matrices to describe system dynamics -> Option A
  4. Quick Check:

    State-space = matrix model [OK]
Hint: State-space means matrix model of system changes [OK]
Common Mistakes:
  • Confusing State-space with graphical tools
  • Thinking it only displays output
  • Assuming it generates random data
2. Which of the following is the correct way to specify the State-space block matrices in Simulink?
easy
A. A = [[0,1],[0,0]]; B = [[0],[1]]; C = [[1,0]]; D = [[0]]
B. A = [0 1; 0 0]; B = [0; 1]; C = [1 0]; D = [0]
C. A = {0,1;0,0}; B = {0;1}; C = {1,0}; D = {0}
D. A = (0,1),(0,0); B = (0),(1); C = (1,0); D = (0)

Solution

  1. Step 1: Recall MATLAB/Simulink matrix syntax

    Matrices in MATLAB/Simulink use square brackets with semicolons separating rows and spaces or commas separating columns.
  2. Step 2: Identify the correct syntax

    A = [0 1; 0 0]; B = [0; 1]; C = [1 0]; D = [0] uses correct MATLAB matrix syntax: [0 1; 0 0] etc., while others use invalid or incorrect formats.
  3. Final Answer:

    A = [0 1; 0 0]; B = [0; 1]; C = [1 0]; D = [0] -> Option B
  4. Quick Check:

    Correct matrix syntax = A = [0 1; 0 0]; B = [0; 1]; C = [1 0]; D = [0] [OK]
Hint: Use [rows; rows] with spaces or commas for columns [OK]
Common Mistakes:
  • Using curly braces {} instead of brackets []
  • Using parentheses () for matrices
  • Separating rows with commas instead of semicolons
3. Given the State-space matrices:
A = [0 1; -2 -3],
B = [0; 1],
C = [1 0],
D = [0]
and input u(t) = 1, what is the initial output y(0) if the initial state x(0) = [0; 0]?
medium
A. 1
B. -3
C. 0
D. Undefined

Solution

  1. Step 1: Calculate output y(0) using y = C*x(0) + D*u(0)

    Given x(0) = [0;0], u(0) = 1, y(0) = C*[0;0] + D*1 = 0 + 0 = 0.
  2. Step 2: Confirm calculation

    Multiplying C by zero vector gives zero, D times input is zero, so output is zero.
  3. Final Answer:

    0 -> Option C
  4. Quick Check:

    y(0) = Cx0 + Du0 = 0 [OK]
Hint: Output at zero state = D times input only [OK]
Common Mistakes:
  • Ignoring initial state and using input only
  • Confusing matrix multiplication order
  • Assuming output equals input directly
4. You entered the following matrices in a State-space block:
A = [0 1; -1 -1],
B = [0; 1],
C = [1; 0],
D = [0].
When simulating, you get an error about matrix dimensions. What is the likely cause?
medium
A. Matrix A must be square but is not
B. Matrix B has wrong number of rows compared to A
C. Matrix D must be a scalar zero, not a matrix
D. Matrix C has wrong number of columns compared to A

Solution

  1. Step 1: Check matrix dimensions for State-space consistency

    Matrix A is 2x2, so B must be 2x1, C must be 1x2, D must be 1x1. Here B=[0;1] (2x1) ok, but C=[1; 0] is 2x1.
  2. Step 2: Identify mismatch

    Matrix C has wrong number of columns (1 vs 2 for A).
  3. Final Answer:

    Matrix C has wrong number of columns compared to A -> Option D
  4. Quick Check:

    C columns must match A columns [OK]
Hint: C columns = A columns; B rows = A rows [OK]
Common Mistakes:
  • Mixing rows and columns in matrices
  • Entering C as a column vector instead of row
  • Assuming D can be any size
5. You want to model a mechanical system with two states using a State-space block. The system has matrices:
A = [0 1; -1 -1],
B = [0; 1],
C = [1 0],
D = [0].
If the input force is a step input of magnitude 3, what will be the steady-state output y(t) as t approaches infinity?
hard
A. 3
B. 0
C. 1
D. Cannot determine without simulation

Solution

  1. Step 1: Find steady-state state x_ss using (A)x_ss + (B)u_ss = 0

    At steady state, dx/dt=0, so 0 = A*x_ss + B*u_ss. With u_ss=3, solve for x_ss: x_ss = -inv(A)*B*3.
  2. Step 2: Calculate output y_ss = C*x_ss + D*u_ss

    Calculate x_ss, then y_ss. For given matrices, y_ss = C*(-inv(A)*B*3) + 0 = 3 (after calculation).
  3. Final Answer:

    3 -> Option A
  4. Quick Check:

    Steady output = input magnitude for stable system [OK]
Hint: Steady output = input if system is stable [OK]
Common Mistakes:
  • Ignoring steady-state calculation
  • Assuming output equals zero without input
  • Not inverting matrix A correctly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard