| name | lqr-control |
| description | Linear Quadratic Regulator (LQR) control design — state space formulation, Riccati equation, Q and R weighting matrices, closed-loop pole placement, robustness margins, integral augmentation, LQI (LQR with integral), observer design (LQE/Kalman), output feedback, MATLAB implementation, mechanical system applications. |
| metadata | {"priority":7,"promptSignals":{"phrases":["LQR control","linear quadratic regulator","optimal control LQR","Riccati equation","state feedback LQR","LQR Q R matrix"],"minScore":3}} |
Linear Quadratic Regulator (LQR) — Complete Skill
Problem Formulation
System Description
Continuous-time state space:
ẋ = A x + B u [state equation; A ∈ ℝⁿˣⁿ; B ∈ ℝⁿˣᵐ; x = state; u = control input]
y = C x + D u [output equation; y = measured output]
Control objective: regulate state x to zero (or to reference) while minimizing cost
LQR Cost Function
Infinite-horizon quadratic cost:
J = ∫₀^∞ (xᵀ Q x + uᵀ R u) dt [J = total cost; Q ≥ 0 (positive semi-definite); R > 0 (positive definite)]
Q matrix: penalizes state deviation (large Q_ii → state x_i tightly regulated)
R matrix: penalizes control effort (large R → less aggressive control; saves actuator energy/wear)
Interpretation:
Large Q/R ratio → aggressive control, tight tracking, potentially large control effort
Small Q/R ratio → sluggish control, large steady-state error, minimal control effort
Design freedom: choose Q and R to achieve desired closed-loop performance
Optimal Solution — Algebraic Riccati Equation (ARE)
Continuous-Time ARE
Solution procedure:
-
Solve the Algebraic Riccati Equation (ARE) for P > 0:
Aᵀ P + P A - P B R⁻¹ Bᵀ P + Q = 0 [P ∈ ℝⁿˣⁿ, symmetric positive definite]
-
Optimal gain matrix:
K = R⁻¹ Bᵀ P [K ∈ ℝᵐˣⁿ]
-
Optimal control law:
u*(t) = -K x(t) [state feedback; requires full state measurement or observer]
Closed-loop system:
ẋ = (A - B K) x [stable if (A, B) controllable and Q, R chosen properly]
Eigenvalues of (A - BK): closed-loop poles; placed optimally by LQR
Discrete-Time LQR
Discrete-time ARE:
P = Q + Aᵀ P A - Aᵀ P B (R + Bᵀ P B)⁻¹ Bᵀ P A [solve iteratively or with MATLAB]
K = (R + Bᵀ P B)⁻¹ Bᵀ P A
Control law:
u_k = -K x_k [applied at each time step k]
Q and R Matrix Design
Physical Design Approach (Bryson's Rule)
Bryson's Method (practical starting point):
Q = diag(1/x_max_i²) [Q_ii = 1/(max acceptable deviation of state i)²]
R = diag(1/u_max_j²) [R_jj = 1/(max acceptable control effort j)²]
Example — active suspension:
States: x = [z_s, ż_s, z_u, ż_u]ᵀ (sprung/unsprung mass displacement and velocity)
Q = diag([1/(0.05)², 1/(1)², 1/(0.02)², 1/(2)²]) [max 5 cm body displacement, 1 m/s body velocity, etc.]
R = diag([1/(5000)²]) [max 5 kN actuator force]
Iterative refinement:
Start with Bryson → simulate → observe performance → increase Q_ii to tighten regulation of x_i → decrease R_jj to allow more aggressive control
Performance vs. Robustness Trade-off
Aggressive gains (large Q/R):
Faster response, smaller tracking error
Larger bandwidth → amplifies sensor noise
Reduced robustness margins → susceptible to model uncertainty
Conservative gains (small Q/R):
Slower response, possible steady-state error
Lower bandwidth → better noise rejection
Higher robustness margins
LQR Properties
Guaranteed Stability Margins
Classical LQR gain and phase margins (single input, full state feedback):
Gain margin: [0.5, ∞) — infinite upward gain margin; can increase gain without instability
Phase margin: ≥ 60° — robust to phase lag in loop
Return Difference Inequality:
|(I + K(sI - A)⁻¹ B)| ≥ 1 → singular values of loop gain ≥ 1 → guaranteed return difference
This implies: gain margin [0.5, ∞); phase margin ≥ 60°
Practical caveat: these margins apply to SISO LQR with full state feedback; output feedback (with observer) has reduced guaranteed margins (Doyle's counterexample — observer-based LQR can have zero gain margin)
Controllability Requirement
LQR solvable if: (A, B) is stabilizable (all unstable modes are controllable)
LQR optimal if: (A, B) is controllable AND (A, Q^(1/2)) is observable
Verify: rank([B AB A²B...Aⁿ⁻¹B]) = n (Kalman controllability matrix)
LQR with Integral Action (LQI — Tracking)
Integral Augmentation
Problem: standard LQR regulates to zero; for setpoint tracking with disturbance rejection, add integrator states
Augmented state:
x_aug = [x; x_I] where ẋ_I = r - y = r - C x [x_I = integral of tracking error; r = reference]
Augmented system:
ẋ_aug = A_aug × x_aug + B_aug × u + B_r × r
A_aug = [A 0; -C 0]; B_aug = [B; 0]; B_r = [0; I]
LQI gain:
K_aug = [K_x | K_I] from LQR on augmented system
u = -K_x × x - K_I × x_I [state feedback + integral]
Effect: integral action eliminates steady-state error to step references and constant disturbances
Observer Design (LQG)
Linear Quadratic Estimator (Kalman Filter Observer)
When full state not measurable: combine LQR with Kalman filter (LQE) → LQG (Linear Quadratic Gaussian) control
Observer (Luenberger / Kalman):
x̂̇ = A x̂ + B u + L(y - C x̂) [L = observer gain]
u = -K x̂ [control law uses estimated state]
Kalman filter gain for LQE:
Minimize: E[xᵀ Q_e x] (state estimation error) subject to process noise W and measurement noise V
L = P_e Cᵀ V⁻¹ [P_e from dual Riccati equation: A P_e + P_e Aᵀ - P_e Cᵀ V⁻¹ C P_e + W = 0]
W = process noise covariance; V = measurement noise covariance (analogous to Q, R for controller)
Separation principle:
LQR controller and LQE observer can be designed independently
Combined LQG: closed-loop poles = LQR poles ∪ LQE poles (exact separation in linear case)
LQG robustness: generally LESS robust than pure LQR (as noted by Doyle 1978)
LQG/LTR (Loop Transfer Recovery): design procedure to recover LQR robustness margins in LQG
Mechanical Engineering Applications
Active Suspension (Quarter-Car Model)
States: x = [z_s, ż_s, z_u, ż_u]ᵀ (body and wheel displacements and velocities)
Inputs: u = F_actuator (active force)
Road disturbance: w = ż_road (disturbance input)
Equations of motion:
m_s ẑ̈_s = -k_s(z_s - z_u) - c_s(ż_s - ż_u) + F_act
m_u ẑ̈_u = k_s(z_s - z_u) + c_s(ż_s - ż_u) - k_t(z_u - z_road) - F_act
LQR objectives:
Minimize body acceleration (ride comfort): high Q for ż_s
Maintain tire contact: high Q for (z_u - z_road)
Limit actuator stroke: high Q for (z_s - z_u)
Limit force: high R
Typical LQR performance vs. passive:
LQR: 30–50% reduction in RMS body acceleration at 5 Hz road input
Magnetic Bearing Control
Unstable plant (single DOF magnetic bearing):
A = [0 1; k_x/m 0] [k_x = position stiffness (positive = destabilizing); m = rotor mass]
System has unstable eigenvalue at √(k_x/m)
LQR requirement: (A, B) controllable (B = [0; 1/m]) → rank condition satisfied
LQR stabilizes the open-loop unstable mode naturally
Gains: large Q₁₁ (penalize position error) → stiff levitation; large Q₂₂ → damp velocity; R → limit current
Flexible Structure Control (Vibration Suppression)
Modal model:
ẍ_i + 2ζ_i ω_i ẋ_i + ω_i² x_i = φ_i^T B u [decoupled modal equations; i = 1 to N modes]
State: [x_i, ẋ_i] for each mode; truncated to first M modes (residual modes = spillover)
LQR for vibration suppression:
Penalize modal displacements and velocities: Q = block-diag of Q_mode_i
Result: active damping added to all controllable modes
Spillover warning: control of truncated model may excite unmodeled high-frequency modes → instability
Prevention: penalize control bandwidth (high R) + notch filters for unmodeled modes
MATLAB Implementation
% System matrices
A = [0 1; -omega_n^2 -2*zeta*omega_n]; % 2nd order oscillator
B = [0; 1/m];
C = [1 0]; % position output
% LQR weighting
Q = diag([1/(x_max)^2, 1/(v_max)^2]); % Bryson's rule
R = 1/(u_max)^2;
% Solve Riccati equation and find gain
[K, P, e] = lqr(A, B, Q, R);
% e = closed-loop eigenvalues (poles of A - B*K)
% Verify stability
eig(A - B*K) % all must have negative real part
% Observer design (Kalman)
W = 1e-4 * eye(2); % process noise covariance
V = 1e-2; % measurement noise variance
[L, ~, ~] = lqe(A, eye(2), C, W, V); % L = observer gain
% Simulate LQG (LQR + Kalman filter)
sys_cl = ss(A - B*K - L*C, L, C, 0); % closed-loop TF with observer
% Closed-loop response
t = 0:0.001:5; % time vector
[y, t, x] = lsim(sys_cl, u_input, t, x0);
Output
Provide: system type (suspension/bearing/robot/vibration), state vector x (physical meaning; n states), input vector u (m inputs; actuator type), A and B matrices (from physics equations), controllability check (rank = n), Q matrix (Bryson's rule; diagonal entries with justification [units²]), R matrix (diagonal entries [units²]), P solution from ARE [Riccati], optimal gain K = R⁻¹Bᵀ P [gain vector/matrix], closed-loop poles (eigenvalues of A-BK; check negative real parts → stable), LQI augmentation (integral state for tracking; yes/no), observer gain L (Kalman; process noise W, measurement noise V), LQG combined performance (guaranteed gain margin > 0.5, phase margin > 60° for state feedback), MATLAB code snippet, and applicable reference (CCPS LQR, Bryson-Ho "Applied Optimal Control", MATLAB Control Toolbox documentation).