Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Coupled State–Costate Dynamics, Hamiltonian Matrices, and Shooting Instability

The first-order necessary conditions of optimal control form a coupled dynamical system. The state and costate cannot generally be solved independently because the optimal control depends on both.

This section develops that structure through a scalar quadratic optimal-control example and uses the result to explain why simple shooting can fail, even when:

The main topics are:

  1. coupled state–costate equations;

  2. the costate as a sensitivity or dual variable;

  3. a fixed-endpoint quadratic example;

  4. eigenvalue and eigenvector analysis;

  5. Hamiltonian matrix structure;

  6. spectral symmetry of Hamiltonian systems;

  7. propagation of shooting errors;

  8. long-horizon instability; and

  9. motivation for robust numerical optimal-control methods.

Canonical State–Costate Equations

Consider the optimal-control problem

minu()[Φ(x(tf),tf)+t0tfL(x,u,t)dt],\min_{\boldsymbol{u}(\cdot)} \left[ \Phi(\boldsymbol{x}(t_f),t_f) + \int_{t_0}^{t_f} L(\boldsymbol{x},\boldsymbol{u},t)\,\mathrm{d} t \right],

subject to

x˙=f(x,u,t).\dot{\boldsymbol{x}} = \boldsymbol{f}(\boldsymbol{x},\boldsymbol{u},t).

The Hamiltonian is

H(x,u,λ,t)=L(x,u,t)+λTf(x,u,t).H(\boldsymbol{x},\boldsymbol{u},\boldsymbol{\lambda},t) = L(\boldsymbol{x},\boldsymbol{u},t) + \boldsymbol{\lambda}^{\mathsf{T}}\boldsymbol{f}(\boldsymbol{x},\boldsymbol{u},t).

The canonical equations are

x˙=(Hλ)T,λ˙=(Hx)T.\begin{aligned} \dot{\boldsymbol{x}} &= \left( \frac{\partial H}{\partial\boldsymbol{\lambda}} \right)^{\mathsf{T}}, \\ \dot{\boldsymbol{\lambda}} &= - \left( \frac{\partial H}{\partial\boldsymbol{x}} \right)^{\mathsf{T}}. \end{aligned}

Expanding the costate equation gives

λ˙=[Lx+λTfx]T.\dot{\boldsymbol{\lambda}} = - \left[ \frac{\partial L}{\partial\boldsymbol{x}} + \boldsymbol{\lambda}^{\mathsf{T}} \frac{\partial\boldsymbol{f}}{\partial\boldsymbol{x}} \right]^{\mathsf{T}}.

Thus, the costate generally depends on:

Why the State and Costate Are Coupled

Suppose the pointwise optimality condition gives

u=u(x,λ,t).\boldsymbol{u}^* = \boldsymbol{u}^*(\boldsymbol{x}^*,\boldsymbol{\lambda}^*,t).

Substitution into the state equation gives

x˙=f ⁣(x,u(x,λ,t),t).\dot{\boldsymbol{x}}^* = \boldsymbol{f}\!\left( \boldsymbol{x}^*, \boldsymbol{u}^*(\boldsymbol{x}^*,\boldsymbol{\lambda}^*,t), t \right).

Therefore,

x˙=gx(x,λ,t).\dot{\boldsymbol{x}}^* = \boldsymbol{g}_x(\boldsymbol{x}^*,\boldsymbol{\lambda}^*,t).

Similarly,

λ˙=gλ(x,λ,t).\dot{\boldsymbol{\lambda}}^* = \boldsymbol{g}_\lambda(\boldsymbol{x}^*,\boldsymbol{\lambda}^*,t).

The combined optimality system is

ddt[xλ]=[gx(x,λ,t)gλ(x,λ,t)].\boxed{ \frac{\,\mathrm{d}}{\,\mathrm{d} t} \begin{bmatrix} \boldsymbol{x}^*\\ \boldsymbol{\lambda}^* \end{bmatrix} = \begin{bmatrix} \boldsymbol{g}_x(\boldsymbol{x}^*,\boldsymbol{\lambda}^*,t)\\ \boldsymbol{g}_\lambda(\boldsymbol{x}^*,\boldsymbol{\lambda}^*,t) \end{bmatrix}. }

