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.

Variation of the Hamiltonian Integral

the endpoint-variation section derived the first variation of the endpoint portion of the augmented functional. The remaining task is to vary the integral

t0tf(HλTx˙)dt,\int_{t_0}^{t_f}\left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right)\,\mathrm{d} t,

when the state, control, costate, initial time, and final time are all allowed to vary.

The derivation has four essential steps:

  1. apply the Leibniz rule to account for moving integration limits;

  2. compute the variation of the Hamiltonian;

  3. integrate the term containing δx˙\delta\dot{\boldsymbol{x}} by parts;

  4. collect the coefficients of the independent variations.

Starting point

Consider the augmented functional

Ja=ΦνTϕ+t0tf(HλTx˙)dt,J_a = \Phi-\boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi} + \int_{t_0}^{t_f} \left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right)\,\mathrm{d} t,

where

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 endpoint terms ΦνTϕ\Phi-\boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi} were handled in the endpoint-variation section. Define

I=t0tf(HλTx˙)dt.\mathcal{I} = \int_{t_0}^{t_f} \left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right)\,\mathrm{d} t.

This section derives δI\delta\mathcal{I}.

Why tt is not varied inside the integral

The symbol tt inside the integral is the dummy variable of integration. It is the independent variable with respect to which the trajectories are parameterized. Thus, inside the integral, one varies the functions x(t)\boldsymbol{x}(t), u(t)\boldsymbol{u}(t), and λ(t)\boldsymbol{\lambda}(t), but not the dummy variable tt itself.

By contrast, t0t_0 and tft_f are scalar parameters that define the lower and upper integration limits. They may be fixed or free and therefore may possess nonzero variations δt0\delta t_0 and δtf\delta t_f.

Leibniz rule for moving limits

Let

F(t)=H(x,u,λ,t)λTx˙.F(t)=H(\boldsymbol{x},\boldsymbol{u},\boldsymbol{\lambda},t)-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}.

Then

I=t0tfF(t)dt.\mathcal{I}=\int_{t_0}^{t_f}F(t)\,\mathrm{d} t.

The first variation is

δI=F(tf)δtfF(t0)δt0+t0tfδF(t)dt.\delta\mathcal{I} = F(t_f)\delta t_f - F(t_0)\delta t_0 + \int_{t_0}^{t_f}\delta F(t)\,\mathrm{d} t.

Substituting the definition of FF,

δI=[HλTx˙]tfδtf[HλTx˙]t0δt0+t0tfδ(HλTx˙)dt.\begin{aligned} \delta\mathcal{I} ={}& \left[H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right]_{t_f}\delta t_f - \left[H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right]_{t_0}\delta t_0 \nonumber\\ &+ \int_{t_0}^{t_f} \delta\left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right)\,\mathrm{d} t. \end{aligned}

Variation of the integrand

The integrand variation is

δ(HλTx˙)=δHδ(λTx˙).\delta\left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right) = \delta H - \delta\left(\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right).

Using the product rule,

δ(λTx˙)=δλTx˙+λTδx˙.\delta\left(\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right) = \delta\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}} + \boldsymbol{\lambda}^{\mathsf{T}}\delta\dot{\boldsymbol{x}}.

Therefore,

δ(HλTx˙)=δHδλTx˙λTδx˙.\delta\left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right) = \delta H - \delta\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}} - \boldsymbol{\lambda}^{\mathsf{T}}\delta\dot{\boldsymbol{x}}.

Variation of the Hamiltonian

Because

H=H(x,u,λ,t),H=H(\boldsymbol{x},\boldsymbol{u},\boldsymbol{\lambda},t),

the variation of HH at fixed tt is

δH=Hxδx+Huδu+Hλδλ.\delta H = H_{\boldsymbol{x}}\delta\boldsymbol{x} + H_{\boldsymbol{u}}\delta\boldsymbol{u} + H_{\boldsymbol{\lambda}}\delta\boldsymbol{\lambda}.

Here the derivative convention is

Hx=HxR1×n,Hu=HuR1×m,Hλ=HλR1×n.\begin{aligned} H_{\boldsymbol{x}}&=\frac{\partial H}{\partial\boldsymbol{x}}\in\mathbb{R}^{1\times n}, &H_{\boldsymbol{u}}&=\frac{\partial H}{\partial\boldsymbol{u}}\in\mathbb{R}^{1\times m}, &H_{\boldsymbol{\lambda}}&=\frac{\partial H}{\partial\boldsymbol{\lambda}}\in\mathbb{R}^{1\times n}. \end{aligned}

Thus each product in (14) is scalar.

Substitution into (12) gives

