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.

Analytical Direct Shooting and Problem Simplification

This section revisits a minimum-time optimal control problem to emphasize an important modeling principle: not every problem requires heavy numerical machinery. Before writing code, the governing equations and optimality conditions should be simplified as far as possible analytically.

The example considered here is

minu(),tfJ=tf\min_{u(\cdot),\,t_f} J=t_f

subject to

x˙=vsinu,y˙=vcosu,v˙=gcosu,\begin{aligned} \dot{x} &= v\sin u,\\ \dot{y} &= -v\cos u,\\ \dot{v} &= g\cos u, \end{aligned}

with boundary conditions

x(0)=0,y(0)=0,v(0)=0,x(tf)=2,y(tf)=2,\begin{aligned} x(0)&=0, & y(0)&=0, & v(0)&=0,\\ x(t_f)&=2, & y(t_f)&=-2, \end{aligned}

and free terminal velocity.

Hamiltonian and Costate Equations

The Hamiltonian is

H=1+λxvsinuλyvcosu+λvgcosu.\mathcal{H} = 1 + \lambda_x v\sin u - \lambda_y v\cos u + \lambda_v g\cos u.

The costate equations are

λ˙x=Hx=0,λ˙y=Hy=0,λ˙v=Hv=λxsinu+λycosu.\begin{aligned} \dot{\lambda}_x &= -\frac{\partial \mathcal{H}}{\partial x} = 0,\\ \dot{\lambda}_y &= -\frac{\partial \mathcal{H}}{\partial y} = 0,\\ \dot{\lambda}_v &= -\frac{\partial \mathcal{H}}{\partial v} = -\lambda_x\sin u+\lambda_y\cos u. \end{aligned}

Thus,

λx=constant,λy=constant.\lambda_x=\text{constant}, \qquad \lambda_y=\text{constant}.

Stationarity Condition

For an interior optimal control,

Hu=0.\frac{\partial \mathcal{H}}{\partial u}=0.

Hence,

λxvcosu+λyvsinuλvgsinu=0.\lambda_x v\cos u + \lambda_y v\sin u - \lambda_v g\sin u = 0.

Rearranging,

λxvcosu=(λvgλyv)sinu.\lambda_x v\cos u = \left( \lambda_v g-\lambda_y v \right) \sin u.

Therefore,

tanu=λxvλvgλyv.\boxed{ \tan u = \frac{\lambda_x v} {\lambda_v g-\lambda_y v}. }

By differentiating this relation and using the state and costate equations, one obtains

u¨=0.\boxed{ \ddot{u}=0. }

Therefore, the optimal control is affine in time:

u(t)=c0+c1t.\boxed{ u(t)=c_0+c_1 t. }

This structural result is the key simplification.

Direct-Shooting Parameterization

A conventional direct-shooting implementation would parameterize u(t)u(t), integrate the dynamics numerically, and optimize over the control parameters and final time.

Here, however, the affine control allows the dynamics to be integrated analytically.

The unknown parameter vector is

p=[c0c1tf]T.\boxed{ \boldsymbol{p} = \begin{bmatrix} c_0 & c_1 & t_f \end{bmatrix}^{\mathsf T}. }

Analytical Integration of the Velocity

Using

u(t)=c0+c1t,u(t)=c_0+c_1t,

the velocity equation becomes

v˙=gcos(c0+c1t).\dot{v} = g\cos(c_0+c_1t).

Integrating from 0 to tt,

v(t)=v(0)+0tgcos(c0+c1τ)dτ=gc1[sin(c0+c1t)sinc0].\begin{aligned} v(t) &= v(0) + \int_0^t g\cos(c_0+c_1\tau)\,\mathrm{d}\tau\\ &= \frac{g}{c_1} \left[ \sin(c_0+c_1t)-\sin c_0 \right]. \end{aligned}

Since v(0)=0v(0)=0,

v(t)=gc1[sin(c0+c1t)sinc0].\boxed{ v(t) = \frac{g}{c_1} \left[ \sin(c_0+c_1t)-\sin c_0 \right]. }

The case c1=0c_1=0 must be treated separately because the above form contains division by c1c_1.

Analytical Integration of the Horizontal Position

The horizontal dynamics are