The two systems must be solved simultaneously.

Interpretation of the Costate

The costate is a dual or adjoint variable associated with the state dynamics.

Conceptually, it measures the sensitivity of the optimal cost to a perturbation in the state.

A common interpretation is

λi(t)Jxi(t),\lambda_i(t) \sim \frac{\partial J^*}{\partial x_i(t)},

where JJ^* denotes the optimal value function, subject to sign and formulation conventions.

If perturbing the state had no influence on the cost, then there would be no meaningful optimization pressure associated with that state direction.

The costate transmits this sensitivity through the optimality system and directly affects the optimal control.

A Scalar Quadratic Example

Consider

minu()J=120tf(x2+u2)dt\boxed{ \min_{u(\cdot)} J = \frac{1}{2} \int_0^{t_f} \left( x^2+u^2 \right)\,\mathrm{d} t }

subject to

x˙=x+u.\dot{x} = x+u.

The time horizon tft_f is fixed, and the state is fixed at both endpoints:

x(0)=x0,x(tf)=xf.\begin{aligned} x(0)&=x_0,\\ x(t_f)&=x_f. \end{aligned}

There is no terminal cost.

Hamiltonian and Optimal Control

The Hamiltonian is

H=12(x2+u2)+λ(x+u).H = \frac{1}{2} \left( x^2+u^2 \right) + \lambda(x+u).

The Hamiltonian is quadratic in uu, and the control is unconstrained. Therefore, the stationarity condition applies:

Hu=u+λ=0.\frac{\partial H}{\partial u} = u+\lambda = 0.

Hence,

u=λ.\boxed{ u^*=-\lambda^*. }

This formula explicitly demonstrates that the optimal control depends on the costate.

Coupled Optimality Dynamics

The state equation becomes

x˙=xλ.\dot{x}^* = x^*-\lambda^*.

The costate equation is

λ˙=Hx=(x+λ).\begin{aligned} \dot{\lambda}^* &= -\frac{\partial H}{\partial x} \\ &= -\left(x^*+\lambda^*\right). \end{aligned}

Therefore,

ddt[xλ]=[1111][xλ].\boxed{ \frac{\,\mathrm{d}}{\,\mathrm{d} t} \begin{bmatrix} x\\ \lambda \end{bmatrix} = \begin{bmatrix} 1 & -1\\ -1 & -1 \end{bmatrix} \begin{bmatrix} x\\ \lambda \end{bmatrix}. }

Define

p=[xλ],A=[1111].\boldsymbol{p} = \begin{bmatrix} x\\ \lambda \end{bmatrix}, \qquad \boldsymbol{A} = \begin{bmatrix} 1 & -1\\ -1 & -1 \end{bmatrix}.

Then

p˙=Ap.\dot{\boldsymbol{p}} = \boldsymbol{A}\boldsymbol{p}.

Boundary Conditions

The state is fixed at both endpoints:

x(0)=x0,x(tf)=xf.\begin{aligned} x(0)&=x_0,\\ x(t_f)&=x_f. \end{aligned}

Because both endpoint values of the state are fixed, the costate has no directly prescribed initial or final value.

Thus, the problem is a two-point boundary-value problem with:

Eigenvalue Analysis

For

p˙=Ap,\dot{\boldsymbol{p}} = \boldsymbol{A}\boldsymbol{p},

the eigenvalues satisfy

det(μIA)=0.\det(\mu\boldsymbol{I}-\boldsymbol{A})=0.

Here,

μIA=[μ111μ+1].\mu\boldsymbol{I}-\boldsymbol{A} = \begin{bmatrix} \mu-1 & 1\\ 1 & \mu+1 \end{bmatrix}.

