---
title: Systems of equations and state space
heading: Many first-order equations instead of one high-order one
eyebrow: A8 · Lesson 36 · State space, previewed
xp: 40
---

::: hook
A circuit with three capacitors and two inductors gives a fifth-order differential equation, and writing it as one equation is a mess. There's a cleaner way to keep track. Every capacitor's voltage and every inductor's current is something the circuit remembers from one instant to the next. List them all as a vector, and the circuit's whole behavior is one matrix equation: the vector's rate of change is a matrix times the vector. The matrix's eigenvalues from A7 turn out to be the roots you've been finding by hand.

::: play
- This is a series RLC circuit drawn in its **state plane**: the capacitor's voltage across, the inductor's current up. Each segment shows which way the state moves from that point.
- The curve starts at 5 V with no current. Follow it. Where does it end up, and how does it get there?
- Raise R past about 63 Ω. How does the path change? Set R = 0.
:::
:::

```sim plot
view: flow
x: v = -6..6 V
y: i = -200..200 mA
slider: R = 0..120 step 1 = 10 Ω
dx: (i/1000)/10e-6
dy: (-v - R*i/1000)/10e-3*1000
start: 5, 0 | label: start | forward
grid: 18
readout: ζ = R/2*sqrt(10e-6/10e-3)
```

::: predict
## With R = 0, what path does the state follow?

- [ ] A spiral into the middle
- [x] A closed loop, round and round forever
- [ ] A straight line into the middle
- [ ] A spiral outward

::: reveal
A closed loop. With no resistance nothing is lost, so the energy $\tfrac12Cv^2 + \tfrac12Li^2$ stays the same, and that fixes an ellipse in the state plane. Add resistance and every lap loses energy, so the path spirals in; with enough resistance it heads straight for the middle without circling at all.
:::
:::

::: nameit
## State variables and the state equation

**State variables** are the quantities a circuit stores: capacitor voltages and inductor currents. Knowing them now, plus the inputs from now on, is enough to predict everything later. A circuit with $n$ independent energy-storing parts has $n$ state variables, and an $n$th-order equation becomes $n$ first-order ones.

**The series RLC.** Take $v$ (capacitor) and $i$ (inductor). The capacitor's law gives $\dot v = i/C$; the loop around the circuit gives $L\dot i = v_s - v - Ri$. As a matrix:

$$\frac{d}{dt}\begin{bmatrix} v \\ i \end{bmatrix} = \begin{bmatrix} 0 & 1/C \\ -1/L & -R/L \end{bmatrix}\begin{bmatrix} v \\ i \end{bmatrix} + \begin{bmatrix} 0 \\ 1/L \end{bmatrix}v_s$$

which is the general **state equation**

$$\dot{\mathbf{x}} = A\mathbf{x} + B\mathbf{u}$$

**Any high-order equation converts.** For $\ddot y + p\dot y + qy = u$, choose $x_1 = y$ and $x_2 = \dot y$. Then $\dot x_1 = x_2$ and $\dot x_2 = -qx_1 - px_2 + u$, so

$$A = \begin{bmatrix} 0 & 1 \\ -q & -p \end{bmatrix}$$

**Eigenvalues are the characteristic roots.** For the RLC matrix,

$$\det(sI - A) = s^2 + \frac{R}{L}s + \frac{1}{LC}$$

exactly the characteristic polynomial of lesson 17. In general, the natural response is built from $e^{\lambda t}$ for each eigenvalue λ of A, and each eigenvector is a **mode**: a direction in the state plane along which the state simply shrinks (or spirals) without changing direction. The full solution is the matrix exponential, $\mathbf{x}(t) = e^{At}\mathbf{x}(0)$, which course A10 and the controls survey build on.

**Why bother.** State form handles circuits with many loops and many sources without special cases, it's the form computers solve (lesson 45), and it's the language of control systems. The phase portrait in the sim is the state equation drawn directly.
:::

::: example
## Write $\ddot y + 3\dot y + 2y = 0$ in state form and find the eigenvalues.

::: solution
1. **State form.** With $\mathbf{x} = (y, \dot y)$,
   $$\dot{\mathbf{x}} = \begin{bmatrix}0 & 1\\-2 & -3\end{bmatrix}\mathbf{x}$$
2. **Eigenvalues.** Trace $-3$, determinant 2, so
   $$\lambda^2 + 3\lambda + 2 = 0$$
   which gives $\lambda = -1, -2$.

