Skip to main content

State-Space Representation

State-space representation is the working language of simulation because it expresses a dynamic model as first-order differential equations. Higher-order equations, coupled component models, and nonlinear systems can all be written in this form. Once a model is in state-space form, a numerical solver only needs a function that maps the current time, current state, and current input to the state derivative.

This representation also separates model structure from implementation. MATLAB functions such as ode45, ss, lsim, and step operate naturally on state equations, and Simulink's Integrator and State-Space blocks are built around the same idea. Transfer functions are useful for linear input-output analysis, but state-space models keep the internal variables visible, which is essential when validating simulations against measured states or checking physical constraints.

Definitions

A continuous-time nonlinear state-space model is

x˙=f(x,u,t),y=g(x,u,t).\dot{\mathbf{x}}=\mathbf{f}(\mathbf{x},\mathbf{u},t), \qquad \mathbf{y}=\mathbf{g}(\mathbf{x},\mathbf{u},t).

Here xRn\mathbf{x}\in\mathbb{R}^n is the state vector, uRm\mathbf{u}\in\mathbb{R}^m is the input vector, and yRp\mathbf{y}\in\mathbb{R}^p is the output vector. The model order is nn, the number of states.

The linear time-invariant state-space model is

x˙=Ax+Bu,y=Cx+Du.\dot{\mathbf{x}}=A\mathbf{x}+B\mathbf{u}, \qquad \mathbf{y}=C\mathbf{x}+D\mathbf{u}.

The matrix dimensions are

ARn×n,BRn×m,CRp×n,DRp×m.A\in\mathbb{R}^{n\times n},\quad B\in\mathbb{R}^{n\times m},\quad C\in\mathbb{R}^{p\times n},\quad D\in\mathbb{R}^{p\times m}.

An initial condition x(0)=x0\mathbf{x}(0)=\mathbf{x}_0 is part of the simulation problem. Without it, the derivative rule is incomplete because many possible trajectories satisfy the same differential equation.

State variables are not unique. A second-order equation can be represented by position and velocity, by position and momentum, or by transformed modal coordinates. Different choices can improve numerical conditioning, interpretability, or compatibility with measured data.

Key results

Any ordinary differential equation that can be solved for the highest derivative can be rewritten as first-order state equations. For

a2y¨+a1y˙+a0y=b0u,a_2\ddot{y}+a_1\dot{y}+a_0y=b_0u,

choose x1=yx_1=y and x2=y˙x_2=\dot{y}. Then

x˙1=x2,x˙2=a0a2x1a1a2x2+b0a2u.\begin{aligned} \dot{x}_1 &= x_2,\\ \dot{x}_2 &= -\frac{a_0}{a_2}x_1-\frac{a_1}{a_2}x_2+\frac{b_0}{a_2}u. \end{aligned}

For an LTI model, the unforced solution is

x(t)=eAtx0.\mathbf{x}(t)=e^{At}\mathbf{x}_0.

With input u(t)\mathbf{u}(t), the solution is

x(t)=eAtx0+0teA(tτ)Bu(τ)dτ.\mathbf{x}(t)=e^{At}\mathbf{x}_0+\int_0^t e^{A(t-\tau)}B\mathbf{u}(\tau)\,d\tau.

This formula is important even when we do not compute the matrix exponential directly. It shows that the eigenvalues of AA control natural modes and that input history is filtered through the same state transition matrix.

The transfer function matrix of an LTI state-space model is

G(s)=C(sIA)1B+D.G(s)=C(sI-A)^{-1}B+D.

This connects state-space simulation to the Laplace-domain tools used in signals, systems, and control. The poles of G(s)G(s) are usually eigenvalues of AA, although cancellations can hide internal modes from a particular input-output channel.

For simulation work, state ordering should be documented as carefully as parameter values. A solver only sees a vector of numbers, so the meaning of x(1) and x(2) must be recoverable from comments, variable names, plots, or block labels. A common professional practice is to keep a short state table with symbol, units, initial value, and physical interpretation. That table prevents mistakes when the derivative function is edited later or when a Simulink model is compared with a MATLAB script.

State scaling also matters. If one state is a voltage near 10310^{-3} and another is a position near 10410^4, a single absolute tolerance can make the solver over-resolve one state and under-resolve another. In MATLAB this can be handled with vector absolute tolerances, nondimensional states, or a scaled state transformation. In Simulink, the same issue appears when logged signals have very different magnitudes and the solver reports tiny steps or inaccurate zero crossings. A state-space representation is therefore not only a mathematical format; it is also a numerical interface.

Visual

FormMain useStrengthLimitation
Higher-order ODECompact scalar physicsFamiliar for simple mechanical or electrical modelsNot directly accepted by general ODE solvers
State-spaceSimulation and multi-input systemsHandles coupled states and nonlinearitiesState choice must be made carefully
Transfer functionLinear input-output analysisEasy poles, zeros, frequency responseHides internal state and initial-condition structure
Block diagramSimulink implementationShows signal flow and feedbackCan obscure equations if blocks are undocumented

Worked example 1: Convert an RLC circuit to state-space form

Problem: A series RLC circuit is driven by an input voltage vs(t)v_s(t). Let R=4 ΩR=4\ \Omega, L=0.5 HL=0.5\ \mathrm{H}, and C=0.1 FC=0.1\ \mathrm{F}. Choose capacitor voltage and inductor current as states. Derive AA and BB for output y=vCy=v_C.

  1. Choose states:
x1=vC,x2=iL.x_1=v_C,\qquad x_2=i_L.
  1. Use capacitor and inductor relations:
iC=Cv˙C,vL=Li˙L.i_C=C\dot{v}_C,\qquad v_L=L\dot{i}_L.