Therefore,

0=(μ1)(μ+1)1=μ22.\begin{aligned} 0 &= (\mu-1)(\mu+1)-1 \\ &= \mu^2-2. \end{aligned}

Hence,

μ1,2=±2.\boxed{ \mu_{1,2} = \pm\sqrt{2}. }

One eigenvalue is negative and the other is positive.

Thus, the state–costate dynamics contain:

Eigenvectors

For

μ1=2,\mu_1=-\sqrt{2},

an eigenvector satisfies

(μ1IA)v1=0.(\mu_1\boldsymbol{I}-\boldsymbol{A})\boldsymbol{v}_1=\boldsymbol{0}.

Choosing the second component equal to one gives

v1=[11+21].\boldsymbol{v}_1 = \begin{bmatrix} \dfrac{1}{1+\sqrt{2}}\\[2mm] 1 \end{bmatrix}.

For

μ2=+2,\mu_2=+\sqrt{2},

one may choose

v2=[1121].\boldsymbol{v}_2 = \begin{bmatrix} \dfrac{1}{1-\sqrt{2}}\\[2mm] 1 \end{bmatrix}.

The general solution is

p(t)=C1v1e2t+C2v2e+2t.\boxed{ \boldsymbol{p}(t) = C_1\boldsymbol{v}_1e^{-\sqrt{2}t} + C_2\boldsymbol{v}_2e^{+\sqrt{2}t}. }

Stable and Unstable Modes

In forward time:

e2t0,e^{-\sqrt{2}t} \longrightarrow0,

whereas

e+2t.e^{+\sqrt{2}t} \longrightarrow\infty.

In backward time, the roles reverse.

Therefore, integrating the full Hamiltonian system in either direction generally exposes one unstable mode.

A Hamiltonian system exposes paired stable and unstable eigenvalues during forward integration.

Figure 1:A Hamiltonian system exposes paired stable and unstable eigenvalues during forward integration.

Hamiltonian Matrix Structure

For a general canonical system,

p˙=g(p),p=[xλ],\dot{\boldsymbol{p}} = \boldsymbol{g}(\boldsymbol{p}), \qquad \boldsymbol{p}= \begin{bmatrix} \boldsymbol{x}\\ \boldsymbol{\lambda} \end{bmatrix},

the Jacobian of the Hamiltonian vector field has the block form

gp=[HλxHλλHxxHxλ].\frac{\partial\boldsymbol{g}}{\partial\boldsymbol{p}} = \begin{bmatrix} H_{\lambda x} & H_{\lambda\lambda}\\ -H_{xx} & -H_{x\lambda} \end{bmatrix}.

This is a Hamiltonian matrix under the standard smoothness and symmetry assumptions on second derivatives.

A real matrix A\boldsymbol{A} is Hamiltonian if

ATJ+JA=0,\boldsymbol{A}^{\mathsf{T}}\boldsymbol{J}+\boldsymbol{J}\boldsymbol{A}=\boldsymbol{0},

where

J=[0II0].\boldsymbol{J} = \begin{bmatrix} \boldsymbol{0} & \boldsymbol{I}\\ -\boldsymbol{I} & \boldsymbol{0} \end{bmatrix}.

Equivalently,

JA\boldsymbol{J}\boldsymbol{A}

is symmetric.

Spectral Symmetry

Hamiltonian matrices have a characteristic eigenvalue symmetry.

If

μ\mu

is an eigenvalue, then the spectrum also contains

μ.-\mu.

For real matrices, complex conjugacy adds

μandμ.\overline{\mu} \quad\text{and}\quad -\overline{\mu}.

Thus, a complex eigenvalue generally appears in a quartet:

μ,  μ,  μ,  μ.\boxed{ \mu,\; -\mu,\; \overline{\mu},\; -\overline{\mu}. }

For a two-dimensional Hamiltonian system, only two eigenvalues exist. Therefore, a nonreal eigenvalue with nonzero real part would require four eigenvalues and cannot occur. The pair must instead lie:

In the present example, the pair is

±2.\pm\sqrt{2}.

Simple Shooting Formulation

Suppose the unknown initial costate is guessed as

λ(0)=λˉ0.\lambda(0)=\bar{\lambda}_0.

Then

[x(t)λ(t)]=eAt[x0λˉ0].\begin{bmatrix} x(t)\\ \lambda(t) \end{bmatrix} = e^{\boldsymbol{A} t} \begin{bmatrix} x_0\\ \bar{\lambda}_0 \end{bmatrix}.

The shooting method adjusts λˉ0\bar{\lambda}_0 until

x(tf)=xf.x(t_f)=x_f.

Define the residual

R(λˉ0)=x(tf;λˉ0)xf.R(\bar{\lambda}_0) = x(t_f;\bar{\lambda}_0)-x_f.

The desired initial costate satisfies

R(λ0)=0.R(\lambda_0^*)=0.

Propagation of Initial-Costate Error

Let the exact initial costate be

λ0.\lambda_0^*.

Define the initial error

δλ0=λˉ0λ0.\delta\lambda_0 = \bar{\lambda}_0-\lambda_0^*.

The trajectory error is

e(t)=[x(t)x(t)λ(t)λ(t)].\boldsymbol{e}(t) = \begin{bmatrix} x(t)-x^*(t)\\ \lambda(t)-\lambda^*(t) \end{bmatrix}.

Because the initial state is exact,

e(0)=[0δλ0].\boldsymbol{e}(0) = \begin{bmatrix} 0\\ \delta\lambda_0 \end{bmatrix}.

Therefore,

e(t)=eAt[0δλ0].\boxed{ \boldsymbol{e}(t) = e^{\boldsymbol{A} t} \begin{bmatrix} 0\\ \delta\lambda_0 \end{bmatrix}. }

Using the eigendecomposition

A=VDV1,\boldsymbol{A} = \boldsymbol{V}\boldsymbol{D}\boldsymbol{V}^{-1},

we have

eAt=V[e2t00e+2t]V1.e^{\boldsymbol{A} t} = \boldsymbol{V} \begin{bmatrix} e^{-\sqrt{2}t} & 0\\ 0 & e^{+\sqrt{2}t} \end{bmatrix} \boldsymbol{V}^{-1}.

Unless the initial error lies exactly in the stable eigenspace, it has a component that grows like

e+2t.e^{+\sqrt{2}t}.

Long-Horizon Error Amplification

Suppose the initial costate error has magnitude

δλ0=ε.|\delta\lambda_0|=\varepsilon.

The unstable contribution at the final time behaves approximately as

εe2tf.\varepsilon e^{\sqrt{2}t_f}.

Thus, even a tiny initial error becomes large when tft_f is sufficiently long.

To maintain a fixed final error tolerance τ\tau, the initial error must satisfy roughly

ετe2tf.\varepsilon \lesssim \tau e^{-\sqrt{2}t_f}.

The required initial-costate accuracy therefore becomes exponentially severe with the horizon length.

Overflow Can Occur Without Integration Error

The instability is not caused only by numerical integration.

Even if

eAte^{\boldsymbol{A} t}

is evaluated analytically or exactly to machine precision, the unstable mode can exceed the largest representable floating-point number.

Thus, overflow may occur because of:

dynamical instability,\text{dynamical instability},

not because of a low-order integration method.

A numerical integrator adds truncation and roundoff errors, which provide additional disturbances that can excite the unstable mode.

Why Backward Integration Does Not Solve the Problem

Forward integration contains the growing mode

e+2t.e^{+\sqrt{2}t}.

One might attempt backward integration from tft_f. However, backward time reverses stability:

e2te^{-\sqrt{2}t}

becomes the growing mode under backward propagation.

Therefore, the Hamiltonian boundary-value problem is generally not converted into a well-conditioned initial-value problem merely by changing the direction of integration.

