S947 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 x˙=Ax 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 eAt for A=(01−2−3): 2e−t−e−2t and −2e−t+2e−2t, 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 eA/2m 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?

Name it

What the lab computes

  • Matrix exponential: pick m so that ‖At‖/2m<0.5, sum the Taylor series of eAt/2m to 20 terms, then square the result m times.
  • Controllability and observability of a 2 × 2 system: the determinants of (BAB) and (CCA) must be nonzero.
  • Discrete LQR: iterate P←Q+ATPA−ATPB(R+BTPB)−1BTPA until it stops changing; then K=(R+BTPB)−1BTPA. For one state the fixed point solves b2P2+(r(1−a2)−qb2)P−qr=0.
  • Steady-state Kalman filter for a random walk: iterate P−←P−R/(P−+R)+Q, with gain K=P−/(P−+R).

Check

Write expm(A, t): eAt 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 P−=R 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?