Bird
Raised Fist0
Simulinkdata~10 mins

State-space block in Simulink - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - State-space block
Input u(t)
↓
State-space block
↓
Calculate x_dot = A*x + B*u
↓
Update state x(t+dt) = x(t) + x_dot*dt
↓
Calculate output y = C*x + D*u
↓
Output y(t)
The State-space block takes input u(t), updates the system state x(t) using matrices A and B, then computes output y(t) using matrices C and D.
Execution Sample
Simulink
A = [[0,1],[-2,-3]]
B = [[0],[1]]
C = [[1,0]]
D = [[0]]
x = [0,0]
u = 1
dt = 0.1
x_dot = [A[0][0]*x[0] + A[0][1]*x[1] + B[0][0]*u, A[1][0]*x[0] + A[1][1]*x[1] + B[1][0]*u]
x_next = [x[0] + x_dot[0]*dt, x[1] + x_dot[1]*dt]
y = C[0][0]*x[0] + C[0][1]*x[1] + D[0][0]*u
This code calculates the next state and output of a system using state-space equations with given matrices and input.
Execution Table
Stepxux_dotx_nextyDescription
1[0, 0]1[0*0+1*0 + 0*1, -2*0 -3*0 + 1*1] = [0, 1][0+0*0.1, 0+1*0.1] = [0, 0.1][1*0 + 0*0] = 0Initial state x and input u given
2[0, 0.1]1[0*0 + 1*0.1 + 0*1, -2*0 -3*0.1 + 1*1] = [0.1, 0.7][0+0.1*0.1, 0.1+0.7*0.1] = [0.01, 0.17][1*0 + 0*0.1] = 0Calculate x_dot, update x, compute y
3[0.01, 0.17]1[0*0.01 + 1*0.17 + 0*1, -2*0.01 -3*0.17 + 1*1] = [0.17, 0.49][0.01+0.17*0.1, 0.17+0.49*0.1] = [0.027, 0.219][1*0.01 + 0*0.17] = 0.01Repeat calculation for next step
4[0.027, 0.219]1[0*0.027 + 1*0.219 + 0*1, -2*0.027 -3*0.219 + 1*1] = [0.219, 0.103][0.027+0.219*0.1, 0.219+0.103*0.1] = [0.049, 0.229][1*0.027 + 0*0.219] = 0.027Continue updating state and output
5[0.049, 0.229]1[0*0.049 + 1*0.229 + 0*1, -2*0.049 -3*0.229 + 1*1] = [0.229, -0.123][0.049+0.229*0.1, 0.229-0.123*0.1] = [0.072, 0.217][1*0.049 + 0*0.229] = 0.049State and output updated again
6[0.072, 0.217]1[0*0.072 + 1*0.217 + 0*1, -2*0.072 -3*0.217 + 1*1] = [0.217, -0.345][0.072+0.217*0.1, 0.217-0.345*0.1] = [0.094, 0.182][1*0.072 + 0*0.217] = 0.072Process continues
7[0.094, 0.182]1[0*0.094 + 1*0.182 + 0*1, -2*0.094 -3*0.182 + 1*1] = [0.182, -0.537][0.094+0.182*0.1, 0.182-0.537*0.1] = [0.112, 0.128][1*0.094 + 0*0.182] = 0.094Next iteration
8[0.112, 0.128]1[0*0.112 + 1*0.128 + 0*1, -2*0.112 -3*0.128 + 1*1] = [0.128, -0.683][0.112+0.128*0.1, 0.128-0.683*0.1] = [0.125, 0.059][1*0.112 + 0*0.128] = 0.112State and output updated
9[0.125, 0.059]1[0*0.125 + 1*0.059 + 0*1, -2*0.125 -3*0.059 + 1*1] = [0.059, -0.768][0.125+0.059*0.1, 0.059-0.768*0.1] = [0.131, -0.018][1*0.125 + 0*0.059] = 0.125State moves closer to steady state
10[0.131, -0.018]1[0*0.131 + 1*(-0.018) + 0*1, -2*0.131 -3*(-0.018) + 1*1] = [-0.018, -0.683][0.131-0.018*0.1, -0.018-0.683*0.1] = [0.129, -0.086][1*0.131 + 0*(-0.018)] = 0.131Final step shown
ExitSimulation stops after 10 steps
💡 Simulation stops after 10 steps as example trace ends
Variable Tracker
VariableStartAfter 1After 2After 3After 4After 5After 6After 7After 8After 9After 10
x[0, 0][0, 0.1][0.01, 0.17][0.027, 0.219][0.049, 0.229][0.072, 0.217][0.094, 0.182][0.112, 0.128][0.125, 0.059][0.131, -0.018][0.129, -0.086]
y000.010.0270.0490.0720.0940.1120.1250.1310.129
Key Moments - 3 Insights
Why does the state x update using x + x_dot * dt instead of just x_dot?
Because x_dot is the rate of change of state, we multiply by the small time step dt to get the change in state, then add it to the current state x. This is shown in execution_table rows where x_next is calculated.
Why is output y calculated as C*x + D*u and not just C*x?
The output depends on both the current state x and the input u, weighted by matrices C and D respectively. In the example, D is zero, so y = C*x only, but the formula includes D*u for general cases.
What happens if the input u changes during simulation?
The input u affects x_dot and y at each step. If u changes, the values in execution_table for x_dot, x_next, and y would change accordingly, showing different system behavior.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 3. What is the value of x_dot?
A[0.1, 0.7]
B[0.17, 0.49]
C[0, 1]
D[0.219, 0.103]
💡 Hint
Check the 'x_dot' column at Step 3 in the execution_table.
At which step does the output y first become greater than 0?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'y' column in execution_table rows to find when y > 0.
If the input u was changed to 0 at Step 5, what would happen to x_dot at Step 6?
AIt would decrease
BIt would increase
CIt would stay the same
DIt would become zero
💡 Hint
Since x_dot depends on B*u, setting u=0 removes that term, likely decreasing x_dot values.
Concept Snapshot
State-space block models dynamic systems using matrices A, B, C, D.
State x updates by x_dot = A*x + B*u, then x_next = x + x_dot*dt.
Output y is computed as y = C*x + D*u.
Input u affects both state change and output.
Used for simulating linear time-invariant systems.
Full Transcript
The State-space block in Simulink calculates system behavior by updating the state vector x using the equation x_dot = A*x + B*u, where A and B are matrices and u is the input. The state is updated incrementally by adding x_dot times the time step dt to the current state. The output y is computed as y = C*x + D*u, where C and D are output matrices. This process repeats each simulation step, showing how the system evolves over time. The execution table traces these calculations step-by-step, showing how x, x_dot, x_next, and y change. Key points include understanding why the state updates incrementally and how input u influences the system. The visual quiz tests understanding of these stepwise changes.

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