Bird
Raised Fist0
Simulinkdata~20 mins

Discrete state-space in Simulink - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Discrete State-Space Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output 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?
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))
A1.045
B1.0305
C0.945
D1.15
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.
❓ data_output
intermediate
1:00remaining
Number 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?
A2
B3
C4
D6
Attempts:
2 left
💡 Hint
The number of states equals the dimension of the square matrix A.
❓ visualization
advanced
3:00remaining
Plotting 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?
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()
AState 1 grows starting at 1, then halves each step; State 2 grows starting at 0, multiplied by 0.8 each step.
BState 1 grows starting at 0.5, increasing by 0.5 each step; State 2 starts at 0 and grows slower, approaching 1.
CState 1 starts at 1 and decreases by half each step; State 2 starts at 0 and grows by 0.8 each step.
DState 1 grows starting at 1, then halves each step; State 2 remains zero throughout.
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.
🔧 Debug
advanced
2:00remaining
Identify 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?
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)
ALogical error: uses element-wise multiplication instead of matrix multiplication.
BTypeError due to incompatible shapes in multiplication.
CSyntaxError due to missing colon in for loop.
DNo error; code runs and prints final state.
Attempts:
2 left
💡 Hint
Check how matrix multiplication is done in numpy. '*' does element-wise multiplication, '@' does matrix multiplication.
🚀 Application
expert
2:30remaining
Predict 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?
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))
A0.3
B0.5
C1.1
D0.7
Attempts:
2 left
💡 Hint
Calculate x at step 1 and 2, then compute y = C*x at step 2.

Practice

(1/5)
1. What does a discrete state-space model in Simulink primarily represent?
easy
A. A continuous-time system with differential equations
B. A graphical user interface for designing circuits
C. A system described by matrices that updates states step-by-step
D. A tool for creating 3D animations

Solution

  1. 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.
  2. 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.
  3. Final Answer:

    A system described by matrices that updates states step-by-step -> Option C
  4. Quick Check:

    Discrete state-space = step-by-step matrix system [OK]
Hint: Discrete means step-by-step matrix updates [OK]
Common Mistakes:
  • Confusing discrete with continuous systems
  • Thinking state-space is only for continuous models
  • Mixing up state-space with graphical tools
2. Which of the following is the correct syntax to define a discrete state-space system in Simulink's MATLAB Function block?
easy
A. sys = ss(A, B, C, D);
B. sys = ss(A, B, C, D, Ts);
C. sys = discrete(A, B, C, D, Ts);
D. sys = state_space(A, B, C, D, Ts);

Solution

  1. 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.
  2. 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.
  3. Final Answer:

    sys = ss(A, B, C, D, Ts); -> Option B
  4. Quick Check:

    Discrete ss needs sample time Ts [OK]
Hint: Discrete ss needs sample time Ts as last argument [OK]
Common Mistakes:
  • Omitting the sample time Ts
  • Using wrong function names like discrete()
  • Confusing continuous and discrete syntax
3. Given the discrete state-space matrices:
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?
medium
A. [1.6; 0.1]
B. [1.0; 0.05]
C. [1.8; 0.0]
D. [0.9; 0.1]

Solution

  1. 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]
  2. Step 2: Add results to get x[1]

    x[1] = [0.7; 0] + [0.2; 0.1] = [0.9; 0.1]
  3. Final Answer:

    [0.9; 0.1] -> Option D
  4. Quick Check:

    Use x[1] = A*x0 + B*u[0] [OK]
Hint: Multiply A*x0 and add B*u[0] for next state [OK]
Common Mistakes:
  • Forgetting to multiply input u by B
  • Mixing matrix multiplication order
  • Adding instead of multiplying matrices
4. You have this discrete state-space model in Simulink:
A = [[1, 0], [0, 1]];
B = [[0], [0]];
C = [[1, 0]];
D = [[0]];
Why does the output never change regardless of input?
medium
A. Because matrix B is zero, input has no effect on state
B. Because matrix C is zero, output is always zero
C. Because matrix A is identity, states never update
D. Because matrix D is zero, output ignores input

Solution

  1. 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].
  2. 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.
  3. Final Answer:

    Because matrix B is zero, input has no effect on state -> Option A
  4. Quick Check:

    Zero B means input can't change state [OK]
Hint: Zero B means input can't change state [OK]
Common Mistakes:
  • Confusing zero D with zero B effect
  • Assuming identity A means output changes
  • Ignoring input effect on state update
5. You want to design a discrete state-space model in Simulink to simulate a system with states updated every 0.1 seconds. The system matrices are:
A = [[0.8, 0.1], [0, 0.9]];
B = [[0.05], [0.02]];
Which sample time should you specify to correctly model this system?
hard
A. 0.1
B. 1
C. 0
D. -0.1

Solution

  1. 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.
  2. Step 2: Choose correct sample time

    Ts must be positive and equal to the update interval, so Ts = 0.1 seconds.
  3. Final Answer:

    0.1 -> Option A
  4. Quick Check:

    Sample time = update interval = 0.1 [OK]
Hint: Sample time equals system update interval (positive) [OK]
Common Mistakes:
  • Using zero or negative sample time
  • Confusing sample time with continuous time
  • Choosing wrong units for sample time
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