Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

The Linear–Quadratic Regulator

The Riccati equation, certainty equivalence and LQR as a testbed for RL.

LQR is the one continuous-state control problem with an exact, closed-form solution, which made it both the workhorse of control engineering and the simplest serious testbed for reinforcement learning theory. This lesson proves the dynamic-programming solution with noise, states when the infinite-horizon Riccati equation yields a stabilizing controller and shows what goes wrong when it does not (discounting included), separates optimality from robustness, and asks how many samples it takes to learn LQR: by identifying the model, or by policy gradient on a non-convex but benign landscape.

What you’ll learn

  • Prove by dynamic programming that finite-horizon LQR with additive noise has a quadratic cost-to-go, linear optimal feedback and the Riccati recursion, with gains that do not depend on the noise.
  • State the conditions (stabilizability and detectability) under which the algebraic Riccati equation has a unique stabilizing solution, and construct examples in which a missing condition or discounting breaks stability.
  • Explain certainty equivalence and the LQG separation principle, and why optimality does not imply robustness.
  • Derive the LQR policy gradient and the gradient-domination inequality, and compare the guarantees for learning LQR with and without a model.

Finite horizon: the proof by dynamic programming

DerivationProof by backward induction
  1. E[Vt+1(Ax+Bu+wt)]=(Ax+Bu)⊤Pt+1(Ax+Bu)+Tr⁡(Pt+1W)+δt+1\E\big[V_{t+1}(A\mathbf x+B\mathbf u+\mathbf w_t)\big]=(A\mathbf x+B\mathbf u)^\top P_{t+1}(A\mathbf x+B\mathbf u)+\Tr(P_{t+1}W)+\delta_{t+1}

    The claim holds at t=Ht=H. Assume it at t+1t+1, with Pt+1⪰0P_{t+1}\succeq0. Because wt\mathbf w_t has mean zero the cross terms vanish in expectation, and E[w⊤Pw]=Tr⁡(PW)\E[\mathbf w^\top P\mathbf w]=\Tr(PW):

  2. u⊤Mu+2 u⊤B⊤Pt+1Ax=(u+Ktx)⊤M(u+Ktx)−x⊤Kt⊤MKtx\mathbf u^\top M\mathbf u+2\,\mathbf u^\top B^\top P_{t+1}A\mathbf x=(\mathbf u+K_t\mathbf x)^\top M(\mathbf u+K_t\mathbf x)-\mathbf x^\top K_t^\top MK_t\mathbf x

    Let M=R+B⊤Pt+1B≻0M=R+B^\top P_{t+1}B\succ0 and Kt=M−1B⊤Pt+1AK_t=M^{-1}B^\top P_{t+1}A, so that MKt=B⊤Pt+1AMK_t=B^\top P_{t+1}A. Collect the terms in u\mathbf u and complete the square:

  3. Qt(x,u)=(u+Ktx)⊤M(u+Ktx)+x⊤(Q+A⊤Pt+1A−Kt⊤MKt)x+Tr⁡(Pt+1W)+δt+1Q_t(\mathbf x,\mathbf u)=(\mathbf u+K_t\mathbf x)^\top M(\mathbf u+K_t\mathbf x)+\mathbf x^\top\big(Q+A^\top P_{t+1}A-K_t^\top MK_t\big)\mathbf x+\Tr(P_{t+1}W)+\delta_{t+1}

    So the stage cost plus the expected cost-to-go is

  4. Since M≻0M\succ0 the unique minimizer is u=−Ktx\mathbf u=-K_t\mathbf x, and Kt⊤MKt=A⊤Pt+1BM−1B⊤Pt+1AK_t^\top MK_t=A^\top P_{t+1}BM^{-1}B^\top P_{t+1}A gives the Riccati recursion; WW enters only the constant. Finally Pt⪰0P_t\succeq0, because x⊤Ptx\mathbf x^\top P_t\mathbf x is the minimum over u\mathbf u of a sum of nonnegative terms. ■\blacksquare