x˙=vsinu.\dot{x} = v\sin u.

Substituting v(t)v(t) and u(t)u(t),

x˙=gc1[sin(c0+c1t)sinc0]sin(c0+c1t).\dot{x} = \frac{g}{c_1} \left[ \sin(c_0+c_1t)-\sin c_0 \right] \sin(c_0+c_1t).

Expanding,

x˙=gc1sin2(c0+c1t)gsinc0c1sin(c0+c1t).\dot{x} = \frac{g}{c_1} \sin^2(c_0+c_1t) - \frac{g\sin c_0}{c_1} \sin(c_0+c_1t).

Using

sin2α=1cos2α2,\sin^2\alpha = \frac{1-\cos 2\alpha}{2},

we obtain

x˙=g2c1g2c1cos(2c0+2c1t)gsinc0c1sin(c0+c1t).\dot{x} = \frac{g}{2c_1} - \frac{g}{2c_1} \cos(2c_0+2c_1t) - \frac{g\sin c_0}{c_1} \sin(c_0+c_1t).

Integrating and enforcing x(0)=0x(0)=0 gives

x(t)=gt2c1g4c12[sin(2c0+2c1t)sin(2c0)]+gsinc0c12[cos(c0+c1t)cosc0].\begin{aligned} x(t) ={}& \frac{gt}{2c_1} - \frac{g}{4c_1^2} \left[ \sin(2c_0+2c_1t)-\sin(2c_0) \right] \nonumber\\ &+ \frac{g\sin c_0}{c_1^2} \left[ \cos(c_0+c_1t)-\cos c_0 \right]. \end{aligned}

Therefore,

x(t)=gt2c1g4c12[sin(2c0+2c1t)sin2c0]+gsinc0c12[cos(c0+c1t)cosc0].\boxed{ x(t) = \frac{gt}{2c_1} - \frac{g}{4c_1^2} \left[ \sin(2c_0+2c_1t)-\sin 2c_0 \right] + \frac{g\sin c_0}{c_1^2} \left[ \cos(c_0+c_1t)-\cos c_0 \right]. }

Analytical Integration of the Vertical Position

The vertical dynamics are

y˙=vcosu.\dot{y} = -v\cos u.

Substituting,

y˙=gc1[sin(c0+c1t)sinc0]cos(c0+c1t).\dot{y} = -\frac{g}{c_1} \left[ \sin(c_0+c_1t)-\sin c_0 \right] \cos(c_0+c_1t).

Thus,

y˙=gc1sin(c0+c1t)cos(c0+c1t)+gsinc0c1cos(c0+c1t).\begin{aligned} \dot{y} ={}& -\frac{g}{c_1} \sin(c_0+c_1t)\cos(c_0+c_1t) \nonumber\\ &+ \frac{g\sin c_0}{c_1} \cos(c_0+c_1t). \end{aligned}

Integrating and enforcing y(0)=0y(0)=0,

y(t)=g2c12[sin2(c0+c1t)sin2c0]+gsinc0c12[sin(c0+c1t)sinc0].\begin{aligned} y(t) ={}& -\frac{g}{2c_1^2} \left[ \sin^2(c_0+c_1t)-\sin^2 c_0 \right] \nonumber\\ &+ \frac{g\sin c_0}{c_1^2} \left[ \sin(c_0+c_1t)-\sin c_0 \right]. \end{aligned}

Therefore,

y(t)=g2c12[sin2(c0+c1t)sin2c0]+gsinc0c12[sin(c0+c1t)sinc0].\boxed{ y(t) = -\frac{g}{2c_1^2} \left[ \sin^2(c_0+c_1t)-\sin^2 c_0 \right] + \frac{g\sin c_0}{c_1^2} \left[ \sin(c_0+c_1t)-\sin c_0 \right]. }

Terminal Constraints

The terminal conditions require

x(tf;c0,c1)=2,y(tf;c0,c1)=2.\begin{aligned} x(t_f;c_0,c_1)&=2,\\ y(t_f;c_0,c_1)&=-2. \end{aligned}

Define

F1(c0,c1,tf)=x(tf;c0,c1)2,F2(c0,c1,tf)=y(tf;c0,c1)+2.\begin{aligned} F_1(c_0,c_1,t_f) &= x(t_f;c_0,c_1)-2,\\ F_2(c_0,c_1,t_f) &= y(t_f;c_0,c_1)+2. \end{aligned}