δ(HλTx˙)=Hxδx+Huδu+HλδλδλTx˙λTδx˙.\begin{aligned} \delta\left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right) ={}& H_{\boldsymbol{x}}\delta\boldsymbol{x} + H_{\boldsymbol{u}}\delta\boldsymbol{u} + H_{\boldsymbol{\lambda}}\delta\boldsymbol{\lambda} \nonumber\\ &- \delta\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}} - \boldsymbol{\lambda}^{\mathsf{T}}\delta\dot{\boldsymbol{x}}. \end{aligned}

Integration by parts

The final term in (16) contains the derivative of a variation. To express the first variation in terms of δx\delta\boldsymbol{x} rather than δx˙\delta\dot{\boldsymbol{x}}, integrate by parts:

t0tfλTδx˙dt=[λTδx]t0tft0tfλ˙Tδxdt.\int_{t_0}^{t_f}\boldsymbol{\lambda}^{\mathsf{T}}\delta\dot{\boldsymbol{x}}\,\mathrm{d} t = \left[\boldsymbol{\lambda}^{\mathsf{T}}\delta\boldsymbol{x}\right]_{t_0}^{t_f} - \int_{t_0}^{t_f}\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\delta\boldsymbol{x}\,\mathrm{d} t.

Therefore,

t0tfλTδx˙dt=[λTδx]t0tf+t0tfλ˙Tδxdt=λ(t0)Tδx(t0)λ(tf)Tδx(tf)+t0tfλ˙Tδxdt.\begin{aligned} - \int_{t_0}^{t_f}\boldsymbol{\lambda}^{\mathsf{T}}\delta\dot{\boldsymbol{x}}\,\mathrm{d} t ={}& - \left[\boldsymbol{\lambda}^{\mathsf{T}}\delta\boldsymbol{x}\right]_{t_0}^{t_f} + \int_{t_0}^{t_f}\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\delta\boldsymbol{x}\,\mathrm{d} t \nonumber\\ ={}& \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}(t_0) - \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}(t_f) \nonumber\\ &+ \int_{t_0}^{t_f}\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\delta\boldsymbol{x}\,\mathrm{d} t. \end{aligned}

Rearrangement of the interior terms

Substituting (18) into the integral variation yields

t0tfδ(HλTx˙)dt=λ(t0)Tδx(t0)λ(tf)Tδx(tf)+t0tf[Hxδx+λ˙Tδx+Huδu+HλδλδλTx˙]dt.\begin{aligned} \int_{t_0}^{t_f} \delta\left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right)\,\mathrm{d} t ={}& \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}(t_0) - \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}(t_f) \nonumber\\ &+ \int_{t_0}^{t_f} \Big[ H_{\boldsymbol{x}}\delta\boldsymbol{x} + \dot{\boldsymbol{\lambda}}^{\mathsf{T}}\delta\boldsymbol{x} + H_{\boldsymbol{u}}\delta\boldsymbol{u} \nonumber\\ &\hspace{4.5em} + H_{\boldsymbol{\lambda}}\delta\boldsymbol{\lambda} - \delta\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}} \Big]\,\mathrm{d} t. \end{aligned}

The state-variation terms combine directly:

Hxδx+λ˙Tδx=(Hx+λ˙T)δx.H_{\boldsymbol{x}}\delta\boldsymbol{x}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\delta\boldsymbol{x} = \left(H_{\boldsymbol{x}}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\right)\delta\boldsymbol{x}.

For the costate-variation terms, use the fact that the expression is scalar:

δλTx˙=x˙Tδλ.\delta\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}} = \dot{\boldsymbol{x}}^{\mathsf{T}}\delta\boldsymbol{\lambda}.

Hence

HλδλδλTx˙=(Hλx˙T)δλ.H_{\boldsymbol{\lambda}}\delta\boldsymbol{\lambda}- \delta\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}} = \left(H_{\boldsymbol{\lambda}}-\dot{\boldsymbol{x}}^{\mathsf{T}}\right)\delta\boldsymbol{\lambda}.

Therefore,

t0tfδ(HλTx˙)dt=λ(t0)Tδx(t0)λ(tf)Tδx(tf)+t0tf[(Hx+λ˙T)δx+Huδu+(Hλx˙T)δλ]dt.\begin{aligned} \int_{t_0}^{t_f} \delta\left(H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right)\,\mathrm{d} t ={}& \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}(t_0) - \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}(t_f) \nonumber\\ &+ \int_{t_0}^{t_f} \Big[ \left(H_{\boldsymbol{x}}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\right)\delta\boldsymbol{x} + H_{\boldsymbol{u}}\delta\boldsymbol{u} \nonumber\\ &\hspace{5em} + \left(H_{\boldsymbol{\lambda}}-\dot{\boldsymbol{x}}^{\mathsf{T}}\right)\delta\boldsymbol{\lambda} \Big]\,\mathrm{d} t. \end{aligned}

