---
title: State-space models
heading: Systems as first-order matrix equations
eyebrow: C9 · Lesson 45 · State-space models
xp: 40
---

::: hook
Transfer functions describe a system from the outside: input in, output out. A state-space model describes it from the inside, with a short list of numbers, the **state**, that captures everything about the system's past that matters for its future: a capacitor's voltage, an inductor's current, a motor's position and speed. The state changes by a first-order matrix equation, which is how simulators step systems forward in time, how controllers estimate what they can't measure, and the natural way to handle several inputs and outputs at once. The poles turn out to be the eigenvalues of a matrix.
:::

::: play
- A damped oscillator, $x_1' = x_2$ and $x_2' = -\omega_n^2x_1 - 2\zeta\omega_nx_2$, drawn as a **phase portrait**: the state $(x_1, x_2)$ moves along the arrows, and the curves are paths from two starting states.
- With small ζ the path spirals in slowly: an underdamped ringing. Raise ζ past 1 and the spiral straightens: no oscillation.
- Set ζ to 0: the paths are closed loops, oscillating forever. The readouts are the eigenvalues of the matrix, the system's poles.
:::
:::

```sim plot
view: flow
x: x1 = -2..2
y: x2 = -3..3
slider: wn = 0.5..3 = 1.5 step 0.1
slider: z = 0..1.5 = 0.2 step 0.05
dx: x2
dy: -wn^2*x1 - 2*z*wn*x2
start: 1.6, 0 | label: start
start: -1, 2.5 | quiet
readout: poles' real part = -z*wn | digits: 3
readout: poles' imaginary part (if ζ < 1) = wn*sqrt(abs(1 - z^2))*step(1 - z) | digits: 3
```

::: predict
## A system has $A = \begin{bmatrix} 0 & 1 \\ -4 & -4 \end{bmatrix}$. What are its poles?

- [ ] −1 and −4
- [x] −2, twice
- [ ] −2 ± 2j
- [ ] 0 and −4

::: reveal
−2, twice. The eigenvalues solve $\det(sI - A) = s^2 + 4s + 4 = (s + 2)^2 = 0$. That's critical damping, ζ = 1: the fastest response with no overshoot.
:::
:::

::: nameit
## The model

$$\mathbf{x}' = A\mathbf{x} + B\mathbf{u}, \qquad \mathbf{y} = C\mathbf{x} + D\mathbf{u}$$

The state $\mathbf{x}$ has one entry per energy store (capacitor voltages, inductor currents, positions and velocities), so its length is the system's order.

**From a differential equation.** $y'' + a_1y' + a_0y = b_0u$ with $x_1 = y$, $x_2 = y'$:

$$A = \begin{bmatrix} 0 & 1 \\ -a_0 & -a_1 \end{bmatrix},\quad B = \begin{bmatrix} 0 \\ b_0 \end{bmatrix},\quad C = \begin{bmatrix} 1 & 0 \end{bmatrix},\quad D = 0$$

**From a circuit.** A series RLC driven by $v_s$, with states $v_C$ and $i_L$: $v_C' = i_L/C$ and $i_L' = (v_s - v_C - Ri_L)/L$.

## Poles and transfer function

The poles are the eigenvalues of A, the roots of $\det(sI - A) = 0$. For a 2 × 2 matrix that's

$$s^2 - (\operatorname{tr} A)\,s + \det A = 0$$

so the eigenvalues add to the trace and multiply to the determinant. The transfer function is $H(s) = C(sI - A)^{-1}B + D$, and its DC gain is $D - CA^{-1}B$.

## Discrete time and simulation

$\mathbf{x}[n+1] = A\mathbf{x}[n] + B\mathbf{u}[n]$ is stable when every eigenvalue of A has magnitude below 1. Simulating the continuous model with Euler's method, $\mathbf{x} \leftarrow \mathbf{x} + h(A\mathbf{x} + B\mathbf{u})$, is a discrete system with matrix $I + hA$; for $x' = -ax$ that's $1 - ah$, stable only if $h < 2/a$, which is why stiff systems need small steps or implicit methods (A8).
:::

::: example
## Write $y'' + 3y' + 2y = u$ in state space and find its poles and DC gain.

::: solution
1. **State matrices.**
   $$A = \begin{bmatrix} 0 & 1 \\ -2 & -3\end{bmatrix}$$
   with $B = [0, 1]^T$ and $C = [1, 0]$.
