---
title: State space
heading: Describing a system by its state vector and first-order equations ẋ = Ax + Bu, a mass on a spring as the example, the eigenvalues of A as the poles, the trace and determinant of a 2 × 2 system, and state feedback u = −Kx that places the closed-loop poles wherever you choose
eyebrow: D3 · Lesson 9 · State space
xp: 40
---

::: hook
Transfer functions describe one input and one output. A rocket has several engines and dozens of sensors, and a battery's state of charge isn't directly measurable at all. **State space** describes a system by a list of numbers, its **state**, that captures everything about its past that matters for its future (a mass's position and velocity, a circuit's capacitor voltages and inductor currents) and a set of first-order differential equations for how they change. Feeding back the whole state lets a controller put the closed-loop poles anywhere, and it's the language of modern control, from the Apollo guidance computer to a drone's flight controller.
:::

::: play
- A unit mass driven by a force (a double integrator, like the drone of lesson 3 or a cart on a track) with **state feedback** $u = -k_1x_1 - k_2x_2$ on its position $x_1$ and velocity $x_2$.
- The arrows show where the state moves from each point; the traced paths start from three different initial states.
- $k_1$ acts like a spring and $k_2$ like a damper: the closed-loop poles are the roots of $s^2 + k_2s + k_1$, so any pair of poles is reachable by choosing the two gains.
:::

```sim plot
view: flow
x: x1 = -3..3
y: x2 = -3..3
slider: k = 0.5..20 step 0.5 = 4
slider: c = 0..8 step 0.1 = 1
dx: x2
dy: -k*x1 - c*x2
start: 2.5, 0
start: -1, 2.5
start: 0, -2.5
heads: on
readout: natural frequency, rad/s = sqrt(k) | digits: 3
readout: damping ratio = c/(2*sqrt(k)) | digits: 3
```

::: predict
## A mass of 2 kg on a spring of 8 N/m with damping 2 N·s/m has state $(x, v)$. What are the eigenvalues of its A matrix?

- [ ] 2 and 8
- [x] −0.5 ± j1.94
- [ ] −1 ± j2
- [ ] 0 and −1

::: reveal
$m\ddot x = -kx - b\dot x$ gives $\dot x = v$, $\dot v = -4x - v$, so $A = \begin{bmatrix} 0 & 1 \\ -4 & -1 \end{bmatrix}$. Its characteristic polynomial is $s^2 + s + 4$, with roots $-0.5 \pm j\sqrt{3.75} = -0.5 \pm j1.94$: the same as the transfer function's poles.
:::
:::

::: nameit
## The state equations

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

An nth-order system has n states. For a mass m on a spring k with damping b and applied force u, with $\mathbf x = (x, v)$:

$$A = \begin{bmatrix} 0 & 1 \\ -k/m & -b/m \end{bmatrix}, \qquad B = \begin{bmatrix} 0 \\ 1/m \end{bmatrix}$$

## Poles are eigenvalues

The system's 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$, so the poles sum to the trace and multiply to the determinant. Stable 2 × 2 systems have a negative trace and a positive determinant.

## State feedback

Feeding back every state, $\mathbf u = -K\mathbf x$, gives $\dot{\mathbf x} = (A - BK)\mathbf x$: the gains change the matrix and so the poles. If the system is **controllable** (the input can influence every state, tested by the rank of $[B\ AB\ \cdots]$), any set of pole locations can be reached. For the double integrator, matching $s^2 + k_2s + k_1$ to $s^2 + 2\zeta\omega_ns + \omega_n^2$ gives

$$k_1 = \omega_n^2, \qquad k_2 = 2\zeta\omega_n$$

States that can't be measured are estimated by an **observer**, a model of the system run alongside it and corrected by the measured outputs (S9).
:::

::: example
## Choose state-feedback gains for a unit mass so that its closed loop has $\omega_n$ = 4 rad/s and ζ = 0.7.

::: solution
1. **Position gain.**
   $$k_1 = 16\ \text{N/m}$$
2. **Velocity gain.**
   $$\begin{aligned} k_2 &= 2 \times 0.7 \times 4 \\ &= 5.6\ \text{N·s/m} \end{aligned}$$
3. **Closed-loop poles.**
   $$s = -2.8 \pm j2.86$$

**Answer:** $k_1$ = 16 N/m and $k_2$ = 5.6 N·s/m.
:::
:::

::: example
## A 2 × 2 system has trace −6 and determinant 25. Where are its poles?

::: solution
1. **Characteristic equation.**
   $$s^2 + 6s + 25 = 0$$
2. **Poles.**
   $$s = -3 \pm j4$$
3. **What they mean.** The system is stable, oscillating at 4 rad/s with a decay time constant of 1/3 s.

**Answer:** the poles are at $-3 \pm j4$.
:::
:::

::: example
## The unit mass's controller has $\omega_n$ = 4 rad/s. An observer that measures position should be about four times faster. What observer gains give $\omega_n$ = 16 rad/s and ζ = 0.7?

::: solution
1. **Same form as the controller.** The observer's error obeys the same form as the controlled mass.
2. **First gain.**
   $$\begin{aligned} l_1 &= 2\zeta\omega_n \\ &= 22.4\ \text{s}^{-1} \end{aligned}$$
