---
title: The linear-quadratic regulator
heading: Choosing state-feedback gains by minimizing a quadratic cost on state error and control effort, the algebraic Riccati equation, the scalar and double-integrator solutions, Bryson's rule for the weights, and the margins an LQR loop is guaranteed
eyebrow: S9 · Lesson 38 · The linear-quadratic regulator
xp: 50
---

::: hook
Pole placement lets you put the poles anywhere, which raises an awkward question: where? Fast poles need large gains and large actuator effort; slow ones leave errors uncorrected. Kálmán's answer in 1960 was to state the trade-off as a cost, the integral of squared state error plus squared control effort, and find the feedback that minimizes it. The result, the linear-quadratic regulator, picks every gain at once from two weights, and as a bonus comes with guaranteed stability margins that hand-placed poles don't have.
:::

::: play
- A one-state plant $\dot{x} = ax + u$ under the LQR that minimizes $\int(qx^2 + ru^2)\,dt$, against the weight ratio ρ = q/r on a log axis.
- The closed-loop pole sits at $-\sqrt{a^2 + \rho}$ and the gain is $a + \sqrt{a^2 + \rho}$. Cheap control (large ρ) gives a fast pole and a big gain.
- Expensive control (ρ → 0) barely acts: a stable plant is left alone, but an unstable pole at +a is mirrored to −a, the least effort that stabilizes it.
:::

```sim plot
view: graph
x: rho = 0.01..1000 log
y: v = -40..40
slider: a = -5..5 = 1
plot: -sqrt(a^2 + rho) | samples: 400 | label: closed-loop pole
plot: a + sqrt(a^2 + rho) | samples: 400 | color: ch3 | label: feedback gain
plot: 0*rho | dashed | color: ch4
readout: pole for ρ of 1 = -sqrt(a^2 + 1) | digits: 3
```

::: predict
## A double integrator gets the LQR with Q = diag(q, 0) and R = 1. What damping ratio do its closed-loop poles have, whatever q is?

- [ ] It depends on q
- [ ] 0.5
- [x] 0.707
- [ ] 1

::: reveal
The Riccati equation gives K = $(\sqrt{q},\ \sqrt{2\sqrt{q}})$, so the closed loop is $s^2 + \sqrt{2}\,q^{1/4}s + \sqrt{q}$: $\omega_n = q^{1/4}$ and ζ = $1/\sqrt{2}$ = 0.707 exactly. The weight sets the speed; the optimization picks the damping on its own.
:::
:::

::: nameit
## The problem

For $\dot{x} = Ax + Bu$, find u minimizing

$$J = \int_0^\infty\left(x^TQx + u^TRu\right)dt, \qquad Q \succeq 0,\ R \succ 0$$

## The solution

If (A, B) is controllable, the optimum is state feedback $u = -Kx$ with

$$K = R^{-1}B^TP, \qquad A^TP + PA - PBR^{-1}B^TP + Q = 0$$

the **algebraic Riccati equation**, with P the positive-definite solution. The minimum cost from $x_0$ is $x_0^TPx_0$.

**One state**, $\dot{x} = ax + bu$, $J = \int(qx^2 + ru^2)$: $2aP - b^2P^2/r + q = 0$, so

$$P = \frac{r}{b^2}\left(a + \sqrt{a^2 + b^2q/r}\right), \qquad K = \frac{bP}{r}, \qquad \text{pole at } -\sqrt{a^2 + b^2q/r}$$

**Double integrator**, Q = diag(q, 0), R = 1: $K = (\sqrt{q},\ \sqrt{2\sqrt{q}})$, $\omega_n = q^{1/4}$, ζ = 0.707.

## Choosing the weights

**Bryson's rule:** make each term about one at its largest acceptable value: $Q_{ii} = 1/x_{i,\max}^2$ and $R_{jj} = 1/u_{j,\max}^2$. Then adjust: raise a state's weight to tighten it, raise R to calm the actuator.

## Guaranteed margins

With full state feedback and one input, the LQR loop gain $K(sI - A)^{-1}B$ always keeps $|1 + L(j\omega)| \ge 1$: its Nyquist plot stays outside the unit circle around −1. That guarantees a gain margin from 1/2 to ∞ and a phase margin of at least 60°. An observer in the loop can destroy these guarantees, a famous result of John Doyle (1978), which is why lesson 39's estimator must be checked.
:::

::: example
## An unstable plant $\dot{x} = x + u$ gets the LQR with q = 3, r = 1. Find P, the gain and the closed-loop pole.

