The Principle of Optimality and the Hamilton–Jacobi–Bellman Equation
Earlier sections developed optimality conditions through the calculus of variations, Pontryagin’s minimum principle, and direct numerical methods. Those approaches typically produce an open-loop optimal trajectory for a specified initial condition and model.
Dynamic programming takes a different viewpoint. Instead of solving only for one optimal trajectory from one initial condition, it asks:
What is the minimum remaining cost from every possible state and every possible time?
The answer is encoded in the value function, also called the optimal cost-to-go. The partial differential equation satisfied by this function is the Hamilton–Jacobi–Bellman equation.
Open-Loop and Closed-Loop Optimal Control¶
An open-loop control is determined as a function of time:
It is computed for a particular initial state and a particular model. Once computed, the control does not explicitly change in response to deviations of the measured state.
A closed-loop control is a feedback law:
The current state is used to determine the control. Dynamic programming naturally generates this feedback form because it computes the optimal action for every state-time pair.
The Principle of Optimality¶
Suppose an optimal trajectory connects point to point . Let and be any two points lying on that trajectory.
Then the segment of the trajectory connecting to must itself be optimal for the subproblem that begins at and ends at .
A shorter geometric statement is:
What the Principle Does Not Mean¶
Suppose is not on the optimal trajectory from to . Even if the path from to is optimal and the path from to is optimal, the concatenated path
need not be optimal from to .
The principle of optimality applies only to subarcs of the original optimal path.
Geometric Illustration¶
Figure 1:The principle of optimality applies to subarcs of the optimal trajectory.
Planning Backward and Executing Forward¶
Dynamic programming is based on a backward-planning idea:
Start from the terminal objective.
Determine the minimum remaining cost from states near the terminal time.
Continue backward in time.
Once the full policy is known, execute it forward in time.
This is often summarized by the statement:
Life is lived forward, but it is planned backward.
In control, one determines the optimal cost remaining from the current state to the terminal time. If the system deviates from the nominal path, the same value function provides the new optimal action from the new state.
Continuous-Time Optimal Control Problem¶
Consider
with Bolza cost
The objective is to minimize over admissible controls.
The Cost-to-Go Function¶
Instead of starting only at , define a problem beginning at an arbitrary state and time :
The optimal cost-to-go, or value function, is
The terminal boundary condition is
Interpretation of the Value Function¶
The value function answers the question:
If the system is currently at state at time , what is the smallest possible cost that remains from now until the terminal time?
At the initial condition,
is the optimal value of the original problem.
Along an optimal trajectory,
decreases as cost is accumulated and eventually reaches the terminal cost.
Total Derivative Along the Optimal Trajectory¶
Along an optimal trajectory,
Its total derivative is
Because
differentiating with respect to the lower integration limit gives
Therefore,
Substituting
yields
Hamiltonian Form¶
Define the Hamiltonian
where
Then, along the optimal trajectory,
Because the control must minimize the Hamiltonian, the general HJB equation is
The terminal condition is
The Hamilton–Jacobi–Bellman Equation¶
The compact Hamiltonian form is
This is a nonlinear first-order partial differential equation with a terminal boundary condition.
Why the HJB Equation Is a Backward-Time Equation¶
The boundary condition is given at , not at :
Therefore, the HJB equation is integrated backward from the terminal time toward the initial time.
This matches the cost-to-go interpretation: one begins with the cost remaining at the end and works backward to determine the cost remaining at all earlier times.
Feedback Control from the HJB Equation¶
Once is known, the optimal control is obtained from
This is a state-feedback law.
The central advantage is that the solution is defined for all states in the domain, not merely along one nominal trajectory.
Relationship to the Costate¶
In Pontryagin’s minimum principle,
is the costate.
In dynamic programming,
is the gradient of the value function.
Along an optimal trajectory,
Thus, the costate is the gradient of the optimal cost-to-go evaluated along the optimal path.
Connection to the Costate Equation¶
Differentiate
with respect to time:
The HJB equation implies the same costate dynamics as Pontryagin’s minimum principle:
Therefore, the HJB equation and the minimum principle are consistent descriptions of optimality.
Why HJB Is More General Than a Single Open-Loop Solution¶
Pontryagin’s principle typically produces an extremal trajectory for a specified initial state.
The HJB equation produces the full value function
which contains the optimal cost from every state and time.
Consequently, the HJB equation can generate feedback control even after disturbances or modeling errors move the system away from the nominal trajectory.
Replanning Interpretation¶
Suppose the nominal trajectory is interrupted by an unexpected change. The current state becomes
One does not need to return to the original initial condition. Instead, the optimal policy evaluates
and continues optimally from the current state.
This is the mathematical version of replanning a route after encountering a road closure.
Computational Challenge¶
The HJB equation is a PDE in state and time. If the state dimension is , then the value function is defined over an -dimensional domain.
The computational burden grows rapidly with . This is known as the curse of dimensionality.
This makes direct solution of the HJB equation impractical for many high-dimensional systems.
Introductory Scalar Linear–Quadratic Example¶
Consider
subject to
The running cost is
The terminal cost is
The dynamics are
Hamiltonian for the Example¶
The HJB Hamiltonian is
The minimizing control satisfies
Therefore,
Substituting into the Hamiltonian gives
Hence, the HJB equation is
The terminal condition is
Quadratic Value-Function Ansatz¶
Because the dynamics are linear and the cost is quadratic, assume
The terminal condition gives
so
The derivatives are
Optimal Feedback Law¶
Using
the optimal control becomes
This is a time-varying linear state-feedback law.
The feedback gain is
Riccati Differential Equation¶
Substitute the quadratic ansatz into the HJB equation:
For nonzero , divide by :
Therefore,
This differential equation is integrated backward in time.
Closed-Loop State Dynamics¶
Substituting
into the system dynamics gives
Once is found backward in time, the optimal state can be propagated forward from
Backward Planning and Forward Execution¶
The solution procedure has two stages:
Integrate the Riccati equation backward from
Integrate the closed-loop state equation forward from
This is the precise mathematical realization of planning backward and executing forward.
Numerical MATLAB Template¶
tf = 5;
% Backward Riccati equation
riccati = @(t,P) P.^2 + 4*P - 1;
% Integrate backward from P(tf) = 1
[tP, P] = ode45(riccati, [tf 0], 1);
% Reverse arrays for interpolation in increasing time
tP = flipud(tP);
P = flipud(P);
Pfun = @(t) interp1(tP, P, t, 'pchip');
% Initial state
x0 = 1;
% Closed-loop dynamics
closedLoop = @(t,x) -(2 + Pfun(t))*x;
% Integrate state forward
[tx, x] = ode45(closedLoop, [0 tf], x0);
% Optimal control
u = -arrayfun(Pfun, tx).*x;Verification Checks¶
For the scalar example, verify:
;
the Riccati residual is small;
;
the state satisfies
the HJB residual is small;
the value function decreases consistently with the accumulated running cost.
HJB Residual¶
For an approximate value function and control , define
A high-quality approximation should satisfy
Comparison with Pontryagin’s Minimum Principle¶
For this example, the Hamiltonian in the minimum principle is
Stationarity gives
Dynamic programming gives
Therefore,
The two methods produce the same optimal control.
Summary¶
The principle of optimality states that every subarc of an optimal trajectory is itself optimal.
The value function is the minimum remaining cost from a state-time pair.
The terminal condition is specified at .
The HJB equation is solved backward in time.
The general continuous-time HJB equation is
The optimal feedback law is obtained by minimizing the HJB Hamiltonian.
Along the optimal trajectory,
Dynamic programming produces a feedback law rather than only one open-loop trajectory.
The HJB equation suffers from the curse of dimensionality.
For linear systems with quadratic costs, a quadratic value function leads to a Riccati differential equation.
The scalar example produces
Connection. Applying the HJB equation to finite-horizon LQR shows how a quadratic value function turns a nonlinear PDE into a matrix differential equation.