Complete variation before endpoint conversion

Combining (8) and (23) gives

δI=[HλTx˙]tfδtf[HλTx˙]t0δt0+λ(t0)Tδx(t0)λ(tf)Tδx(tf)+t0tf[(Hx+λ˙T)δx+Huδu+(Hλx˙T)δλ]dt.\begin{aligned} \delta\mathcal{I} ={}& \left[H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right]_{t_f}\delta t_f - \left[H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right]_{t_0}\delta t_0 \nonumber\\ &+ \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}(t_0) - \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}(t_f) \nonumber\\ &+ \int_{t_0}^{t_f} \Big[ \left(H_{\boldsymbol{x}}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\right)\delta\boldsymbol{x} + H_{\boldsymbol{u}}\delta\boldsymbol{u} \nonumber\\ &\hspace{5em} + \left(H_{\boldsymbol{\lambda}}-\dot{\boldsymbol{x}}^{\mathsf{T}}\right)\delta\boldsymbol{\lambda} \Big]\,\mathrm{d} t. \end{aligned}

At this stage, the endpoint state variations are the trajectory variations δx(t0)\delta\boldsymbol{x}(t_0) and δx(tf)\delta\boldsymbol{x}(t_f), not the total endpoint variations δx0\delta\boldsymbol{x}_0 and δxf\delta\boldsymbol{x}_f.

Conversion to total endpoint variations

The total endpoint variations satisfy

δx0=δx(t0)+x˙(t0)δt0,\begin{aligned} \delta\boldsymbol{x}_0 &= \delta\boldsymbol{x}(t_0)+\dot{\boldsymbol{x}}(t_0)\delta t_0, \end{aligned}
δxf=δx(tf)+x˙(tf)δtf.\begin{aligned} \delta\boldsymbol{x}_f &= \delta\boldsymbol{x}(t_f)+\dot{\boldsymbol{x}}(t_f)\delta t_f. \end{aligned}

Thus,

δx(t0)=δx0x˙(t0)δt0,\begin{aligned} \delta\boldsymbol{x}(t_0) &= \delta\boldsymbol{x}_0-\dot{\boldsymbol{x}}(t_0)\delta t_0, \end{aligned}
δx(tf)=δxfx˙(tf)δtf.\begin{aligned} \delta\boldsymbol{x}(t_f) &= \delta\boldsymbol{x}_f-\dot{\boldsymbol{x}}(t_f)\delta t_f. \end{aligned}

Substitute these relations into the boundary terms in (24):

λ(t0)Tδx(t0)λ(tf)Tδx(tf)=λ(t0)Tδx0λ(t0)Tx˙(t0)δt0λ(tf)Tδxf+λ(tf)Tx˙(tf)δtf.\begin{aligned} &\boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}(t_0) - \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}(t_f) \nonumber\\ ={}& \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}_0 - \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\dot{\boldsymbol{x}}(t_0)\delta t_0 \nonumber\\ &- \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}_f + \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\dot{\boldsymbol{x}}(t_f)\delta t_f. \end{aligned}

Now combine these terms with the Leibniz endpoint contributions. At the final time,

[HλTx˙]tfδtf+λ(tf)Tx˙(tf)δtf=H(tf)δtf.\begin{aligned} &\left[H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right]_{t_f}\delta t_f + \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\dot{\boldsymbol{x}}(t_f)\delta t_f \nonumber\\ &=H(t_f)\delta t_f. \end{aligned}

At the initial time,

[HλTx˙]t0δt0λ(t0)Tx˙(t0)δt0=H(t0)δt0.\begin{aligned} &- \left[H-\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\right]_{t_0}\delta t_0 - \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\dot{\boldsymbol{x}}(t_0)\delta t_0 \nonumber\\ &=-H(t_0)\delta t_0. \end{aligned}

Therefore, all terms involving λTx˙δt\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}}\delta t cancel exactly.

Final expression for the integral variation

The first variation of the Hamiltonian integral is