In a series circuit the current through all elements is iL=iCi_L=i_C, so

x˙1=1Cx2=10x2.\dot{x}_1=\frac{1}{C}x_2=10x_2.
  1. Apply Kirchhoff's voltage law:
vs=vR+vL+vC=RiL+Li˙L+vC.v_s=v_R+v_L+v_C=Ri_L+L\dot{i}_L+v_C.
  1. Solve for i˙L\dot{i}_L:
Li˙L=vsRiLvC,L\dot{i}_L=v_s-Ri_L-v_C,

so

x˙2=1Lx1RLx2+1Lvs=2x18x2+2vs.\dot{x}_2=-\frac{1}{L}x_1-\frac{R}{L}x_2+\frac{1}{L}v_s =-2x_1-8x_2+2v_s.
  1. Assemble matrices:
x˙=[01028]x+[02]vs,y=[10]x.\dot{\mathbf{x}}= \begin{bmatrix} 0 & 10\\ -2 & -8 \end{bmatrix}\mathbf{x} + \begin{bmatrix} 0\\ 2 \end{bmatrix}v_s, \qquad y=\begin{bmatrix}1&0\end{bmatrix}\mathbf{x}.

Checked answer: dimensions are consistent: AA is 2×22\times2, BB is 2×12\times1, and CC is 1×21\times2. A unit step in voltage should make vCv_C approach 1 V1\ \mathrm{V} at steady state, because the capacitor is open-circuit in DC and no voltage is dropped across RR or LL after transients.

Simulink description: use a State-Space block with the AA, BB, CC, and D=0D=0 matrices, or build the two equations with Sum, Gain, and Integrator blocks. The time-response plot should show capacitor voltage rising toward the input with possible overshoot depending on damping.

Worked example 2: Build a controllable canonical realization

Problem: The transfer function

G(s)=Y(s)U(s)=3s2+4s+5G(s)=\frac{Y(s)}{U(s)}=\frac{3}{s^2+4s+5}

is to be simulated in state-space form. Construct a realization using x1=yx_1=y and x2=y˙x_2=\dot{y}, and check the step steady state.

  1. Convert the transfer function to a differential equation:
(s2+4s+5)Y(s)=3U(s).(s^2+4s+5)Y(s)=3U(s).

Assuming zero initial conditions, this corresponds to

y¨+4y˙+5y=3u.\ddot{y}+4\dot{y}+5y=3u.
  1. Choose states:
x1=y,x2=y˙.x_1=y,\qquad x_2=\dot{y}.
  1. Write first-order equations:
x˙1=x2,x˙2=5x14x2+3u.\begin{aligned} \dot{x}_1 &= x_2,\\ \dot{x}_2 &= -5x_1-4x_2+3u. \end{aligned}
  1. Assemble output:
y=x1.y=x_1.

Thus

A=[0154],B=[03],C=[10],D=0.A=\begin{bmatrix}0&1\\-5&-4\end{bmatrix}, \quad B=\begin{bmatrix}0\\3\end{bmatrix}, \quad C=\begin{bmatrix}1&0\end{bmatrix}, \quad D=0.
  1. Check the unit-step steady state. At equilibrium, x˙1=x˙2=0\dot{x}_1=\dot{x}_2=0. From the first equation, xˉ2=0\bar{x}_2=0. From the second,
0=5xˉ1+3,xˉ1=0.6.0=-5\bar{x}_1+3, \qquad \bar{x}_1=0.6.

Checked answer: the DC gain is G(0)=3/5=0.6G(0)=3/5=0.6, matching the equilibrium. The time-response plot should show a stable second-order response because the poles of s2+4s+5s^2+4s+5 are 2±j-2\pm j, both in the left half-plane.

Simulink description: this system can be implemented with one Transfer Fcn block using numerator [3] and denominator [1 4 5], or with two Integrator blocks in state form. The state implementation is better when internal velocity-like state x2x_2 must be inspected.

Code

clear; clc; close all;

% RLC state-space model
R = 4; L = 0.5; Ccap = 0.1;
A1 = [0, 1/Ccap; -1/L, -R/L];
B1 = [0; 1/L];
C1 = [1, 0];
D1 = 0;
sys_rlc = ss(A1, B1, C1, D1);

% Transfer function realization
A2 = [0 1; -5 -4];
B2 = [0; 3];
C2 = [1 0];
D2 = 0;
sys_second = ss(A2, B2, C2, D2);

t = linspace(0, 8, 500);
figure;
subplot(2,1,1);
step(sys_rlc, t); grid on;
title('RLC capacitor voltage response');

subplot(2,1,2);
step(sys_second, t); grid on;
title('Second-order realization response');

The MATLAB ss command creates LTI state-space objects that can be plotted directly. For nonlinear or time-varying systems, replace ss with a derivative function and integrate with ode45, ode15s, or another solver. In Simulink, the equivalent compact implementation is a State-Space block; the expanded implementation is an integrator bank with feedback gains matching the rows of AA and feedthrough gains matching BB.

Common pitfalls

  • Using the output as the only state for a second-order model. The derivative of the output is also needed unless the model has been reduced for a valid reason.
  • Confusing BB and CC dimensions. BB maps inputs into state derivatives; CC maps states into outputs.
  • Assuming every transfer function realization exposes the same internal variables. Realizations can be mathematically equivalent but physically different.
  • Forgetting direct feedthrough DD when the output algebraically depends on the input.
  • Ignoring initial conditions when comparing a state-space simulation to a transfer-function step response. Many transfer-function commands default to zero initial state.
  • Treating hidden pole-zero cancellations as harmless. A canceled internal unstable mode can still be dangerous if it corresponds to a real state.

Connections