A-B-C-D

State Space

Continuous
Run the live example Free · no sign-up · runs in your browser

The StateSpace block implements general continuous-time linear time-invariant (LTI) dynamic systems formulated in matrix state-space notation. Representing plants via internal state vectors (x\mathbf{x}), input vectors (u\mathbf{u}), and output measurement vectors (y\mathbf{y}), it is the cornerstone of modern control theory, multivariable (MIMO) systems, Kalman filtering, Linear Quadratic Regulators (LQR), and structural modal analysis. The block parses standard MATLAB/matrix syntax, supports multiple inputs and outputs, and integrates state trajectories using high-order WASM ODE solvers.

Mathematical Model

The continuous state-space system is described by the first-order vector differential state equation and algebraic output equation:

x˙(t)=Ax(t)+Bu(t)y(t)=Cx(t)+Du(t)\begin{aligned} \dot{\mathbf{x}}(t) &= \mathbf{A}\mathbf{x}(t) + \mathbf{B}\mathbf{u}(t) \\ \mathbf{y}(t) &= \mathbf{C}\mathbf{x}(t) + \mathbf{D}\mathbf{u}(t) \end{aligned}

where:

  • x(t)∈Rn\mathbf{x}(t) \in \mathbb{R}^n is the nn-dimensional state vector
  • u(t)∈Rm\mathbf{u}(t) \in \mathbb{R}^m is the mm-dimensional input vector
  • y(t)∈Rp\mathbf{y}(t) \in \mathbb{R}^p is the pp-dimensional output vector
  • A∈Rn×n\mathbf{A} \in \mathbb{R}^{n \times n} is the state transition matrix
  • B∈Rn×m\mathbf{B} \in \mathbb{R}^{n \times m} is the input coupling matrix
  • C∈Rp×n\mathbf{C} \in \mathbb{R}^{p \times n} is the output measurement matrix
  • D∈Rp×m\mathbf{D} \in \mathbb{R}^{p \times m} is the direct feedthrough matrix

The eigenvalues of matrix A\mathbf{A} define the system poles:

det⁡(λI−A)=0\det(\lambda \mathbf{I} - \mathbf{A}) = 0

The system is asymptotically stable if and only if all eigenvalues of A\mathbf{A} have strictly negative real parts (Re⁡(λi)<0\operatorname{Re}(\lambda_i) < 0). In the frequency domain, the equivalent p×mp \times m transfer function matrix is given by:

G(s)=C(sI−A)−1B+D\mathbf{G}(s) = \mathbf{C}(s\mathbf{I} - \mathbf{A})^{-1}\mathbf{B} + \mathbf{D}

Inputs & Outputs

Direction ID Label Type Status
→ In u Input(s) number Required
→ In reset Reset number Optional
← Out y Output(s) number Output

Parameters

Parameters Label Type Default Description
A A Matrix (state) matrix -1
B B Matrix (input) matrix 1
C C Matrix (output) matrix 1
D D Matrix (feedthrough) vector 0
initialState Initial State (comma-sep) vector 0

Usage Examples

Example 1: Inverted Pendulum on a Cart Linearized State-Space Model

Modeling an inverted pendulum around its upright unstable equilibrium with state vector x=[x,x˙,θ,θ˙]T\mathbf{x} = [x, \dot{x}, \theta, \dot{\theta}]^T. Setting A = "0 1 0 0; 0 -0.1 2.5 0; 0 0 0 1; 0 -0.2 28.5 0", B = "0; 1.5; 0; 3.0", C = "1 0 0 0; 0 0 1 0" (measuring cart position and pendulum angle), D = "0; 0", and initialState = "0, 0, 0.05, 0". This enables testing state-feedback stabilization (u=−Kxu = -\mathbf{K}\mathbf{x}) from an initial tilt of 0.05 rad0.05\text{ rad}.

Example 2: Two-Mass Resonant Drive Transmission

Modeling a dual-inertia motor-load coupling with states for motor velocity, load velocity, and shaft twist angle. Configuring A = "-0.2 0 -5; 0 -0.1 5; 1 -1 0", B = "1; 0; 0", C = "0 1 0", and D = "0". The system captures resonant torsional oscillations and shaft torque transmission during motor acceleration steps.

Remarks & Best Practices

  • Matrix Dimension Consistency: Matrix dimensions must be strictly consistent: if A\mathbf{A} is n×nn \times n, then B\mathbf{B} must be n×mn \times m, C\mathbf{C} must be p×np \times n, and D\mathbf{D} must be p×mp \times m. Dimension mismatches trigger a configuration error.
  • Multivariable MIMO Support: Supports multi-input multi-output architectures; input and output ports automatically adapt to the column count of B\mathbf{B} and row count of C\mathbf{C}.
  • High-Order Stiff Solvers: Evaluated in Rust/WASM across explicit Runge-Kutta (RK4, RK45) and stiff implicit TR-BDF2 solvers, ensuring numerical stability even for stiff matrices with widely separated eigenvalues.
  • External Reset Action: Asserting a positive value on the optional reset port resets the state vector x(t)\mathbf{x}(t) back to the initial conditions specified in initialState.

Frequently Asked Questions (FAQ)

Q: How to select weighting matrices Q and R for Linear Quadratic Regulator (LQR)?

Use Bryson's Rule as an engineering baseline: set diagonal elements to Qii=1(xi,max⁡)2Q_{ii} = \frac{1}{(x_{i,\max})^2} and Rjj=1(uj,max⁡)2R_{jj} = \frac{1}{(u_{j,\max})^2}, where xi,max⁡x_{i,\max} is the maximum acceptable deviation for state ii and uj,max⁡u_{j,\max} is the maximum actuator excursion. This normalizes all state penalties and control efforts to non-dimensional units, allowing intuitive trade-offs between response speed and actuator effort.

Q: How does State-Space compare to Transfer Function representation?

Transfer functions G(s)=Y(s)/U(s)G(s) = Y(s)/U(s) describe single-input single-output (SISO) input-output dynamics under zero initial conditions, hiding internal plant dynamics. State-Space models (x˙=Ax+Bu,y=Cx+Du\dot{x} = Ax + Bu, y = Cx + Du) naturally handle multi-input multi-output (MIMO) systems, non-zero initial conditions, and internal observability and controllability structures.

Related Components

  • TransferFunction: Single-input single-output transfer function B(s)/A(s)B(s)/A(s).
  • ZeroPole: Zero-pole-gain factored representation K∏(s−zi)/∏(s−pj)K \prod(s - z_i) / \prod(s - p_j).
  • Integrator: Continuous 1/s1/s single-state integrator.
  • SecondOrderSystem: Second-order continuous oscillator model.