δI=λ(t0)Tδx0λ(tf)TδxfH(t0)δt0+H(tf)δtf+t0tf[(Hx+λ˙T)δx+Huδu+(Hλx˙T)δλ]dt.\boxed{ \begin{aligned} \delta\mathcal{I} ={}& \boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}_0 - \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}_f - H(t_0)\delta t_0 + H(t_f)\delta t_f \\ &+ \int_{t_0}^{t_f} \Big[ \left(H_{\boldsymbol{x}}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\right)\delta\boldsymbol{x} + H_{\boldsymbol{u}}\delta\boldsymbol{u} \\ &\hspace{5em} + \left(H_{\boldsymbol{\lambda}}-\dot{\boldsymbol{x}}^{\mathsf{T}}\right)\delta\boldsymbol{\lambda} \Big]\,\mathrm{d} t. \end{aligned} }

This is the principal result of the chapter.

Dimension verification

The dimensions of the interior coefficients are

Hx+λ˙TR1×n,δxRn×1,HuR1×m,δuRm×1,Hλx˙TR1×n,δλRn×1.\begin{aligned} H_{\boldsymbol{x}}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}} &\in\mathbb{R}^{1\times n}, &\delta\boldsymbol{x}&\in\mathbb{R}^{n\times 1}, \\ H_{\boldsymbol{u}}&\in\mathbb{R}^{1\times m}, &\delta\boldsymbol{u}&\in\mathbb{R}^{m\times 1}, \\ H_{\boldsymbol{\lambda}}-\dot{\boldsymbol{x}}^{\mathsf{T}}&\in\mathbb{R}^{1\times n}, &\delta\boldsymbol{\lambda}&\in\mathbb{R}^{n\times 1}. \end{aligned}

Each product is scalar, as required. The endpoint products are also scalar:

λ(t0)Tδx0,λ(tf)Tδxf,H(t0)δt0,H(tf)δtf.\boldsymbol{\lambda}(t_0)^{\mathsf{T}}\delta\boldsymbol{x}_0, \quad \boldsymbol{\lambda}(t_f)^{\mathsf{T}}\delta\boldsymbol{x}_f, \quad H(t_0)\delta t_0, \quad H(t_f)\delta t_f.

Interior necessary conditions anticipated

Because the interior variations are independent, the coefficients in (32) lead to

Hx+λ˙T=0T,\begin{aligned} H_{\boldsymbol{x}}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}}&=\boldsymbol{0}^{\mathsf{T}}, \end{aligned}
Hu=0T,\begin{aligned} H_{\boldsymbol{u}}&=\boldsymbol{0}^{\mathsf{T}}, \end{aligned}
Hλx˙T=0T.\begin{aligned} H_{\boldsymbol{\lambda}}-\dot{\boldsymbol{x}}^{\mathsf{T}}&=\boldsymbol{0}^{\mathsf{T}}. \end{aligned}

Equivalently,

λ˙=HxT,\begin{aligned} \dot{\boldsymbol{\lambda}} &= - H_{\boldsymbol{x}}^{\mathsf{T}}, \end{aligned}
0=HuT,\begin{aligned} \boldsymbol{0} &= H_{\boldsymbol{u}}^{\mathsf{T}}, \end{aligned}
x˙=HλT.\begin{aligned} \dot{\boldsymbol{x}} &= H_{\boldsymbol{\lambda}}^{\mathsf{T}}. \end{aligned}

Since

H=L+λTf,H=L+\boldsymbol{\lambda}^{\mathsf{T}}\boldsymbol{f},

one has

Hλ=fT,H_{\boldsymbol{\lambda}}=\boldsymbol{f}^{\mathsf{T}},

and therefore

x˙=HλT=f.\dot{\boldsymbol{x}}=H_{\boldsymbol{\lambda}}^{\mathsf{T}}=\boldsymbol{f}.

Thus the variation with respect to the costate simply recovers the original state dynamics.

Geometric picture of the derivation

Logical structure of the integral-variation derivation.

Figure 1:Logical structure of the integral-variation derivation.

Worked symbolic example

Consider the scalar system

x˙=ax+bu\dot{x}=ax+bu

with running cost

L(x,u)=12qx2+12ru2.L(x,u)=\frac{1}{2}qx^2+\frac{1}{2}ru^2.

The Hamiltonian is

H=12qx2+12ru2+λ(ax+bu).H = \frac{1}{2}qx^2 + \frac{1}{2}ru^2 + \lambda(ax+bu).

Its derivatives are

Hx=qx+aλ,Hu=ru+bλ,Hλ=ax+bu.\begin{aligned} H_x&=qx+a\lambda, \\ H_u&=ru+b\lambda, \\ H_\lambda&=ax+bu. \end{aligned}

The interior part of the first variation is

t0tf[(qx+aλ+λ˙)δx+(ru+bλ)δu+(ax+bux˙)δλ]dt.\begin{aligned} \int_{t_0}^{t_f} \Big[ (qx+a\lambda+\dot{\lambda})\delta x + (ru+b\lambda)\delta u + (ax+bu-\dot{x})\delta\lambda \Big]\,\mathrm{d} t. \end{aligned}