Shooting Jacobian Conditioning

For scalar shooting,

R(λ0)=x(tf;λ0)xf.R(\lambda_0) = x(t_f;\lambda_0)-x_f.

Its derivative is

dRdλ0=x(tf)λ0.\frac{\,\mathrm{d} R}{\,\mathrm{d}\lambda_0} = \frac{\partial x(t_f)}{\partial\lambda_0}.

This sensitivity is a component of the state-transition matrix:

p(tf)p(0)=eAtf.\frac{\partial\boldsymbol{p}(t_f)}{\partial\boldsymbol{p}(0)} = e^{\boldsymbol{A} t_f}.

Because this matrix contains exponentially large and small singular directions, the shooting Jacobian can become poorly scaled or ill-conditioned.

This makes Newton corrections sensitive to:

Stable and Unstable Manifold Interpretation

The exact optimal trajectory lies at the intersection of conditions imposed at opposite ends of the interval.

The initial endpoint conditions define a set of allowable initial points. The terminal conditions define a set of trajectories that arrive at the required terminal set.

The correct solution must lie on a special manifold that balances stable and unstable Hamiltonian modes.

A small error moves the trajectory away from this manifold, after which the unstable mode dominates.

Why Multiple Shooting Helps

Multiple shooting divides

[0,tf]\left[0,t_f\right]

into shorter intervals.

Instead of propagating one initial error over the full horizon, each segment propagates errors only over a shorter duration.

If the maximum segment length is Δt\Delta t, the local amplification behaves like

e2Δte^{\sqrt{2}\Delta t}

rather than

e2tf.e^{\sqrt{2}t_f}.

Continuity constraints connect the segment solutions.

The method introduces more variables but improves conditioning.

Why Direct Methods Are Attractive

Direct methods avoid solving the continuous Hamiltonian boundary-value problem by shooting from one endpoint.

Instead, they discretize:

The resulting nonlinear programming problem can exploit:

This does not eliminate all numerical difficulties, but it often avoids catastrophic initial-value sensitivity.

Practical Diagnostic Workflow

Before implementing simple shooting:

  1. derive the coupled state–costate dynamics;

  2. substitute the optimal control;

  3. linearize around a representative trajectory;

  4. inspect eigenvalues or finite-time growth;

  5. estimate the amplification across the horizon;

  6. inspect scaling and endpoint sensitivity;

  7. test a short horizon first; and

  8. use multiple shooting or direct methods if the system is strongly unstable.

Common Errors

  1. Treating state and costate dynamics as decoupled.

  2. Solving the costate first and substituting it afterward without justification.

  3. Forgetting that the optimal control depends on the costate.

  4. Assuming a linear original plant produces a stable Hamiltonian system.

  5. Attributing every shooting failure to the ODE solver.

  6. Assuming backward integration removes instability.

  7. Ignoring exponential error amplification over long horizons.

  8. Using simple shooting without inspecting the spectrum or sensitivities.

  9. Confusing machine overflow with an algebraic error in the equations.

  10. Simplifying the physical problem instead of selecting a suitable numerical method.

Summary

The main conclusions are:

  1. State and costate equations form a coupled optimality system.

  2. The costate represents the sensitivity of the cost to state perturbations.

  3. In the quadratic example, the optimal control is u=λu^*=-\lambda^*.

  4. The resulting Hamiltonian dynamics contain eigenvalues ±2\pm\sqrt{2}.

  5. Hamiltonian spectra are symmetric about the real and imaginary axes.

  6. One mode grows in forward time and another grows in backward time.

  7. Initial-costate errors can grow exponentially across the horizon.

  8. This failure can occur even with analytic propagation and no integration error.

  9. Long-horizon simple shooting can exceed finite-precision capability.

  10. Multiple shooting and direct methods provide more practical alternatives.

Connection. The final complication for the indirect framework is a constraint that acts continuously along the trajectory, creating active sets, multipliers, and constrained arcs.