Three remarks. The linear policy is not an assumption but the optimum among all policies, however complex. The Riccati recursion is value iteration on the set of quadratic functions, which it maps to itself, at a cost of O(n3+m3)\order{n^3+m^3} per step. And the noise changes not what to do but only what it costs: this is certainty equivalence, exact for linear dynamics, quadratic costs and additive noise, and false in general.

Predict before you look

Take xt+1=xt+ut+wtx_{t+1}=x_t+u_t+w_t with Var⁡(wt)=1\Var(w_t)=1, cost x2+u2x^2+u^2 per step, horizon H=2H=2 and Qf=0Q_f=0. What is the optimal expected total cost from x0=2x_0=2?

Show the answer

7

Backward: p2=0p_2=0, p1=1p_1=1, p0=1.5p_0=1.5, and δ0=Tr⁡(p1W)+Tr⁡(p2W)=1\delta_0=\Tr(p_1W)+\Tr(p_2W)=1. So V0(2)=1.5⋅4+1=7V_0(2)=1.5\cdot4+1=7. The gains k1=0k_1=0 and k0=12k_0=\tfrac12 are those of the noiseless problem; the noise adds exactly 1.

Infinite horizon: when the Riccati equation stabilizes

DerivationWhy, in outline
  1. 0=P0⪯P1⪯P2⪯⋯⪯PK′0=P_0\preceq P_1\preceq P_2\preceq\cdots\preceq P_{K'}

    Start the recursion at P0=0P_0=0. Then x⊤Pkx\mathbf x^\top P_k\mathbf x is the optimal cost of the kk-step problem, which can only grow with kk, so PkP_k is nondecreasing in the positive semidefinite order. Stabilizability gives an upper bound: a stabilizing gain K′K' has a finite infinite-horizon cost x⊤PK′x\mathbf x^\top P_{K'}\mathbf x, and no kk-step optimum exceeds it.

  2. A bounded monotone sequence of symmetric matrices converges, and the limit PP solves the algebraic equation because the recursion's right-hand side is continuous.

  3. Detectability makes the limit's gain stabilizing. Along the closed loop the cost ∑txt⊤(Q+K⊤RK)xt\sum_t\mathbf x_t^\top(Q+K^\top RK)\mathbf x_t is finite, so Cxt→0C\mathbf x_t\to0 and Kxt→0K\mathbf x_t\to0; the state then evolves essentially by AA alone, and an unstable mode could persist only unseen by the cost, which detectability rules out. Uniqueness, and convergence from every P0⪰0P_0\succeq0, follow from a comparison argument given in the texts cited.

Reinforcement learning usually discounts. Substituting x~t=γt/2xt\tilde{\mathbf x}_t=\gamma^{t/2}\mathbf x_t and u~t=γt/2ut\tilde{\mathbf u}_t=\gamma^{t/2}\mathbf u_t turns the discounted cost ∑tγt(xt⊤Qxt+ut⊤Rut)\sum_t\gamma^t(\mathbf x_t^\top Q\mathbf x_t+\mathbf u_t^\top R\mathbf u_t) into an undiscounted one for the system (γA,γB)(\sqrt\gamma A,\sqrt\gamma B), with the same gain. The theorem then guarantees only that γ (A−BK)\sqrt\gamma\,(A-BK) is stable, that is ρ(A−BK)<1/γ\rho(A-BK)<1/\sqrt\gamma: the discounted optimum may let the real system diverge, as long as it diverges more slowly than the discount shrinks the cost.

Predict before you look

Take a=2a=2, b=1b=1, q=r=1q=r=1 and γ=0.2\gamma=0.2. The scaled system has a~=20.2\tilde a=2\sqrt{0.2} and b~=0.2\tilde b=\sqrt{0.2}, its Riccati solution is p=5p=\sqrt5, and the discounted-optimal gain is k=a~b~ p/(1+b~2p)≈0.618k=\tilde a\tilde b\,p/(1+\tilde b^2p)\approx0.618. What is the true closed-loop multiplier a−bka-bk?