The corresponding interior necessary conditions are

x˙=ax+bu,λ˙=qxaλ,0=ru+bλ.\begin{aligned} \dot{x}&=ax+bu, \\ \dot{\lambda}&=-qx-a\lambda, \\ 0&=ru+b\lambda. \end{aligned}

If r>0r>0, the stationary control is

u=brλ.u^*=-\frac{b}{r}\lambda.

Connection to the full first variation

the endpoint-variation section obtained

δ(ΦνTϕ)=(Φx0νTϕx0)δx0+(Φt0νTϕt0)δt0+(ΦxfνTϕxf)δxf+(ΦtfνTϕtf)δtfϕTδν.\begin{aligned} \delta(\Phi-\boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}) ={}& \left(\Phi_{\boldsymbol{x}_0}-\boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{\boldsymbol{x}_0}\right)\delta\boldsymbol{x}_0 + \left(\Phi_{t_0}-\boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{t_0}\right)\delta t_0 \nonumber\\ &+ \left(\Phi_{\boldsymbol{x}_f}-\boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{\boldsymbol{x}_f}\right)\delta\boldsymbol{x}_f + \left(\Phi_{t_f}-\boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{t_f}\right)\delta t_f - \boldsymbol{\phi}^{\mathsf{T}}\delta\boldsymbol{\nu}. \end{aligned}

Adding (32) gives the complete first variation

δJa=(Φx0νTϕx0+λ(t0)T)δx0+(Φt0νTϕt0H(t0))δt0+(ΦxfνTϕxfλ(tf)T)δxf+(ΦtfνTϕtf+H(tf))δtfϕTδν+t0tf[(Hx+λ˙T)δx+Huδu+(Hλx˙T)δλ]dt.\begin{aligned} \delta J_a ={}& \left( \Phi_{\boldsymbol{x}_0} - \boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{\boldsymbol{x}_0} + \boldsymbol{\lambda}(t_0)^{\mathsf{T}} \right)\delta\boldsymbol{x}_0 \nonumber\\ &+ \left( \Phi_{t_0} - \boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{t_0} - H(t_0) \right)\delta t_0 \nonumber\\ &+ \left( \Phi_{\boldsymbol{x}_f} - \boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{\boldsymbol{x}_f} - \boldsymbol{\lambda}(t_f)^{\mathsf{T}} \right)\delta\boldsymbol{x}_f \nonumber\\ &+ \left( \Phi_{t_f} - \boldsymbol{\nu}^{\mathsf{T}}\boldsymbol{\phi}_{t_f} + H(t_f) \right)\delta t_f - \boldsymbol{\phi}^{\mathsf{T}}\delta\boldsymbol{\nu} \nonumber\\ &+ \int_{t_0}^{t_f} \Big[ \left(H_{\boldsymbol{x}}+\dot{\boldsymbol{\lambda}}^{\mathsf{T}}\right)\delta\boldsymbol{x} + H_{\boldsymbol{u}}\delta\boldsymbol{u} + \left(H_{\boldsymbol{\lambda}}-\dot{\boldsymbol{x}}^{\mathsf{T}}\right)\delta\boldsymbol{\lambda} \Big]\,\mathrm{d} t. \end{aligned}

This expression is the starting point for the necessary-conditions section, where the state equation, costate equation, stationarity condition, endpoint feasibility condition, and transversality conditions are stated systematically.

Common errors

  1. Varying the dummy variable tt. Only t0t_0 and tft_f generate endpoint-time variations.

  2. Omitting Leibniz terms. Variable limits produce endpoint contributions even before the integrand itself is varied.

  3. Missing the product-rule term. Both δλTx˙\delta\boldsymbol{\lambda}^{\mathsf{T}}\dot{\boldsymbol{x}} and λTδx˙\boldsymbol{\lambda}^{\mathsf{T}}\delta\dot{\boldsymbol{x}} must appear.

  4. Losing the sign during integration by parts. The leading minus sign acts on both the endpoint term and the remaining integral.

  5. Confusing δx(tf)\delta\boldsymbol{x}(t_f) with δxf\delta\boldsymbol{x}_f. The latter includes the effect of a moving final time.

  6. Using inconsistent row/column derivative conventions. Every coefficient–variation product must be scalar.

  7. Declaring Hu=0H_{\boldsymbol{u}}=0 without checking control bounds. Stationarity is an interior condition.

Connection. With endpoint and integral terms assembled, the coefficients of the independent variations can finally be interpreted as the necessary conditions.