**Answer:** with $\mathbf{x} = (y, \dot y)$ the state matrix has rows $(0, 1)$ and $(-2, -3)$, and its eigenvalues are $-1$ and $-2$.
:::
:::

::: example
## Find the state matrix of a series RLC with $R$ = 10 Ω, $L$ = 1 mH, $C$ = 10 µF, using $\mathbf{x} = (v_C, i_L)$.

::: solution
1. **State equations.**
   $$\begin{aligned} \dot v_C &= i_L/C \\ \dot i_L &= (-v_C - Ri_L)/L \end{aligned}$$
2. **State matrix.**
   $$A = \begin{bmatrix}0 & 10^5\\-1000 & -10^4\end{bmatrix}$$
3. **Check with the determinant.** The determinant $10^8 = \frac{1}{LC}$ gives $\omega_0 = 10^4$ rad/s.

**Answer:** $A$ has rows $(0, 10^5)$ and $(-1000, -10^4)$; its determinant gives $\omega_0 = 10^4$ rad/s.
:::
:::

::: example
## Write $m\ddot x + c\dot x + kx = F$ in state form for $m$ = 2 kg, $c$ = 4 N·s/m and $k$ = 10 N/m, and find the eigenvalues.

::: solution
1. **State form.** With state $(x, \dot x)$, the second row comes from the equation solved for $\ddot x$:
   $$\begin{aligned} &\frac{d}{dt}\begin{bmatrix}x\\\dot x\end{bmatrix} \\ &= \begin{bmatrix}0 & 1\\-k/m & -c/m\end{bmatrix}\begin{bmatrix}x\\\dot x\end{bmatrix} \\ &\quad + \begin{bmatrix}0\\1/m\end{bmatrix}F \end{aligned}$$
2. **Put in the numbers.**
   $$\begin{aligned} &\frac{d}{dt}\begin{bmatrix}x\\\dot x\end{bmatrix} \\ &= \begin{bmatrix}0 & 1\\-5 & -2\end{bmatrix}\begin{bmatrix}x\\\dot x\end{bmatrix} \\ &\quad + \begin{bmatrix}0\\0.5\end{bmatrix}F \end{aligned}$$
3. **Eigenvalues.** They solve
   $$\lambda^2 + 2\lambda + 5 = 0$$
   so $\lambda = -1 \pm 2j$.
4. **What they mean.** It rings at 2 rad/s inside an envelope $e^{-t}$.

**Answer:** the state matrix has rows $(0, 1)$ and $(-5, -2)$ and the input vector is $(0, 0.5)$; the eigenvalues are $-1 \pm 2j$, so it rings at 2 rad/s inside an $e^{-t}$ envelope.
:::
:::

::: check
kind: parts
given: r1 = 1..3 int; r2 = 4..6 int; let p = r1 + r2; let q = r1*r2

## Write $\ddot y + \given{p}\dot y + \given{q}y = 0$ in state form with $x_1 = y$, $x_2 = \dot y$, as $\dot{\mathbf{x}} = A\mathbf{x}$.

::: part
answer: -q
tolerance: 0.5%

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

::: misses
- [q] Move $qy$ to the other side: $\ddot y = -qy - p\dot y$.
- [-p] That's the bottom-right entry, the one multiplying $x_2 = \dot y$.
- [any] The second row says $\dot x_2 = \ddot y = -qx_1 - px_2$.
:::
:::

::: part
answer: -r1
tolerance: 0.5%

### What is the eigenvalue of A closest to zero?

::: misses
- [-r2] That's the faster one.
- [r1] Eigenvalues of a damped system are negative.
- [any] Solve $\det(sI - A) = s^2 + \given{p}s + \given{q} = 0$.
:::
:::

::: right
Right. The eigenvalues are −{r1} and −{r2}: the slower mode, $e^{-\given{r1}t}$, takes longest to fade.
:::
:::

::: check
given: R = 10..1k E12 Ω; L = 1m..100m E6 H
answer: -R/L
tolerance: 1%

## In the RLC state matrix with R = {R} and L = {L}, what is the bottom-right entry, in 1/s?

::: right
Right. $-R/L$ = {answer}: the resistor drains the inductor's current.
:::

::: misses
- [R/L] It's negative: resistance always slows the current.
- [-L/R] Upside down: it's $-R/L$.
- [any] Not yet. From $L\dot i = -v - Ri$, the coefficient of $i$ in $\dot i$ is $-R/L$.
:::
:::

::: check
kind: choice

## A circuit has two capacitors and one inductor, none of them in parallel or series with each other. How many state variables does it need?