Show the answer

1.382

2−0.618=1.382>12-0.618=1.382>1: the state grows by 38% per step, yet the discounted cost is finite because γ⋅1.3822≈0.38<1\gamma\cdot1.382^2\approx0.38<1. The controller is optimal for its objective and unstable in reality, which is why a discount factor chosen too small can make an RL-trained controller unsafe.

Certainty equivalence, LQG and robustness

With noisy measurements yt=Cxt+vt\mathbf y_t=C\mathbf x_t+\mathbf v_t and Gaussian noise, the optimal controller of the linear–quadratic–Gaussian (LQG) problem splits into two parts designed independently: a Kalman filter computes the state estimate x^t=E[xt∣y≤t,u<t]\hat{\mathbf x}_t=\E[\mathbf x_t\mid\mathbf y_{\le t},\mathbf u_{<t}], and the LQR gain acts on it, ut=−Kx^t\mathbf u_t=-K\hat{\mathbf x}_t. This separation principle is certainty equivalence again: act as if the estimate were the truth. It is the cleanest instance of the recipe model-based RL uses everywhere, and it is exact only in the linear–quadratic–Gaussian world.

The cart of Optimal Control & Model Predictive Control behaves as these margins suggest. When the design model believes the cart weighs 1.9 kg instead of 1 kg, the real loop gain is 1.9 times the designed one, an increase of the kind LQR tolerates, and the cost rose only from 73.4 to 75.3, although the controller's own prediction of its cost, x0⊤P^x0\mathbf x_0^\top\hat P\mathbf x_0 computed on the wrong model, was 91.7, about 22% too high. The guarantee is for continuous time, so the widget's 0.1 s steps make it suggestive, not a proof. Optimality is always relative to a model; robustness is a separate design goal.

Learning LQR: with a model, or by policy gradient

Recht (2019) argued that LQR with unknown AA and BB is the right first testbed for reinforcement learning methods: simple enough to analyze, rich enough to tell them apart. Two routes have sharp guarantees.

Identify, then control. Excite the system with random inputs, estimate (A^,B^)(\hat A,\hat B) by least squares, and design a controller for the estimate. Dean, Mania, Matni, Recht & Tu (2020) bounded the estimation error from NN independent rollouts and synthesized a robust controller that stabilizes every system within the error bounds; its cost exceeds the optimum by a relative amount of order (n+m)log⁡(1/δ)/N\sqrt{(n+m)\log(1/\delta)/N}, times a system-dependent constant, with probability 1−δ1-\delta once NN is large enough. Mania, Tu & Recht (2019) showed that the plain certainty-equivalent controller, the LQR gain of the estimate, does better once the parameter error ε\varepsilon is small: its suboptimality is of order ε2\varepsilon^2 rather than ε\varepsilon, although it needs a smaller ε\varepsilon before it is guaranteed to stabilize the true system. Online, certainty equivalence with simple random exploration achieves regret of order T\sqrt T up to logarithmic factors, as an optimistic method had earlier (Abbasi-Yadkori & Szepesvári, 2011).

Policy gradient. Parameterize the controller as u=−Kx\mathbf u=-K\mathbf x and descend C(K)=Ex0[x0⊤PKx0]C(K)=\E_{\mathbf x_0}[\mathbf x_0^\top P_K\mathbf x_0], where PK=Q+K⊤RK+(A−BK)⊤PK(A−BK)P_K=Q+K^\top RK+(A-BK)^\top P_K(A-BK) is the closed loop's cost matrix. CC is not convex: Fazel, Ge, Kakade & Mesbahi (2018) give a system in which two gains have finite cost while their average does not stabilize. Yet gradient descent finds the global optimum.

