Introduction

Balance a broomstick on your palm, keep a drone hovering, land a rocket booster tail-first: they all share the same nagging tension. Push back too gently and the system drifts away and falls. Push back too hard and you waste energy, overshoot, and fight yourself.

The Linear-Quadratic Regulator, or LQR, is the classical answer to "how hard should I push, right now, given exactly this much error?" It looks at the system's current state — position, velocity, tilt, whatever describes it — and computes the control action that minimizes a cost blending two things you want small: how far you are from the target, and how much effort you're spending to get there.

What makes LQR remarkable is not the idea — plenty of controllers try to balance accuracy against effort. It's that for linear systems and quadratic costs, the optimal controller is not found by trial and error or iterative search. It falls straight out of solving one algebraic equation, named after the Italian mathematician Jacopo Riccati.

Try It

Here is the textbook stress test for a controller: an inverted pendulum balanced on a cart that can only move left and right. Push the cart the wrong way and the pole falls; do nothing and the pole falls too — this system is unstable on its own.

<p class="hint">{{hint_para}}</p>
<canvas id="scene" width="460" height="220"></canvas>
<div class="status" id="status">{{status_ready}}</div>
<div class="controls">
  <label>{{label_angle_weight}} <span id="qVal">10</span>
    <input id="qSlider" type="range" min="1" max="300" value="10" step="1">
  </label>
  <label>{{label_effort_weight}} <span id="rVal">1</span>
    <input id="rSlider" type="range" min="1" max="50" value="1" step="1">
  </label>
</div>
<div class="btns">
  <button id="solve" type="button">{{btn_solve}}</button>
  <button id="nudge" type="button">{{btn_nudge}}</button>
  <button id="reset" type="button" class="ghost">{{btn_reset}}</button>
</div>
* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; color: #222; margin: 0; }
.hint { font-size: .9rem; color: #444; margin: 0 0 .6rem; line-height: 1.45; }
canvas { display: block; background: #eef2f6; border: 1px solid #cdd9e3; border-radius: 8px;
         width: 100%; max-width: 460px; height: auto; }
.controls { display: flex; flex-wrap: wrap; gap: 1.2rem; margin: .6rem 0; }
.controls label { font-size: .85rem; font-weight: 600; color: #1d3557; display: flex;
                   flex-direction: column; gap: .2rem; min-width: 180px; }
.controls input[type="range"] { width: 180px; }
.status { font-size: 1rem; font-weight: 600; margin: .5rem 0; min-height: 1.4em; }
.status.ok { color: #0a7d33; }
.status.bad { color: #c92f3c; }
.btns { display: flex; gap: .5rem; flex-wrap: wrap; }
button { font: 600 14px system-ui, sans-serif; padding: .45rem .9rem; border: 1px solid #1d3557;
         background: #1d3557; color: #fff; border-radius: 8px; cursor: pointer; }
button.ghost { background: #fff; color: #1d3557; }
// Code not found

The sliders control the cost weights: how harshly the controller penalizes angle error and cart effort. Push the angle weight up and the controller reacts fast and stiffly; push the effort weight up and it becomes gentle and economical, tolerating more wobble to save energy. Press Compute LQR gain to re-solve the Riccati equation for your chosen weights and watch the same pendulum balance differently.

The Real Complexity

Strip away the pendulum and the LQR problem is pure algebra. The system evolves as x˙=Ax+Bu\dot{x} = Ax + Bu, where xx is the state (angle, position, their rates) and uu is the control input (the push). The cost to minimize, over all time, is

J=0(xTQx+uTRu)dtJ = \int_0^{\infty} \left( x^T Q x + u^T R u \right) dt

Here QQ and RR are matrices you choose: QQ penalizes state error, RR penalizes control effort. Crank up QQ and the controller chases the target aggressively; crank up RR and it conserves effort.

  • The optimal control law is linear. The best possible uu turns out to always have the form u=Kxu = -Kx — a simple proportional feedback, no matter how far ahead you plan. That alone is a striking result: the infinite-horizon optimization problem collapses into one constant matrix KK, the gain.
  • KK comes from one equation. The gain is K=R1BTPK = R^{-1} B^T P, where PP is the unique symmetric positive-definite solution of the algebraic Riccati equation:

ATP+PAPBR1BTP+Q=0A^T P + P A - P B R^{-1} B^T P + Q = 0

  • No search, no local minima. Unlike most optimization landscapes, this equation has (under mild conditions — the system must be controllable) exactly one solution that stabilizes the system, and standard numerical routines (eigenvalue decomposition of a related Hamiltonian matrix) find it directly, without hill-climbing or guessing.
  • The cost is the trade-off you asked for. QQ and RR are not hyperparameters to search over blindly — they are the specification. Choosing them is the real engineering judgment; solving for KK given them is mechanical.

That is the surprising part: a problem that looks like it should need gradient descent or heavy search resolves into a single deterministic linear-algebra computation, the same way some hard-looking problems turn out to sit inside P once you find the right structure.

Where It Matters

Any system you want to hold near a target while spending as little effort as possible is a candidate for LQR:

  • Aerospace: aircraft autopilots, satellite attitude control and rocket-landing guidance all use LQR or its extensions to keep a vehicle on course through disturbances.
  • Robotics: self-balancing robots, quadcopter stabilization and legged-robot posture control lean on the same linear-feedback structure around a walking or hovering trim point.
  • Noisy systems (LQG): combine LQR with a Kalman filter and you get the Linear-Quadratic-Gaussian controller, optimal state feedback when your sensors are noisy, not just when your dynamics are simple.
  • Beyond linear systems: real vehicles are nonlinear, but linearizing around an operating point and applying LQR locally is the workhorse first step before reaching for heavier tools like Model Predictive Control.

Learn how LQR turns stabilization into linear algebra and you've met the reasoning behind most classical autopilots — and the baseline every modern controller, including reinforcement-learning ones, still gets compared against.

Conclusion

The Linear-Quadratic Regulator is a reminder that not every optimization problem is a search. Give it a linear system and a quadratic cost, and the entire infinite-horizon question of "what's the best thing to do right now" reduces to one algebraic equation with one correct answer.

That is a rare gift. Most of the interesting problems in this space — nonlinear dynamics, hard constraints, discrete choices — don't collapse so cleanly, which is exactly why LQR remains the yardstick: the clean, solvable case every messier controller is still measured against.

Share this article

Pick a channel — or use your device's native share sheet.

Comments

Loading comments...

https://www.kipuhub.com/en/article/lqr-control/Content licensed under CC BY-NC 4.0.