::: solution
1. **Riccati solution.**
   $$\begin{aligned} P &= 1 + \sqrt{1 + 3} \\ &= 3 \end{aligned}$$
   which satisfies $2P - P^2 + 3 = 0$.
2. **Gain and closed loop.** The gain is K = 3, so
   $$\dot{x} = (1 - 3)x$$
   a pole at $-2 = -\sqrt{1 + 3}$.
3. **Cost.** Starting from $x_0$ = 1, the cost is
   $$Px_0^2 = 3$$

**Answer:** P = 3 and K = 3, with the closed-loop pole at −2.
:::
:::

::: example
## A position stage should stay within 0.1 m and its amplifier delivers at most 12 V. Set up Bryson's weights.

::: solution
1. **Bryson's weights.** One over the square of each allowed size:
   $$\begin{aligned} q &= 1/0.1^2 \\ &= 100 \\ r &= 1/12^2 \\ &= 0.00694 \end{aligned}$$
   on position and voltage, a ratio q/r = 14,400.
2. **What that gives.** For a double integrator with unit input gain, that's like q = 14,400 with r = 1, giving
   $$\begin{aligned} \omega_n &= 14{,}400^{1/4} \\ &= 11\ \text{rad/s} \end{aligned}$$
   at ζ = 0.707.
3. **Adjust.** If the step responses then saturate the amplifier, raise r.

**Answer:** q = 100 on position and r = 0.00694 on voltage.
:::
:::

::: example
## An unstable plant $\dot{x} = 2x + u$ gets the LQR with r = 1. Find the gain and pole for q = 0, 5 and 96.

::: solution
1. **Pole.**
   $$\begin{aligned} s &= -\sqrt{a^2 + b^2q/r} \\ &= -\sqrt{4 + q} \end{aligned}$$
2. **Gain.**
   $$\begin{aligned} K &= P \\ &= a + \sqrt{a^2 + q} \end{aligned}$$
   For the three weights:

| q | Pole | K |
|---|---|---|
| 0 | −2 | 4 |
| 5 | −3 | 5 |
| 96 | −10 | 12 |

3. **When the state costs nothing.** Even then the LQR must stabilize, and the cheapest way mirrors the unstable pole into the left half-plane.
4. **Heavier weights.** Heavier state weights then push the pole out roughly as $\sqrt q$.

**Answer:** q = 0 gives a pole at −2 with K = 4, q = 5 gives −3 with K = 5, and q = 96 gives −10 with K = 12.
:::
:::

::: check
given: a = -2 | 1 | 3; b = 2 | 3; q = 1 | 10; r = 0.1 | 1
answer: -sqrt(a^2 + b^2*q/r)
unit: rad/s
tolerance: 0.5%

## $\dot{x} = \given{a}x + \given{b}u$ gets the LQR for $\int(\given{q}x^2 + \given{r}u^2)\,dt$. Where's the closed-loop pole?

::: right
Right. $-\sqrt{a^2 + b^2q/r}$ = {answer}.
:::

::: misses
- [-sqrt(a^2 + q/r)] Include $b^2$: the input's strength matters.
- [any] Not yet. Solve the scalar Riccati equation, then $a - b^2P/r$.
:::
:::

::: check
given: a = -2 | 1 | 3; b = 2 | 3; q = 1 | 10; r = 0.1 | 1
answer: (a + sqrt(a^2 + b^2*q/r))/b
tolerance: 0.5%

## For the same plant and cost, what's the LQR gain K?

::: right
Right. $K = bP/r = (a + \sqrt{a^2 + b^2q/r})/b$ = {answer}.
:::

::: misses
- [a + sqrt(a^2 + b^2*q/r)] Divide by b.
- [any] Not yet. $K = bP/r$.
:::
:::

::: check
given: q = 9 | 81 | 10000
answer: sqrt(2*sqrt(q))
tolerance: 0.5%

## A double integrator gets the LQR with Q = diag({q}, 0), R = 1. What's its velocity gain?

::: right
Right. $K_2 = \sqrt{2\sqrt{q}}$ = {answer}, with $K_1 = \sqrt{q}$.
:::

::: misses
- [sqrt(q)] That's the position gain.
- [any] Not yet. Solve the 2 × 2 Riccati equation.
:::
:::

::: check
given: x = 0.01 | 0.2 | 2; u = 5 | 24
answer: u^2/x^2
tolerance: 0.5%

## By Bryson's rule, a state may reach {x} and the input {u}. What's the weight ratio q/r?

::: right
Right. $q/r = u_\max^2/x_\max^2$ = {answer}.
:::

