LQR

The Linear Quadratic Regulator (LQR) is an optimal feedback control scheme for linear systems with quadratic state and input costs.

The demo solves the discrete algebraic Riccati equation in the browser and redraws the closed-loop response as the penalties change.

System Response

State 1 State 2 Input
Closed-loop LQR response Line plot of two states and one control input over one second.
Gain
Closed-loop Poles (z-plane)
Peak Input
Settling Time
A
B
Q
R

Penalty Weights

Ready

What to Notice

Increasing a state penalty makes deviations in that state more expensive, so the controller spends more input to drive it down. The input penalty is fixed at $R = 1.0$, so the sliders expose the trade-off between the two state coordinates rather than the state-input trade-off.

The readout shows the 5% settling time: the time after which every system state remains within 5% of its initial deviation from its steady-state value. We initialize all states to 1 and this is a regulation task with all steady-state values zero, so the 5% band is at $\pm 0.05$.

About the System

The discrete-time system has linear dynamics

\[x_{k+1} = A x_k + B u_k\]

where

\[A = I + 0.01 \begin{bmatrix}-2 & 13 \\ 4 & -3\end{bmatrix}, \qquad B = 0.01 \begin{bmatrix}2 \\ 8\end{bmatrix}.\]

For each setting, the browser solves the discrete algebraic Riccati equation

\[P = Q + A^\top P A - A^\top P B(R + B^\top P B)^{-1}B^\top P A\]

calculates the gain matrix

\[K = -(R + B^\top P B)^{-1}B^\top P A.\]

and simulates the system in closed-loop under the feedback policy

\[u_t = K x_t\]