Linear Quadratic Regulator for Continuous-Time Systems
The continuous-time Linear Quadratic Regulator (LQR) extends the optimal control theory to systems described by differential equations. This document presents the complete derivation using the Hamilton-Jacobi-Bellman (HJB) equation approach.
Problem Formulation
System Dynamics
Consider a continuous-time linear time-varying system:
Where:
- : state vector at time
- : control input at time
- : state transition matrix
- : input matrix
Quadratic Performance Function
The objective is to minimize the quadratic cost function:
Where:
And is the terminal (final) time.
Weight Matrices
Terminal weight matrix:
- : symmetric positive semi-definite
State weight matrix:
- : symmetric positive semi-definite
Input weight matrix:
- : symmetric positive definite
- : Positive semi-definite ()
- : Positive definite ()
These conditions ensure the optimization problem is well-posed and has a unique solution.
Cost-to-Go Analysis
General Cost-to-Go Function
The cost-to-go from any time to the final time is:
Incremental Cost Analysis
For a small time increment , the cost-to-go can be decomposed as:
Cost for interval :
Cost for interval :
Optimal Cost-to-Go Structure
The optimal cost-to-go for the LQR problem has a quadratic form:
where is the cost-to-go matrix.
State Evolution
The state at time can be approximated as:
Cost-to-Go Matrix Evolution
The cost-to-go matrix also evolves over time:
Optimization Using HJB Equation
Complete Cost Expression
Substituting the state evolution and matrix evolution:
Expanding the Quadratic Form
After algebraic manipulation (ignoring second-order terms in ):
Finding the Optimal Control
To minimize the cost, we take the derivative with respect to and set it to zero:
This gives:
Optimal control law:
Feedback gain:
So the control law is:
Riccati Differential Equation
Derivation
Since the optimal cost must satisfy for all time, substituting the optimal control back into the cost expression and equating coefficients yields:
This is the continuous-time Riccati differential equation.
Boundary Condition
The Riccati equation is solved backward in time with the terminal condition:
Alternative Forms
The Riccati equation can also be written as:
Or in terms of the closed-loop matrix :
Time-Invariant Case
Steady-State Solution
For Linear Time-Invariant (LTI) systems where and are constant, and considering the infinite-horizon case ():
The Riccati matrix converges to a constant:
Setting , we obtain the continuous-time algebraic Riccati equation (CARE):
Optimal Feedback Gain
The steady-state optimal feedback gain is:
Algorithm Summary
Finite-Horizon Solution
Backward Integration:
- Initialize:
- Integrate backward: Solve the Riccati differential equation from to
- Compute gains: for all
Forward Implementation:
- Given: Initial state
- For : Apply control
Infinite-Horizon Solution
Offline Computation:
- Solve CARE: Find satisfying the algebraic Riccati equation
- Compute gain:
Online Implementation:
- Apply constant gain: for all
Implementation
MATLAB Implementation
function [K, P] = lqr_continuous(A, B, Q, R, S, tf)
% Continuous-time LQR solution
% Inputs: A, B (system matrices), Q, R, S (weight matrices), tf (final time)
% Outputs: K (feedback gains), P (cost matrices)
% Time vector (backward integration)
tspan = [tf, 0];
% Initial condition (terminal cost matrix)
P0 = reshape(S, [], 1); % Vectorize matrix
% Solve Riccati differential equation backward
[t, P_vec] = ode45(@(t, P) riccati_ode(t, P, A, B, Q, R), tspan, P0);
% Reshape solution
n = size(A, 1);
P = zeros(n, n, length(t));
K = zeros(size(B, 2), n, length(t));
for i = 1:length(t)
P(:, :, i) = reshape(P_vec(i, :), n, n);
K(:, :, i) = -R \ (B' * P(:, :, i));
end
% Reverse time order (forward time)
t = flipud(tf - t);
P = flip(P, 3);
K = flip(K, 3);
end
function dPdt = riccati_ode(t, P_vec, A, B, Q, R)
% Riccati differential equation
n = size(A, 1);
P = reshape(P_vec, n, n);
% Riccati equation: -dP/dt = A'P + PA - PBR^(-1)B'P + Q
dP = -(A' * P + P * A - P * B * (R \ (B' * P)) + Q);
dPdt = reshape(dP, [], 1);
end
Python Implementation
import numpy as np
from scipy.integrate import solve_ivp
from scipy.linalg import solve_continuous_are
def lqr_continuous(A, B, Q, R, S=None, tf=None):
"""
Continuous-time LQR solution
"""
n, p = A.shape[0], B.shape[1]
if tf is None:
# Infinite-horizon case: solve CARE
P = solve_continuous_are(A, B, Q, R)
K = -np.linalg.solve(R, B.T @ P)
return K, P
else:
# Finite-horizon case: solve Riccati ODE
if S is None:
S = np.zeros_like(Q)
def riccati_ode(t, P_vec):
P = P_vec.reshape(n, n)
dP = -(A.T @ P + P @ A - P @ B @ np.linalg.solve(R, B.T @ P) + Q)
return dP.flatten()
# Solve backward from tf to 0
t_span = [tf, 0]
P0 = S.flatten()
sol = solve_ivp(riccati_ode, t_span, P0, dense_output=True)
# Evaluate at desired time points
t_eval = np.linspace(0, tf, 100)
P_traj = sol.sol(tf - t_eval).T # Reverse time
# Compute feedback gains
K_traj = np.zeros((len(t_eval), p, n))
P_matrices = np.zeros((len(t_eval), n, n))
for i, P_vec in enumerate(P_traj):
P_mat = P_vec.reshape(n, n)
P_matrices[i] = P_mat
K_traj[i] = -np.linalg.solve(R, B.T @ P_mat)
return K_traj, P_matrices, t_eval
# Example usage for infinite-horizon LQR
A = np.array([[0, 1], [-2, -3]])
B = np.array([[0], [1]])
Q = np.eye(2)
R = np.array([[1]])
K, P = lqr_continuous(A, B, Q, R)
print(f"Optimal gain: {K}")
print(f"Cost matrix: {P}")
Properties and Analysis
1. Stability
For the infinite-horizon case, if is controllable and is observable, then:
- The CARE has a unique positive definite solution
- The closed-loop system is asymptotically stable
2. Optimality
The LQR controller minimizes the quadratic cost function subject to the linear system dynamics.
3. Robustness
Continuous-time LQR controllers have excellent robustness properties:
- Gain margin: Infinite at low frequencies, dB at all frequencies
- Phase margin:
- Return difference: for all
4. Frequency Domain Interpretation
The LQR solution can be interpreted as shaping the open-loop transfer function to achieve desired closed-loop characteristics.
Design Guidelines
Weight Matrix Selection
State weights ():
- Diagonal elements penalize deviations in corresponding states
- Larger values → tighter regulation
- Can be interpreted as inverse of allowable state variance
Input weights ():
- Diagonal elements penalize control effort
- Larger values → more conservative control
- Trade-off between performance and control effort
Terminal weights ():
- Often chosen as steady-state solution:
- Can be zero for regulation problems
Tuning Process
- Start simple: Use identity matrices scaled appropriately
- Analyze response: Check settling time, overshoot, control effort
- Iterative design: Adjust weights based on performance requirements
- Physical constraints: Consider actuator limitations and system physics
Extensions and Applications
1. LQG (Linear Quadratic Gaussian)
Combines LQR with Kalman filter for systems with process noise and measurement noise.
2. Tracking Problems
Modify the cost function to track reference trajectories:
3. Constrained LQR
Handle input and state constraints using:
- Model Predictive Control (MPC)
- Barrier functions
- Penalty methods
4. Robust LQR
Design controllers that maintain performance under:
- Model uncertainties
- Parameter variations
- Disturbances
Comparison: Discrete vs. Continuous
Aspect | Discrete-Time | Continuous-Time |
---|---|---|
System | ||
Cost | ||
Riccati | Difference equation | Differential equation |
DARE/CARE | ||
Solution | Backward recursion | Backward integration |
Implementation | Direct | Requires integration |
References
- Continuous-time LQR Notes - Stanford
- Wang, T. (2023). 控制之美 (卷2). Tsinghua University Press.
- Rakovic, S. V., & Levine, W. S. (2018). Handbook of Model Predictive Control. Birkhäuser.
- Anderson, B. D. O., & Moore, J. B. (2007). Optimal Control: Linear Quadratic Methods. Dover Publications.
- Lewis, F. L., Vrabie, D., & Syrmos, V. L. (2012). Optimal Control (3rd ed.). John Wiley & Sons.