S9 · Lesson 47 · State-space lab
The matrix exponential by scaling and squaring, controllability and observability tests, the discrete Riccati equation by iteration, and the steady-state Kalman filter
State-space design rests on a few computations that are easy to state and worth writing once yourself: the matrix exponential that solves and discretizes plants, the rank tests that say whether a design is possible at all, and the Riccati equations behind the LQR and the Kalman filter. Libraries do these with care for large and badly conditioned problems; for the small systems of this course, simple and transparent methods work, and you can check every one against a closed form.
- The curves are the entries of the first column of for : and , the motion from x(0) = (1, 0).
- At t = 0.5 s they're 0.845 and −0.477; your expm must reproduce them to ten digits.
- Scaling and squaring computes by a short series and squares it m times.
Predict
A scalar random walk with step variance 0.0025 is measured with noise variance 0.25. Iterating the Kalman filter's Riccati recursion, what gain does it settle to?
In steady state the prior variance satisfies , whose positive root is , giving : each measurement moves the estimate about a tenth of the way. Iteration from any positive start converges to the same value, which is what your kalman_steady must find.
Name it
What the lab computes
- Matrix exponential: pick m so that , sum the Taylor series of to 20 terms, then square the result m times.
- Controllability and observability of a 2 × 2 system: the determinants of and must be nonzero.
- Discrete LQR: iterate until it stops changing; then . For one state the fixed point solves .
- Steady-state Kalman filter for a random walk: iterate , with gain .
Check
Write expm(A, t): for a 2 × 2 list A by scaling and squaring.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write controllable(A, B) and observable(A, C) for 2 × 2 systems (B a column as a list of 2, C a row as a list of 2), returning booleans, with a tolerance of 1e-12 on the determinant.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write dlqr_scalar(a, b, q, r): iterate the scalar discrete Riccati equation from P = q until it changes by less than 1e-14, and return (P, K).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write kalman_steady(Q, R): iterate the random-walk Kalman recursion from to convergence and return (prior variance, gain).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does iterating the Riccati recursion converge to the steady-state Kalman gain from almost any starting variance?
Each step of the recursion first adds the process noise, which pushes the variance up, and then folds in a measurement, which pulls it down by an amount that grows with the variance itself. When the variance is too large, the measurement removes more than the process noise adds, and when it's too small, the reverse, so the variance is driven toward the one value where the two balance. That balance point is the steady-state solution, and because the update is a contraction near it, iterations from any positive start approach it geometrically, which is why a filter started with a rough initial variance soon behaves as if it had been running forever.