The optimization problem becomes

minc0,c1,tftf\boxed{ \min_{c_0,c_1,t_f} t_f }

subject to

F1(c0,c1,tf)=0,F2(c0,c1,tf)=0.\boxed{ F_1(c_0,c_1,t_f)=0, \qquad F_2(c_0,c_1,t_f)=0. }

No numerical integration of the state equations is required.

Degrees-of-Freedom Analysis

There are three unknowns:

c0,c1,tf.c_0,\quad c_1,\quad t_f.

There are two terminal equality constraints:

F1=0,F2=0.F_1=0, \qquad F_2=0.

Hence, the number of free degrees of freedom is

32=1.\boxed{ 3-2=1. }

That remaining degree of freedom allows minimization of tft_f.

If tft_f were fixed, there would be two unknowns and two equations, leaving no optimization degree of freedom.

Why This Formulation Is Superior

The analytical reduction provides several advantages:

The main lesson is not that numerical integration is wrong. The lesson is that it should not be used when the problem can be simplified exactly.

Treatment of the Case c1=0c_1=0

If c1=0c_1=0, then

u(t)=c0.u(t)=c_0.

The velocity becomes

v(t)=gtcosc0.v(t)=gt\cos c_0.

Then

x(t)=12gt2sinc0cosc0,y(t)=12gt2cos2c0.\begin{aligned} x(t) &= \frac{1}{2}gt^2\sin c_0\cos c_0,\\ y(t) &= -\frac{1}{2}gt^2\cos^2 c_0. \end{aligned}

This special case can be checked separately against the terminal constraints.

MATLAB Formulation

function solve_session31_part1

    g = 9.81;

    z0 = [0.5; 0.5; 1.0]; % [c0, c1, tf]

    obj = @(z) z(3);

    nonlcon = @(z) terminal_constraints(z,g);

    options = optimoptions('fmincon', ...
        'Display','iter', ...
        'Algorithm','sqp', ...
        'ConstraintTolerance',1e-10, ...
        'OptimalityTolerance',1e-10);

    lb = [-pi; -10; 1e-3];
    ub = [ pi;  10; 20];

    z = fmincon(obj,z0,[],[],[],[],lb,ub,nonlcon,options);

    c0 = z(1);
    c1 = z(2);
    tf = z(3);

    fprintf('c0 = %.12f\n',c0);
    fprintf('c1 = %.12f\n',c1);
    fprintf('tf = %.12f\n',tf);
end

function [c,ceq] = terminal_constraints(z,g)

    c0 = z(1);
    c1 = z(2);
    tf = z(3);

    if abs(c1) < 1e-8
        x = 0.5*g*tf^2*sin(c0)*cos(c0);
        y = -0.5*g*tf^2*cos(c0)^2;
    else
        x = g*tf/(2*c1) ...
          - g/(4*c1^2)*(sin(2*c0+2*c1*tf)-sin(2*c0)) ...
          + g*sin(c0)/c1^2*(cos(c0+c1*tf)-cos(c0));

        y = -g/(2*c1^2)*(sin(c0+c1*tf)^2-sin(c0)^2) ...
          + g*sin(c0)/c1^2*(sin(c0+c1*tf)-sin(c0));
    end

    c = [];
    ceq = [x-2; y+2];
end

Verification

After obtaining (c0,c1,tf)(c_0,c_1,t_f):

  1. verify the terminal constraints;

  2. reconstruct u(t)u(t) analytically;

  3. reconstruct v(t)v(t), x(t)x(t), and y(t)y(t);

  4. optionally integrate the original dynamics numerically;

  5. compare the numerical and analytical trajectories.

General Lessons for Direct Shooting

  1. Derive the structure of the optimal control first.

  2. Use analytical integration whenever possible.

  3. Count unknowns, equations, and degrees of freedom.

  4. Do not use a numerical solver as a substitute for analysis.

  5. Formulate the smallest nonlinear program that represents the problem.

Connection. When the reduced Hamiltonian is linear in a bounded control, switching functions distinguish bang arcs from possible singular intervals.