::: misses
- [u/x] Both weights are inverse squares.
- [any] Not yet. $q = 1/x_\max^2$, $r = 1/u_\max^2$.
:::
:::

::: check
given: a = -1 | 2; b = 1 | 4; q = 2 | 8; r = 0.5 | 2; x = 2 | 3
answer: r/b^2*(a + sqrt(a^2 + b^2*q/r))*x^2
tolerance: 0.5%

## $\dot{x} = \given{a}x + \given{b}u$ with cost weights q = {q}, r = {r}, starting from x = {x}. What's the minimum cost?

::: right
Right. $Px_0^2$ = {answer}.
:::

::: misses
- [r/b^2*(a + sqrt(a^2 + b^2*q/r))] Multiply by $x_0^2$.
- [any] Not yet. $J^* = Px_0^2$.
:::
:::

::: check
given: a = -1 | 2; b = 1 | 3; p = 5 | 20
answer: (p^2 - a^2)/b^2
tolerance: 0.5%

## For $\dot{x} = \given{a}x + \given{b}u$, what weight ratio q/r makes the LQR put the pole at −{p}?

::: right
Right. $p^2 = a^2 + b^2q/r$, so q/r = {answer}.
:::

::: misses
- [any] Not yet. Invert the pole formula.
:::
:::

::: check
kind: parts
given: a = -1 | 1 | 3; b = 1 | 2; q = 1 | 10 | 100; r = 1 | 0.1; x = 1 | 5

## The plant $\dot{x} = \given{a}x + \given{b}u$ gets the LQR for $\int(\given{q}x^2 + \given{r}u^2)\,dt$, starting from x = {x}.

::: part
answer: r/b^2*(a + sqrt(a^2 + b^2*q/r))
tolerance: 0.5%

### What is P?

::: misses
- [any] $P = \frac{r}{b^2}\left(a + \sqrt{a^2 + b^2q/r}\right)$.
:::
:::

::: part
answer: b/r*r/b^2*(a + sqrt(a^2 + b^2*q/r))
tolerance: 0.5%

### What is the gain K?

::: misses
- [any] $K = bP/r$.
:::
:::

::: part
answer: x^2*r/b^2*(a + sqrt(a^2 + b^2*q/r))
tolerance: 0.5%

### What is the minimum cost?

::: misses
- [any] $x_0^2P$.
:::
:::
:::

::: check
kind: derivation
vars: a = -5..5, b = 0.1..10, q = 0.01..100, r = 0.01..100

## The scalar LQR for $\dot{x} = ax + bu$ with weights q and r.

::: step
answer: -sqrt(a^2 + b^2*q/r)

### Where is the closed-loop pole?
:::

::: step
answer: r/b^2*(a + sqrt(a^2 + b^2*q/r))

### What is P?
:::

::: step
answer: (a + sqrt(a^2 + b^2*q/r))/b

### What is K?
:::

::: right
Right. The closed-loop pole $a - bK$ comes out at $-\sqrt{a^2 + b^2q/r}$ whatever the sign of a.
:::
:::

::: explain
## Why does an LQR with expensive control move an unstable pole to its mirror image rather than just barely into the left half-plane?

::: model
When control is expensive, the optimal controller uses as little effort as it can while still keeping the cost finite. An unstable mode left alone would grow forever and make the state cost infinite, so it must be stabilized, but any effort beyond the minimum is wasted. Moving the pole from +a to −a turns out to be that minimum: the state decays at the same rate it would otherwise have grown, and the effort needed is just enough to reverse the growth. Moving it only barely past zero would leave the state decaying so slowly that its accumulated cost would be larger than the effort saved.
:::
:::

::: practice

::: check
given: a = -3 | 0.5 | 4; b = 1 | 3; q = 2 | 20; r = 0.2 | 2
answer: -sqrt(a^2 + b^2*q/r)
unit: rad/s
tolerance: 0.5%

## LQR pole for $a$ = {a}, b = {b}, q = {q}, r = {r}?

::: misses
- [any] $-\sqrt{a^2 + b^2q/r}$.
:::
:::

::: check
given: q = 16 | 625 | 2401
answer: q^0.25
unit: rad/s
tolerance: 0.5%

## Natural frequency of a double integrator's LQR with q = {q}, r = 1?

::: misses
- [any] $q^{1/4}$.
:::
:::

::: check
given: x = 0.05 | 1; u = 3 | 15
answer: u^2/x^2
tolerance: 0.5%

## Bryson's q/r for $x_\max$ = {x}, $u_\max$ = {u}?

::: misses
- [any] $u_\max^2/x_\max^2$.
:::
:::
:::
