3.5.35Guidance, Navigation & Control (GNC)

Linear Quadratic Regulator (LQR) — Riccati equation, optimal gains

2,067 words9 min readdifficulty · medium1 backlinks

WHAT is the problem?

WHY this cost? It is a steel-man of engineering trade-offs. You cannot make error zero instantly — that would need infinite control. You cannot save all fuel — the system would drift. The integral of a quadratic form is the smoothest way to trade the two, and quadratics make the math solvable in closed form.

WHY quadratic (not x|x| or x4x^4)? Because with a linear plant + quadratic cost, the optimal control turns out to be linear in the state (u=Kxu=-Kx). That is the magic marriage: Linear + Quadratic → Linear controller.


HOW: Derive the optimal control from first principles

We use dynamic programming / the value function (Hamilton–Jacobi–Bellman).

Step 1 — Guess the value function

Define the optimal "cost-to-go" from state xx: V(x)=minu()t(xQx+uRu)dt.V(x) = \min_{u(\cdot)} \int_t^\infty (x^\top Q x + u^\top R u)\,dt.

Why guess V(x)=xPxV(x) = x^\top P x (with P=P0P=P^\top \succeq 0)? Because the cost is quadratic and the dynamics linear, the cost-to-go must also be a quadratic form — there is no linear or constant term (at x=0x=0 cost is 0), and no higher powers survive linear dynamics.

Step 2 — Write the HJB equation

The Bellman principle says: at the optimum, the instantaneous cost plus the rate of change of cost-to-go is zero: 0=minu[xQx+uRu+V(Ax+Bu)].0 = \min_u \left[ x^\top Q x + u^\top R u + \nabla V^\top (Ax+Bu) \right]. With V=xPxV = x^\top P x, we have V=2Px\nabla V = 2Px, so: 0=minu[xQx+uRu+2xP(Ax+Bu)].0 = \min_u \Big[ x^\top Q x + u^\top R u + 2x^\top P (Ax + Bu)\Big].

Step 3 — Minimize over uu (this gives the gain)

Take /u\partial/\partial u and set to 0: u[uRu+2xPBu]=2Ru+2BPx=0.\frac{\partial}{\partial u}\Big[u^\top R u + 2x^\top P B u\Big] = 2Ru + 2B^\top P x = 0.

Why this step? The bracket is convex in uu (since R0R\succ 0), so the stationary point is the global minimum. Solving: u=R1BPx=Kx,K=R1BP\boxed{\,u^* = -R^{-1}B^\top P\, x = -Kx,\qquad K = R^{-1}B^\top P\,}

Step 4 — Substitute uu^* back → the Riccati equation

Put u=R1BPxu^* = -R^{-1}B^\top P x into the HJB bracket. Note uRu=xPBR1BPxu^{*\top}Ru^* = x^\top P B R^{-1} B^\top P x and 2xPBu=2xPBR1BPx2x^\top P B u^* = -2x^\top PBR^{-1}B^\top P x. These combine to xPBR1BPx-x^\top PBR^{-1}B^\top P x: 0=x(Q+AP+PAPBR1BP)x.0 = x^\top\Big(Q + A^\top P + P A - P B R^{-1} B^\top P\Big)x. This must hold for all xx, so the matrix in brackets is zero:

Why is it "algebraic"? In the infinite-horizon steady state P˙=0\dot P = 0, so the differential Riccati equation collapses to this algebraic one. Why nonlinear? The term PBR1BP-PBR^{-1}B^\top P is quadratic in PP.


Worked Example 1 — Scalar system (do it fully by hand)

Plant: x˙=ax+bu\dot x = a x + b u with a,ba,b scalars; cost weights q>0, r>0q>0,\ r>0.

Riccati (scalars): 2apb2rp2+q=0.2ap - \dfrac{b^2}{r}p^2 + q = 0.

Why? AP+PA=2apA^\top P + PA = 2ap; PBR1BP=b2rp2PBR^{-1}B^\top P = \frac{b^2}{r}p^2; add Q=qQ=q.

