StateSpace Block
State-space realization: x'=Ax+Bu, y=Cx+Du with A,B,C,D matrices
Open StateSpace in BlockWerk →# StateSpace Block Documentation
Overview
The StateSpace block implements a general state-space linear system described by matrices A, B, C, D:
x' = Ax + Bu (state equation)
y = Cx + Du (output equation)
This is the most general form of linear time-invariant (LTI) systems and is fundamental to modern control theory.
Mathematical Model
ẋ = Ax + Bu
y = Cx + Du
where:
- x ∈ ℝⁿ: state vector (n states)
- u ∈ ℝᵐ: input vector (m inputs)
- y ∈ ℝᵖ: output vector (p outputs)
- A: n×n state matrix
- B: n×m input matrix
- C: p×n output matrix
- D: p×m feedthrough matrix
Where:
- A: n×n state matrix
- B: n×m input matrix
- C: p×n output matrix
- D: p×m feedthrough matrix
Inputs
- Input(s): Multiple numeric inputs (u₁, u₂, ...)
Outputs
- Output(s): Multiple numeric outputs (y₁, y₂, ...)
Parameters
A Matrix (State)
- Description: The n×n state transition matrix
- Format: MATLAB-style matrix string
- Rows separated by semicolons (;)
- Elements separated by spaces
- Examples: "1 2; 3 4" or "[1 0; 0 -2]"
- Default: "-1" (1×1 single pole at -1)
B Matrix (Input)
- Description: The n×m input coupling matrix
- Format: MATLAB-style matrix string
- Default: "1"
C Matrix (Output)
- Description: The p×n output matrix
- Format: MATLAB-style matrix string
- Default: "1"
D Matrix (Feedthrough)
- Description: The p×m direct feedthrough matrix (usually 0 for proper systems)
- Format: MATLAB-style matrix string
- Default: "0"
Initial State
- Description: Initial condition for the state vector
- Format: Comma-separated values
- Default: "0"
Matrix Format Examples
2×2 State Matrix
1 -2
0 -3
2×1 Input Matrix (2 states, 1 input)
0
1
1×2 Output Matrix (1 output, 2 states)
1 0
Examples
Example 1: First-Order System
A simple exponential decay system with time constant τ = 1:
Parameters:
- A: "-1"
- B: "1"
- C: "1"
- D: "0"
This represents: ẋ = -x + u, y = x (or any state)
Example 2: Second-Order Mass-Spring System
m·ẍ + c·ẋ + k·x = u
Let x₁ = position, x₂ = velocity. Then:
ẋ₁ = x₂
ẋ₂ = -k/m·x₁ - c/m·x₂ + 1/m·u
y = x₁ (output position)
Parameters (m=1, c=2, k=1):
- A: "0 1; -1 -2"
- B: "0; 1"
- C: "1 0"
- D: "0"
Example 3: MIMO System (2 inputs, 2 outputs)
A: "0 1 0; 0 0 1; -2 -3 -1"
B: "0 0; 1 0; 0 1"
C: "1 0 0; 0 1 0"
D: "0 0; 0 0"
Common Use Cases
1. Control system design: Implement controllers, observers, compensators 2. Filter design: Digital and analog filters 3. Simulation of mechanical systems: Robot dynamics, vehicle models 4. Power systems: Electrical machine models 5. Aerospace: Aircraft dynamics, satellite attitude control
Numerical Integration
The block uses forward Euler integration for simplicity and stability in most cases:
x[k+1] = x[k] + ẋ[k] · dt
For better accuracy with large sample times, consider using a continuous transfer function approach or a more sophisticated integrator.
Dimension Requirements
The matrices must satisfy strict dimension constraints:
- A: Must be square n×n (n = number of states)
- B: Must be n×m (n states, m inputs)
- C: Must be p×n (p outputs, n states)
- D: Must be p×m (p outputs, m inputs)
If dimensions are inconsistent, the block outputs 0 and skips computation. Verify matrix dimensions match before running the simulation.
Stability Constraints (Forward Euler)
The block uses Forward Euler integration. For stability:
- All eigenvalues of A must satisfy |1 + λ·Δt| < 1
- For a real eigenvalue at -a: requires Δt < 2/a
- Rule of thumb: Δt ≤ 1/(5 × |largest eigenvalue|)
- If the simulation diverges, reduce the sample time
Performance Considerations
- Computational cost: O(n²) for matrix-vector operations (n = number of states)
- Stability: Ensure eigenvalues of A are in the left-half plane (continuous) for stability
- Numerical precision: Works well for n < 20 states; higher orders may accumulate numerical errors
Remarks
- Dimension consistency: Matrix dimensions must satisfy A(n×n), B(n×m), C(p×n), D(p×m) or the block outputs zero
- Euler stability: Forward Euler integration requires Δt < 2/|λ_max|; reduce sample time if simulation diverges
- MIMO support: Full multi-input, multi-output capability; use comma-separated initial states for multi-state systems
- State order: For n > 20 states numerical precision may degrade; consider model reduction
- Feedthrough: If D ≠ 0 the output depends directly on the input (instantaneous response), which can create algebraic loops
See Also
TransferFunction- Alternative representation using transfer functionsZeroPole- Pole-zero form of systemsIntegrator/Derivative- Build state-space blocks from basic componentsProduct,Sum,Gain- Build custom state-space manually