3. **Second gain.**
   $$\begin{aligned} l_2 &= \omega_n^2 \\ &= 256\ \text{s}^{-2} \end{aligned}$$
4. **Settling.** Its estimate settles in about
   $$4/(0.7 \times 16) = 0.36\ \text{s}$$
   well before the controller's own response.

**Answer:** $l_1$ = 22.4 s⁻¹ and $l_2$ = 256 s⁻².
:::
:::

::: check
given: m = 0.5 | 2 | 5; k = 4 | 20 | 50
answer: -k/m
unit: s⁻²
tolerance: 0.5%

## A {m} kg mass on a {k} N/m spring has state (position, velocity). What's the lower-left entry of its A matrix?

::: right
Right. $-k/m$ = {answer} s⁻².
:::

::: misses
- [k/m] The spring pulls back: negative.
- [-k] Divide by the mass.
- [any] Not yet. $\dot v = -(k/m)x - \dots$
:::
:::

::: check
given: t = 2 | 4 | 6; d = 13 | 20 | 40
answer: -t/2
tolerance: 0.5%

## A 2 × 2 system has trace −{t} and determinant {d}, so its poles are complex. What's their real part?

::: right
Right. The poles sum to the trace: −{t}/2 = {answer}.
:::

::: misses
- [-t] Two poles share the trace: halve it.
- [any] Not yet. The characteristic polynomial is $s^2 - (\text{tr})s + \det$.
:::
:::

::: check
given: w = 2 | 5 | 10
answer: w^2
unit: N/m
tolerance: 0.5%

## For a 1 kg double integrator, what position gain $k_1$ gives a closed-loop natural frequency of {w} rad/s?

::: right
Right. $k_1 = \omega_n^2$ = {answer} N/m.
:::

::: misses
- [w] Square it.
- [any] Not yet. Match $s^2 + k_2s + k_1$.
:::
:::

::: check
given: w = 2 | 5 | 10; z = 0.5 | 0.7 | 1
answer: 2*z*w
unit: N·s/m
tolerance: 0.5%

## For the same 1 kg double integrator, what velocity gain $k_2$ gives $\omega_n$ = {w} rad/s and ζ = {z}?

::: right
Right. $k_2 = 2\zeta\omega_n$ = {answer} N·s/m.
:::

::: misses
- [z*w] The damping term is $2\zeta\omega_n$.
- [any] Not yet. Match the s coefficient.
:::
:::

::: check
kind: parts
given: w = 2 | 4 | 10; z = 0.5 | 0.7 | 1

## A unit mass under state feedback $u = -k_1x - k_2\dot x$ should have $\omega_n$ = {w} rad/s and ζ = {z}.

::: part
answer: w^2
unit: N/m
tolerance: 0.5%

### What is $k_1$?

::: misses
- [any] $\omega_n^2$.
:::
:::

::: part
answer: 2*z*w
unit: N·s/m
tolerance: 0.5%

### What is $k_2$?

::: misses
- [any] $2\zeta\omega_n$.
:::
:::
:::

::: check
kind: parts
given: t = -4 | -6 | -10; d = 29 | 34 | 50

## A 2 × 2 system matrix has trace {t} and determinant {d}.

::: part
answer: t/2
tolerance: 0.5%

### What is the real part of its poles?

::: misses
- [any] Half the trace.
:::
:::

::: part
answer: sqrt(d - t^2/4)
unit: rad/s
tolerance: 0.5%

### What is their imaginary part?

::: misses
- [any] $\sqrt{\det - (\text{tr}/2)^2}$.
:::
:::
:::

::: explain
## Why can full state feedback place a controllable system's poles anywhere?

::: model
A system's poles are the eigenvalues of its A matrix, and feeding back each state through its own gain adds a term to every row the input reaches, changing the matrix to A minus BK. Each gain adds an independent adjustable number to the coefficients of the characteristic polynomial, so with as many gains as states there are enough free parameters to match any desired polynomial, and hence any set of poles. Controllability is the condition that the input actually reaches every state, directly or through the dynamics; if some state can't be influenced, its pole stays where it is whatever the gains. In practice the limit is actuator effort: fast poles need large gains and large forces.
:::
:::

::: practice

::: check
given: m = 0.1 | 100; k = 1 | 1000
answer: -k/m
unit: s⁻²
tolerance: 0.5%

## A₂₁ for m = {m} kg, k = {k} N/m?

::: misses
- [any] $-k/m$.
:::
:::

::: check
given: w = 0.5 | 50; z = 0.3 | 1.5
answer: 2*z*w
unit: N·s/m
tolerance: 0.5%

## $k_2$ for $\omega_n$ = {w}, ζ = {z} (unit mass)?

::: misses
- [any] $2\zeta\omega_n$.
:::
:::

::: check
given: t = 0.5 | 20; e = 1.1 | 5; let d = e*t^2/4
answer: -t/2
tolerance: 0.5%

## Real part of the poles: trace −{t}, determinant {d}?

::: misses
- [any] Half the trace.
:::
:::
:::