- [ ] One
- [ ] Two
- [x] Three
- [ ] Six

::: right
Right. One for each independent energy-storing part: two voltages and one current.
:::

::: misses
- [1] Each capacitor and inductor remembers something separately.
- [2] Count the inductor too.
- [4] One state variable per energy-storing part, not two.
:::
:::

::: check
given: a = 2..5 int; d = 6..9 int; b = 1..3 int
answer: -a
tolerance: 0.5%

## What is the slower eigenvalue of $A = \begin{bmatrix} -\given{a} & \given{b} \\ 0 & -\given{d} \end{bmatrix}$?

::: right
Right. A triangular matrix has its eigenvalues on its diagonal: −{a} and −{d}, and −{a} is closer to zero.
:::

::: misses
- [-d] That one decays faster.
- [b] Off-diagonal entries of a triangular matrix don't change its eigenvalues.
- [any] Not yet. For a triangular matrix, the eigenvalues are the diagonal entries.
:::
:::

::: check
kind: choice

## In a state-plane picture, the path spirals into the origin. What kind of response is this?

- [x] Underdamped
- [ ] Overdamped
- [ ] Undamped
- [ ] Unstable

::: right
Right. Circling means oscillation; moving inward means it decays.
:::

::: misses
- [2] Overdamped paths head into the origin without circling.
- [3] Undamped paths are closed loops.
- [4] Unstable paths move away from the origin.
:::
:::

::: check
kind: parts
given: m = 2 | 4; c = 2 | 6; k = 10 | 20

## Put $m\ddot x + c\dot x + kx = F$ with $m$ = {m}, $c$ = {c}, $k$ = {k} in state form $(x, \dot x)$.

::: part
answer: -k/m
tolerance: 0.5%

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

::: misses
- [-k] Divide by the mass.
- [any] $\ddot x = -\frac kmx - \frac cm\dot x + \frac Fm$.
:::
:::

::: part
answer: -c/m
tolerance: 0.5%

### What is the trace of $A$?

::: misses
- [any] The trace is the bottom-right entry, $-c/m$.
:::
:::
:::

::: check
kind: derivation
vars: R = 1..20, L = 0.1..2, C = 0.1..2

## Write a series RLC in state form with $\mathbf{x} = (v_C, i_L)$: $C\dot v_C = i_L$ and $L\dot i_L = -v_C - Ri_L$.

::: step
answer: -R/L

### What is the bottom-right entry of $A$?
:::

::: step
answer: 1/(L*C)

### What is $\det A$?
:::

::: right
Right. Trace $-R/L$ and determinant $\frac{1}{LC}$: the characteristic equation is $s^2 + \frac RLs + \frac{1}{LC} = 0$.
:::
:::

::: explain
## Why are capacitor voltages and inductor currents the natural choice of state variables for a circuit?

::: model
They're the quantities a circuit can't change instantly: a capacitor's voltage needs charge to flow, and an inductor's current needs time to build or collapse. So at any instant they hold the circuit's memory of its past, and the energy stored in it. Given their values and the inputs from now on, every other voltage and current in the circuit can be worked out, which is exactly what a state is.
:::
:::

::: practice

::: check
given: p = 2..9 int; q = 10..20 int
answer: -p
tolerance: 0.5%

## For $\ddot y + \given{p}\dot y + \given{q}y = 0$ with $x_1 = y$, $x_2 = \dot y$, what is the bottom-right entry of A?

::: misses
- [p] Move $p\dot y$ to the other side: it's $-p$.
- [-q] That's the bottom-left entry.
- [any] $\dot x_2 = -qx_1 - px_2$.
:::
:::

::: check
given: L = 1m..100m E6 H; C = 1µ..100µ E6 F
answer: 1/(L*C)
tolerance: 1%

## For the RLC state matrix with L = {L} and C = {C}, what is $\det A$, in 1/s²?

::: misses
- [-1/(L*C)] $\det\begin{bmatrix} 0 & 1/C \\ -1/L & -R/L\end{bmatrix} = 0 - (1/C)(-1/L)$, which is positive.
- [any] $\det A = ad - bc$ with the RLC entries.
:::
:::

::: check
given: s1 = 1..4 int; s2 = 5..9 int
answer: -(s1 + s2)
tolerance: 0.5%

## A 2 × 2 state matrix has eigenvalues −{s1} and −{s2}. What is its trace?

::: misses
- [s1 + s2] The eigenvalues are negative.
- [s1*s2] That's the determinant.
- [any] The trace is the sum of the eigenvalues.
:::
:::
:::