Solve the quadratic for pp (take the positive root, since P0P\succeq0): p=ar+a2r2+qrb2b2.p = \frac{ar + \sqrt{a^2 r^2 + q r b^2}}{b^2}. Why positive root? V=px2V=px^2 is a cost — must be non-negative; only the ++ root gives p>0p>0.

Gain: K=brpK = \dfrac{b}{r}\,p. Closed loop: x˙=(abK)x\dot x = (a - bK)x.

Check stability: abK=ab2rp<0a - bK = a - \frac{b^2}{r}p < 0 always, so the controller always stabilizes even an unstable open-loop plant (a>0a>0).

Numbers: a=1a=1 (unstable!), b=1b=1, q=1q=1, r=1r=1: p=1+1+1=1+22.414,K=p2.414,abK1.414<0.p = 1 + \sqrt{1+1} = 1+\sqrt2 \approx 2.414,\quad K = p \approx 2.414,\quad a-bK \approx -1.414 <0. Stable. ✔


Worked Example 2 — Double integrator (a real GNC case)

A satellite axis: position x1x_1, velocity x2x_2, control acceleration uu: A=[0100], B=[01], Q=[1000], R=[ρ].A=\begin{bmatrix}0&1\\0&0\end{bmatrix},\ B=\begin{bmatrix}0\\1\end{bmatrix},\ Q=\begin{bmatrix}1&0\\0&0\end{bmatrix},\ R=[\rho].

Let P=[p1p2p2p3]P=\begin{bmatrix}p_1&p_2\\p_2&p_3\end{bmatrix}. Expand CARE. Key equations:

  • (1,1): 1p22/ρ=0p2=ρ.(1,1):\ 1 - p_2^2/\rho = 0 \Rightarrow p_2 = \sqrt{\rho}.
  • (1,2): p1p2p3/ρ=0p1=p2p3/ρ.(1,2):\ p_1 - p_2 p_3/\rho = 0 \Rightarrow p_1 = p_2 p_3/\rho.
  • (2,2): 2p2p32/ρ=0p3=2ρp2=2ρ3/4.(2,2):\ 2p_2 - p_3^2/\rho = 0 \Rightarrow p_3 = \sqrt{2\rho\,p_2} = \sqrt{2}\,\rho^{3/4}.

Gain: K=R1BP=1ρ[p2, p3]=[1ρ, 2ρ1/4].K = R^{-1}B^\top P = \frac{1}{\rho}[\,p_2,\ p_3\,] = \big[\,\tfrac{1}{\sqrt\rho},\ \tfrac{\sqrt2}{\rho^{1/4}}\big].

Why this matters: K=[kp, kd]K=[k_p,\ k_d] is exactly a PD controller! The first gain acts on position (spring), the second on velocity (damper). LQR derived PD control optimally. With ρ=1\rho=1: K=[1, 2]K=[1,\ \sqrt2], giving closed-loop poles at 12±j12-\tfrac{1}{\sqrt2}\pm j\tfrac{1}{\sqrt2} — a nicely damped response (damping ratio =1/2=1/\sqrt2).



Recall Feynman: explain to a 12-year-old

Imagine steering a wobbly shopping cart to a spot. Being far from the spot is annoying (that's QQ), but shoving the cart really hard is tiring and jerky (that's RR). LQR figures out the perfect amount of push for every situation so you get there smoothly without wearing yourself out. And the amazing part: the perfect rule is simply "push in proportion to how far off you are" — one recipe (u=Kxu=-Kx) that works everywhere. The Riccati equation is just the puzzle you solve once to find that recipe.


Active Recall