2. **Poles.** Trace −3, determinant 2:
   $$s^2 + 3s + 2 = 0$$
   gives −1 and −2.
3. **DC gain.** Set y' = y'' = 0, so y = u/2: a DC gain of 0.5.

**Answer:** poles at −1 and −2, and a DC gain of 0.5.
:::
:::

::: example
## A series RLC has R = 2 Ω, L = 1 H, C = 0.5 F. Find A and its eigenvalues.

::: solution
1. **State equations.**
   $$\begin{aligned} v_C' &= 2i_L \\ i_L' &= -v_C - 2i_L + v_s \end{aligned}$$
2. **The A matrix.**
   $$A = \begin{bmatrix} 0 & 2 \\ -1 & -2\end{bmatrix}$$
3. **Eigenvalues.** Trace −2, determinant 2:
   $$s^2 + 2s + 2 = 0$$
   so s = −1 ± j.
4. **Natural frequency and damping.** So $\omega_n = \sqrt2$ and $\zeta = 1/\sqrt2$.

**Answer:** A has rows [0, 2] and [−1, −2], and its eigenvalues are −1 ± j.
:::
:::

::: example
## $\dot x_1 = -x_1 + x_2$, $\dot x_2 = -2x_2$, with $x(0) = (1, 1)$. Find the eigenvalues and $x_1(1)$.

::: solution
1. **Eigenvalues.** A is upper triangular, so the eigenvalues are its diagonal: −1 and −2.
2. **The second state.**
   $$x_2 = e^{-2t}$$
3. **The first state.** With $x_1(0) = 1$, the solution of $\dot x_1 + x_1 = e^{-2t}$ is
   $$x_1 = 2e^{-t} - e^{-2t}$$
4. **At t = 1.**
   $$\begin{aligned} x_1(1) &= 2e^{-1} - e^{-2} \\ &= 0.600 \end{aligned}$$
   The slower mode, $e^{-t}$, dominates after a second.

**Answer:** the eigenvalues are −1 and −2, and $x_1(1)$ = 0.600.
:::
:::

::: check
kind: parts
given: a0 = 4 | 9 | 25; a1 = 1 | 3 | 6

## $y'' + \given{a1}y' + \given{a0}y = u$ is written in state space with $x_1 = y$, $x_2 = y'$.

::: part
answer: -a0
tolerance: 0.5%

### What is the bottom-left entry of A?

::: misses
- [a0] $x_2' = y'' = -a_0y - a_1y' + u$.
- [any] Not yet. $-a_0$.
:::
:::

::: part
answer: a1/(2*sqrt(a0))
tolerance: 0.5%

### What is the damping ratio of its poles?

::: misses
- [any] $s^2 + a_1s + a_0$: $\zeta = a_1/(2\sqrt{a_0})$.
:::
:::
:::

::: check
kind: parts
given: p = 1 | -2; q = 3 | 0.5; r = -2 | 4; t = -5 | -1

## $A = \begin{bmatrix} \given{p} & \given{q} \\ \given{r} & \given{t} \end{bmatrix}$.

::: part
answer: p + t
tolerance: 0.5%

### What do its eigenvalues add up to?

::: misses
- [any] The trace.
:::
:::

::: part
answer: p*t - q*r
tolerance: 0.5%

### What do they multiply to?

::: misses
- [p*t + q*r] $\det A = pt - qr$.
- [any] Not yet. The determinant.
:::
:::
:::

::: check
given: b0 = 2 | 5; a0 = 4 | 10; a1 = 1 | 3
answer: b0/a0
tolerance: 0.5%

## What is the DC gain of $y'' + \given{a1}y' + \given{a0}y = \given{b0}u$?

::: right
Right. At rest y' = y'' = 0, so y = {b0}u/{a0}: {answer}.
:::

::: misses
- [b0/a1] At DC the derivatives vanish; only $a_0$ remains.
- [any] Not yet. Set the derivatives to zero.
:::
:::

::: check
kind: parts
given: R = 1 | 10; L = 0.5 | 2; C = 0.1 | 0.01

## A series RLC (R = {R} Ω, L = {L} H, C = {C} F) has states $v_C$ and $i_L$.

::: part
answer: -R/L
tolerance: 0.5%

### What is the entry of A giving $i_L$'s dependence on itself?

::: misses
- [any] $i_L' = (v_s - v_C - Ri_L)/L$.
:::
:::