DerivationProof of the domination inequality
  1. VK′(x)−VK(x)=∑t≥0AK(xt′,−K′xt′)V_{K'}(\mathbf x)-V_K(\mathbf x)=\sum_{t\ge0}A_K\big(\mathbf x'_t,-K'\mathbf x'_t\big)

    Cost difference, the performance-difference lemma for LQR. Let VK(x)=x⊤PKxV_K(\mathbf x)=\mathbf x^\top P_K\mathbf x and define the advantage AK(x,u)=x⊤Qx+u⊤Ru+VK(Ax+Bu)−VK(x)A_K(\mathbf x,\mathbf u)=\mathbf x^\top Q\mathbf x+\mathbf u^\top R\mathbf u+V_K(A\mathbf x+B\mathbf u)-V_K(\mathbf x). Telescoping along the trajectory xt′\mathbf x'_t of another stabilizing gain K′K':

  2. AK(x,−K′x)=2 x⊤Δ⊤EKx+x⊤Δ⊤MKΔ x ≥ − x⊤EK⊤MK−1EK xA_K(\mathbf x,-K'\mathbf x)=2\,\mathbf x^\top\Delta^\top E_K\mathbf x+\mathbf x^\top\Delta^\top M_K\Delta\,\mathbf x\ \ge\ -\,\mathbf x^\top E_K^\top M_K^{-1}E_K\,\mathbf x

    The advantage is quadratic. Expand with Δ=K′−K\Delta=K'-K and MK=R+B⊤PKBM_K=R+B^\top P_KB, then complete the square in Δx\Delta\mathbf x:

  3. C(K)−C(K⋆)≤Tr⁡(ΣK⋆EK⊤MK−1EK)≤∥ΣK⋆∥σmin⁡(R)Tr⁡(EK⊤EK)C(K)-C(K^\star)\le\Tr\big(\Sigma_{K^\star}E_K^\top M_K^{-1}E_K\big)\le\frac{\norm{\Sigma_{K^\star}}}{\sigma_{\min}(R)}\Tr\big(E_K^\top E_K\big)

    Sum along the optimal trajectory. Take K′=K⋆K'=K^\star, average over x0\mathbf x_0, and use ∑tE[xt⋆xt⋆⊤]=ΣK⋆\sum_t\E[\mathbf x^\star_t\mathbf x^{\star\top}_t]=\Sigma_{K^\star} and MK⪰RM_K\succeq R:

  4. Convert to the gradient. EK=12∇C(K) ΣK−1E_K=\tfrac12\nabla C(K)\,\Sigma_K^{-1} and ΣK⪰Σ0\Sigma_K\succeq\Sigma_0, so Tr⁡(EK⊤EK)≤∥∇C(K)∥F2/(4 σmin⁡(Σ0)2)\Tr(E_K^\top E_K)\le\norm{\nabla C(K)}_F^2/\big(4\,\sigma_{\min}(\Sigma_0)^2\big), which gives the bound with a factor 14\tfrac14 to spare. ■\blacksquare

Gradient domination is the LQR instance of a pattern that also explains policy gradients in tabular MDPs (Global Convergence of Policy Gradients): a non-convex objective whose stationary points are all global optima. The catch is the start: every iterate must remain stabilizing, which needs a stabilizing initial gain and small enough steps, and finding a stabilizing gain without a model is a problem in its own right.

Open problems

Key takeaways

  • Finite-horizon LQR is solved exactly by dynamic programming: the cost-to-go is x⊤Ptx+δt\mathbf x^\top P_t\mathbf x+\delta_t, the optimal policy is u=−Ktx\mathbf u=-K_t\mathbf x, and additive noise changes only δt\delta_t, not the gains.
  • With stabilizability and detectability the algebraic Riccati equation has a unique positive semidefinite solution whose gain stabilizes. When the cost cannot see an unstable mode the "optimal" controller can let the state explode, and discounting weakens the guarantee to ρ(A−BK)<1/γ\rho(A-BK)<1/\sqrt\gamma.
  • Certainty equivalence and the LQG separation principle are exact for linear dynamics, quadratic costs and Gaussian noise; optimality still does not imply robustness, since LQR's margins do not survive the Kalman filter.
  • Identify-then-control learns LQR with relative suboptimality of order (n+m)/N\sqrt{(n+m)/N} (robust synthesis) or of order ε2\varepsilon^2 in the parameter error (certainty equivalence, once the error is small).
  • Policy gradient on LQR is non-convex but gradient-dominated, so from a stabilizing start it converges to the global optimum at a linear rate.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

What does additive process noise change in the finite-horizon LQR solution?

  1. The gains, which shrink to avoid amplifying the noise
  2. Only the constant term of the cost-to-go: the expected cost grows by ∑tTr⁡(Pt+1W)\sum_t\Tr(P_{t+1}W), while the gains stay the same
  3. The form of the policy, which must become stochastic
  4. Nothing at all
Show the answer

B. Only the constant term of the cost-to-go: the expected cost grows by ∑tTr⁡(Pt+1W)\sum_t\Tr(P_{t+1}W), while the gains stay the same

The noise adds Tr⁡(Pt+1W)\Tr(P_{t+1}W) to the expected cost-to-go whatever the control, so it cannot change the minimizer: certainty equivalence. The cost of the optimal policy does rise.

Question 2

For a=2a=2, b=1b=1, q=0q=0, r=1r=1, the Riccati recursion started at p0=0p_0=0 stays at p=0p=0 and gives k=0k=0. Which condition of the theorem fails?

  1. Stabilizability
  2. R≻0R\succ0
  3. Detectability: the cost cannot see the unstable state
  4. None; the theorem says k=0k=0 is stabilizing
Show the answer

C. Detectability: the cost cannot see the unstable state

With q=0q=0 the unstable mode is invisible to the cost, so doing nothing is optimal and the state explodes. The system is stabilizable (for example k=1.5k=1.5) and r=1>0r=1>0.

Question 3

Why can a discounted-optimal LQR controller be unstable?

  1. The discounted problem is undiscounted LQR for (γA,γB)(\sqrt\gamma A,\sqrt\gamma B), so only ρ(A−BK)<1/γ\rho(A-BK)<1/\sqrt\gamma is guaranteed
  2. Discounting makes the Riccati equation unsolvable
  3. Discounting changes the dynamics of the real system
  4. It cannot: discounting only reweights costs
Show the answer

A. The discounted problem is undiscounted LQR for (γA,γB)(\sqrt\gamma A,\sqrt\gamma B), so only ρ(A−BK)<1/γ\rho(A-BK)<1/\sqrt\gamma is guaranteed

Scaling states and controls by γt/2\gamma^{t/2} absorbs the discount into the dynamics, and the stability the theorem provides is for the scaled system. The real closed loop may grow at any rate below 1/γ1/\sqrt\gamma per step.

Question 4

Fazel et al.'s global convergence result for policy gradient on LQR needs which of these?

  1. A convex cost C(K)C(K)
  2. Known matrices AA and BB
  3. A deterministic initial state
  4. A stabilizing initial gain and a full-rank covariance of the initial state
Show the answer

D. A stabilizing initial gain and a full-rank covariance of the initial state

A finite cost at the start keeps the iterates among stabilizing gains, and Σ0≻0\Sigma_0\succ0 makes ΣK\Sigma_K invertible, which turns a small gradient into a small suboptimality. The cost is not convex, and the model-free version estimates gradients from rollouts.

Further reading

  • D. P. Bertsekas, Dynamic Programming and Optimal Control, Vol. I (Athena Scientific, 4th ed., 2017).
  • M. Fazel, R. Ge, S. M. Kakade & M. Mesbahi, "Global convergence of policy gradient methods for the linear quadratic regulator," ICML (2018).
  • S. Dean, H. Mania, N. Matni, B. Recht & S. Tu, "On the sample complexity of the linear quadratic regulator," Foundations of Computational Mathematics (2020).
  • H. Mania, S. Tu & B. Recht, "Certainty equivalence is efficient for linear quadratic control," NeurIPS (2019).
  • B. Recht, "A tour of reinforcement learning: the view from continuous control," Annual Review of Control, Robotics, and Autonomous Systems 2 (2019).