What cost does LQR minimize?
J=0(xQx+uRu)dtJ=\int_0^\infty (x^\top Q x + u^\top R u)\,dt — weighted state error + control effort.
What is the optimal LQR control law?
u=Kxu^*=-Kx with K=R1BPK=R^{-1}B^\top P.
State the continuous-time Algebraic Riccati Equation.
AP+PAPBR1BP+Q=0A^\top P + PA - PBR^{-1}B^\top P + Q = 0.
Why is the optimal controller linear in x?
Linear plant + quadratic cost ⇒ quadratic value function V=xPxV=x^\top Px ⇒ minimizing gives linear u=Kxu=-Kx.
Which Riccati root do you pick?
The unique symmetric positive-semidefinite (stabilizing) PP making ABKA-BK Hurwitz.
Effect of increasing R?
Penalizes control more ⇒ less effort ⇒ slower, gentler response.
Effect of increasing Q?
Penalizes error more ⇒ more aggressive, faster response.
Why must R be positive definite (not just PSD)?
So R1R^{-1} exists in K=R1BPK=R^{-1}B^\top P (and cost is strictly convex in uu).
Conditions guaranteeing a stabilizing LQR solution?
(A,B)(A,B) controllable and (A,Q)(A,\sqrt{Q}) observable.
For the double integrator, what classical controller does LQR reproduce?
A PD controller: K=[kp, kd]K=[k_p,\ k_d] on position and velocity.
What is the optimal value (cost-to-go) function form?
V(x)=xPxV(x)=x^\top P x.
Where does the Riccati equation come from?
Substituting the optimal uu^* back into the HJB equation and requiring it hold for all xx.

Connections

  • Hamilton-Jacobi-Bellman Equation — LQR is its cleanest closed-form solution.
  • Controllability and Observability — needed for a valid stabilizing PP.
  • Pole Placement — alternative to LQR; LQR optimally places poles.
  • Kalman Filter — dual Riccati equation; combine → LQG Control.
  • PID Controllers — LQR generalizes/derives PD gains optimally.
  • Lyapunov StabilityV=xPxV=x^\top Px is a Lyapunov function for the closed loop.
  • State-Space Representation — the x˙=Ax+Bu\dot x = Ax+Bu foundation.

Concept Map

combined with

penalizes state

penalizes effort

linear plus quadratic

solved via

guess quadratic

minimize over u

substitute u back

yields P

feedback law

drives state to

realized as

Linear plant dx=Ax+Bu

Quadratic cost J

Q weight on error

R weight on control

Optimal control is linear

HJB dynamic programming

Value function V=x'Px

Optimal gain K=R^-1 B' P

Algebraic Riccati equation

u = -Kx

State to zero

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, LQR ka basic idea bahut simple hai. Tumhare paas ek linear system hai — x˙=Ax+Bu\dot x = Ax + Bu — matlab satellite ya rocket jaisa kuch jise tum control input uu se steer karte ho. Ab tumhe do cheezein manage karni hain: ek to state error kam karna (target par pahunchna), aur doosra control effort bacha na (fuel/actuator zyada na jale). In dono ka trade-off ek cost function J=(xQx+uRu)dtJ = \int (x^\top Q x + u^\top R u)\,dt mein likhte hain, jahan QQ error ko punish karta hai aur RR effort ko.

Kamaal ki baat yeh hai: kyunki system linear hai aur cost quadratic, optimal control bhi linear nikalta hai — u=Kxu = -Kx. Bas ek matrix KK nikalna hai. Yeh KK tumhe Riccati equation se milta hai: AP+PAPBR1BP+Q=0A^\top P + PA - PBR^{-1}B^\top P + Q = 0. Ise solve karke positive-definite PP nikalo, phir K=R1BPK = R^{-1}B^\top P. Ho gaya! Ek baar offline solve karo, phir wahi gain hamesha use karo.

Practical intuition: agar tum RR bada karoge to controller "aaram se" chalega (kam effort, slow response); agar QQ bada karoge to controller "aggressive" ho jayega (fast, zyada effort). Sirf QQ aur RR ka ratio matter karta hai. Aur ek zabardast fact — double integrator ke liye LQR automatically ek PD controller bana deta hai, matlab position par spring aur velocity par damper. Isiliye GNC mein LQR itna popular hai: yeh classical PID ko optimally derive kar deta hai, guess-work ke bina.

Yaad rakhna common galti: log sochte hain bada RR matlab fast response — galat! Bada RR matlab effort pe zyada penalty, isliye gentle/slow response. Aur Riccati ka jo term hai PBR1BP-PBR^{-1}B^\top P, uska sign minus hota hai — yeh mat bhoolna.

Go deeper — visual, from zero

Test yourself — Guidance, Navigation & Control (GNC)

Connections