::: part
answer: 1/sqrt(L*C)
unit: rad/s
tolerance: 0.5%

### What is $\omega_n$?

::: misses
- [any] $\det A = 1/(LC)$.
:::
:::
:::

::: check
given: a = 0.5 | 0.8; b = 0.1 | 0.2; c = 0.2 | 0.1; d = 0.3 | 0.4
answer: ((a + d) + sqrt((a - d)^2 + 4*b*c))/2
tolerance: 0.5%

## A discrete system has $A = \begin{bmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{bmatrix}$ (real eigenvalues). What is its larger eigenvalue?

::: right
Right. {answer}, inside the unit circle, so the system is stable.
:::

::: misses
- [any] Not yet. Solve $\lambda^2 - (a + d)\lambda + (ad - bc) = 0$.
:::
:::

::: check
given: a = 10 | 100 | 1000
answer: 2/a
unit: s
tolerance: 0.5%

## Euler's method simulates $x' = -\given{a}x$ with step h. Above what h does the simulation blow up?

::: right
Right. $x \leftarrow (1 - ah)x$ grows when $\lvert 1 - ah\rvert > 1$: h > 2/a = {answer} s.
:::

::: misses
- [1/a] At h = 1/a the factor is 0; it's at 2/a that it reaches −1.
- [any] Not yet. Find where $\lvert 1 - ah\rvert = 1$.
:::
:::

::: check
kind: choice

## How many state variables does a circuit with two capacitors and one inductor (no loops of only capacitors, no cutsets of only inductors) need?

- [ ] 1
- [ ] 2
- [x] 3
- [ ] 6

::: misses
- [1] Each independent energy store needs its own state.
- [2] Count the inductor too.
- [4] One per element, not two.
:::
:::

::: check
kind: parts
given: T = -5 | -7 | -9; D = 2 | 4 | 6

## A 2 × 2 matrix A has trace {T} and determinant {D}.

::: part
answer: T/2 + sqrt(T^2/4 - D)
tolerance: 0.5%

### What is its eigenvalue nearer zero?

::: misses
- [any] $T/2 + \sqrt{T^2/4 - D}$.
:::
:::

::: part
answer: T/2 - sqrt(T^2/4 - D)
tolerance: 0.5%

### And the other?

::: misses
- [any] $T/2 - \sqrt{T^2/4 - D}$.
:::
:::
:::

::: check
kind: parts
given: a = 0.5 | 2 | 10; b = 1 | 4; c = 2 | 3

## $\dot x = -\given{a}x + \given{b}u$, $y = \given{c}x$.

::: part
answer: c*b/a
tolerance: 0.5%

### What is its DC gain?

::: misses
- [c*b] At DC, $\dot x = 0$: x = bu/a.
- [any] $cb/a$.
:::
:::

::: part
answer: 1/a
unit: s
tolerance: 0.5%

### What is its time constant?

::: misses
- [any] 1/a.
:::
:::
:::

::: explain
## Why are a state-space model's poles the eigenvalues of A?

::: model
With no input, the state obeys $\mathbf{x}' = A\mathbf{x}$. If the state starts along an eigenvector v of A with eigenvalue λ, then $Av = \lambda v$ and the solution is just $e^{\lambda t}v$: that direction grows or decays on its own as $e^{\lambda t}$. Any starting state is a combination of eigenvectors, so the free response is a sum of such exponentials, one per eigenvalue. Those are exactly the system's natural modes, which is what poles are; equivalently, $(sI - A)^{-1}$ in the transfer function blows up when $\det(sI - A) = 0$.
:::
:::

::: practice

::: check
given: p = 2 | -3; t = -6 | -1
answer: p + t
tolerance: 0.5%

## Sum of the eigenvalues of a matrix with diagonal {p} and {t}?

::: misses
- [any] The trace.
:::
:::

::: check
given: a0 = 16 | 36; a1 = 2 | 4
answer: a1/(2*sqrt(a0))
tolerance: 0.5%

## Damping ratio of $y'' + \given{a1}y' + \given{a0}y = u$?

::: misses
- [any] $a_1/(2\sqrt{a_0})$.
:::
:::

::: check
given: a = 2 | 5 | 10 | 20 | 50 | 100 | 200
answer: 2/a
unit: s
tolerance: 0.5%

## Largest stable Euler step for $x' = -\given{a}x$?

::: misses
- [any] 2/a.
:::
:::
:::
