Bang–Bang Control, Switching Functions, and Singular Arcs
This section revisits a bounded-control optimal control problem whose Hamiltonian is linear in the control. Such problems commonly produce bang-bang control, singular control, or combinations of both.
Consider
min u ( ⋅ ) J = ∫ 0 1 x 2 ( t ) u ( t ) d t \min_{u(\cdot)}
J
=
\int_0^1 x_2(t)u(t)\,\mathrm{d} t u ( ⋅ ) min J = ∫ 0 1 x 2 ( t ) u ( t ) d t subject to
x ˙ 1 = x 2 , x ˙ 2 = − x 2 + u , \begin{aligned}
\dot{x}_1 &= x_2,\\
\dot{x}_2 &= -x_2+u,
\end{aligned} x ˙ 1 x ˙ 2 = x 2 , = − x 2 + u , with
0 ≤ u ( t ) ≤ 2 , 0\leq u(t)\leq 2, 0 ≤ u ( t ) ≤ 2 , and boundary conditions
x 1 ( 0 ) = 0 , x 2 ( 0 ) = 1 , x 1 ( 1 ) = 1 , x 2 ( 1 ) = 1. \begin{aligned}
x_1(0)&=0, &
x_2(0)&=1,\\
x_1(1)&=1, &
x_2(1)&=1.
\end{aligned} x 1 ( 0 ) x 1 ( 1 ) = 0 , = 1 , x 2 ( 0 ) x 2 ( 1 ) = 1 , = 1. Hamiltonian ¶ The Hamiltonian is
H = x 2 u + λ 1 x 2 + λ 2 ( − x 2 + u ) = ( x 2 + λ 2 ) u + ( λ 1 − λ 2 ) x 2 . \begin{aligned}
\mathcal{H}
&=
x_2u
+
\lambda_1x_2
+
\lambda_2(-x_2+u)\\
&=
(x_2+\lambda_2)u
+
(\lambda_1-\lambda_2)x_2.
\end{aligned} H = x 2 u + λ 1 x 2 + λ 2 ( − x 2 + u ) = ( x 2 + λ 2 ) u + ( λ 1 − λ 2 ) x 2 . Thus,
H = ϕ ( t ) u + ( λ 1 − λ 2 ) x 2 , \boxed{
\mathcal{H}
=
\phi(t)u
+
(\lambda_1-\lambda_2)x_2,
} H = ϕ ( t ) u + ( λ 1 − λ 2 ) x 2 , where
ϕ ( t ) = x 2 ( t ) + λ 2 ( t ) \boxed{
\phi(t)
=
x_2(t)+\lambda_2(t)
} ϕ ( t ) = x 2 ( t ) + λ 2 ( t ) is the switching function.
Bang-Bang Minimization Rule ¶ Because the Hamiltonian is affine in u u u ,
u ∗ = arg min 0 ≤ u ≤ 2 H . u^*
=
\arg\min_{0\leq u\leq 2}\mathcal{H}. u ∗ = arg 0 ≤ u ≤ 2 min H . Therefore,
u ∗ ( t ) = { 0 , ϕ ( t ) > 0 , 2 , ϕ ( t ) < 0 , undetermined by first-order minimization , ϕ ( t ) = 0. \boxed{
u^*(t)
=
\begin{cases}
0, & \phi(t)>0,\\
2, & \phi(t)<0,\\
\text{undetermined by first-order minimization}, & \phi(t)=0.
\end{cases}
} u ∗ ( t ) = ⎩ ⎨ ⎧ 0 , 2 , undetermined by first-order minimization , ϕ ( t ) > 0 , ϕ ( t ) < 0 , ϕ ( t ) = 0. The case ϕ = 0 \phi=0 ϕ = 0 is the candidate singular case.
Costate Equations ¶ The costate equations are
λ ˙ 1 = − ∂ H ∂ x 1 = 0 , λ ˙ 2 = − ∂ H ∂ x 2 . \begin{aligned}
\dot{\lambda}_1
&=
-\frac{\partial \mathcal{H}}{\partial x_1}
=
0,\\
\dot{\lambda}_2
&=
-\frac{\partial \mathcal{H}}{\partial x_2}.
\end{aligned} λ ˙ 1 λ ˙ 2 = − ∂ x 1 ∂ H = 0 , = − ∂ x 2 ∂ H . Since
∂ H ∂ x 2 = u + λ 1 − λ 2 , \frac{\partial \mathcal{H}}{\partial x_2}
=
u+\lambda_1-\lambda_2, ∂ x 2 ∂ H = u + λ 1 − λ 2 , we obtain
λ ˙ 2 = − u − λ 1 + λ 2 . \boxed{
\dot{\lambda}_2
=
-u-\lambda_1+\lambda_2.
} λ ˙ 2 = − u − λ 1 + λ 2 . Also,
λ 1 = constant . \boxed{
\lambda_1=\text{constant}.
} λ 1 = constant . Testing Constant Bang Controls ¶ Before pursuing a singular arc, one should test whether u = 0 u=0 u = 0 or u = 2 u=2 u = 2 over the entire interval can satisfy the boundary conditions.
Case u = 0 u=0 u = 0 ¶ Then
x ˙ 2 = − x 2 , \dot{x}_2=-x_2, x ˙ 2 = − x 2 , so
x 2 ( t ) = e − t . x_2(t)=e^{-t}. x 2 ( t ) = e − t . Thus,
x 2 ( 1 ) = e − 1 ≠ 1. x_2(1)=e^{-1}\neq 1. x 2 ( 1 ) = e − 1 = 1. Therefore, u = 0 u=0 u = 0 over the full interval is infeasible.
Case u = 2 u=2 u = 2 ¶ Then
x ˙ 2 = − x 2 + 2. \dot{x}_2=-x_2+2. x ˙ 2 = − x 2 + 2. With x 2 ( 0 ) = 1 x_2(0)=1 x 2 ( 0 ) = 1 ,
x 2 ( t ) = 2 − e − t . x_2(t)=2-e^{-t}. x 2 ( t ) = 2 − e − t . Hence,
x 2 ( 1 ) = 2 − e − 1 ≠ 1. x_2(1)=2-e^{-1}\neq 1. x 2 ( 1 ) = 2 − e − 1 = 1. Therefore, u = 2 u=2 u = 2 over the full interval is also infeasible.
Singular-Arc Condition ¶ On a singular arc,
ϕ ( t ) = x 2 ( t ) + λ 2 ( t ) = 0. \boxed{
\phi(t)
=
x_2(t)+\lambda_2(t)
=
0.
} ϕ ( t ) = x 2 ( t ) + λ 2 ( t ) = 0. Therefore,
λ 2 = − x 2 . \lambda_2=-x_2. λ 2 = − x 2 . Differentiating,
ϕ ˙ = x ˙ 2 + λ ˙ 2 . \dot{\phi}
=
\dot{x}_2+\dot{\lambda}_2. ϕ ˙ = x ˙ 2 + λ ˙ 2 . Using
x ˙ 2 = − x 2 + u , λ ˙ 2 = − u − λ 1 + λ 2 , \begin{aligned}
\dot{x}_2&=-x_2+u,\\
\dot{\lambda}_2&=-u-\lambda_1+\lambda_2,
\end{aligned} x ˙ 2 λ ˙ 2 = − x 2 + u , = − u − λ 1 + λ 2 , we obtain
ϕ ˙ = ( − x 2 + u ) + ( − u − λ 1 + λ 2 ) = − x 2 − λ 1 + λ 2 . \begin{aligned}
\dot{\phi}
&=
(-x_2+u)
+
(-u-\lambda_1+\lambda_2)\\
&=
-x_2-\lambda_1+\lambda_2.
\end{aligned} ϕ ˙ = ( − x 2 + u ) + ( − u − λ 1 + λ 2 ) = − x 2 − λ 1 + λ 2 . On the singular arc, λ 2 = − x 2 \lambda_2=-x_2 λ 2 = − x 2 , so
ϕ ˙ = − 2 x 2 − λ 1 . \dot{\phi}
=
-2x_2-\lambda_1. ϕ ˙ = − 2 x 2 − λ 1 . Hence,
2 x 2 + λ 1 = 0. \boxed{
2x_2+\lambda_1=0.
} 2 x 2 + λ 1 = 0. Therefore,
x 2 = − λ 1 2 . x_2
=
-\frac{\lambda_1}{2}. x 2 = − 2 λ 1 . Because λ 1 \lambda_1 λ 1 is constant, x 2 x_2 x 2 is constant on the singular arc.
Determination of the Singular Control ¶ Since x 2 x_2 x 2 is constant,
x ˙ 2 = 0. \dot{x}_2=0. x ˙ 2 = 0. Using the state equation,
0 = − x 2 + u . 0=-x_2+u. 0 = − x 2 + u . Thus,
u s i n g = x 2 . \boxed{
u_{\mathrm{sing}}=x_2.
} u sing = x 2 . The boundary conditions require
x 2 ( 0 ) = 1 , x 2 ( 1 ) = 1. x_2(0)=1,
\qquad
x_2(1)=1. x 2 ( 0 ) = 1 , x 2 ( 1 ) = 1. Therefore, the constant singular state is
x 2 ( t ) = 1. x_2(t)=1. x 2 ( t ) = 1. Hence,
u ∗ ( t ) = 1 for 0 ≤ t ≤ 1. \boxed{
u^*(t)=1
\qquad
\text{for }0\leq t\leq1.
} u ∗ ( t ) = 1 for 0 ≤ t ≤ 1. Verification of the State Trajectory ¶ With u = 1 u=1 u = 1 ,
x ˙ 2 = − x 2 + 1. \dot{x}_2=-x_2+1. x ˙ 2 = − x 2 + 1. Since x 2 ( 0 ) = 1 x_2(0)=1 x 2 ( 0 ) = 1 ,
x 2 ( t ) = 1. x_2(t)=1. x 2 ( t ) = 1. Then
x ˙ 1 = x 2 = 1. \dot{x}_1=x_2=1. x ˙ 1 = x 2 = 1. With x 1 ( 0 ) = 0 x_1(0)=0 x 1 ( 0 ) = 0 ,
x 1 ( t ) = t . x_1(t)=t. x 1 ( t ) = t . Therefore,
x 1 ( 1 ) = 1 , x 2 ( 1 ) = 1. \begin{aligned}
x_1(1)&=1,\\
x_2(1)&=1.
\end{aligned} x 1 ( 1 ) x 2 ( 1 ) = 1 , = 1. All boundary conditions are satisfied.
Costate Values ¶ From
2 x 2 + λ 1 = 0 2x_2+\lambda_1=0 2 x 2 + λ 1 = 0 and x 2 = 1 x_2=1 x 2 = 1 ,
λ 1 = − 2. \boxed{
\lambda_1=-2.
} λ 1 = − 2. Since
λ 2 = − x 2 , \lambda_2=-x_2, λ 2 = − x 2 , we obtain
λ 2 = − 1. \boxed{
\lambda_2=-1.
} λ 2 = − 1. These values satisfy
λ ˙ 2 = − u − λ 1 + λ 2 = − 1 − ( − 2 ) − 1 = 0. \dot{\lambda}_2
=
-u-\lambda_1+\lambda_2
=
-1-(-2)-1
=
0. λ ˙ 2 = − u − λ 1 + λ 2 = − 1 − ( − 2 ) − 1 = 0. Hamiltonian along the Singular Arc ¶ The Hamiltonian is
H = x 2 u + λ 1 x 2 + λ 2 ( − x 2 + u ) . \mathcal{H}
=
x_2u
+
\lambda_1x_2
+
\lambda_2(-x_2+u). H = x 2 u + λ 1 x 2 + λ 2 ( − x 2 + u ) . Using
x 2 = 1 , u = 1 , λ 1 = − 2 , λ 2 = − 1 , x_2=1,\quad
u=1,\quad
\lambda_1=-2,\quad
\lambda_2=-1, x 2 = 1 , u = 1 , λ 1 = − 2 , λ 2 = − 1 , we obtain
H = 1 − 2 + 0 = − 1. \mathcal{H}
=
1-2+0
=
-1. H = 1 − 2 + 0 = − 1. Thus, the Hamiltonian is constant, as expected for an autonomous fixed-final-time problem.
Order of the Singular Arc ¶ The control does not appear explicitly in
ϕ = x 2 + λ 2 . \phi=x_2+\lambda_2. ϕ = x 2 + λ 2 . It also cancels from
The control appears when enforcing constancy of x 2 x_2 x 2 , or equivalently in the next derivative of the switching function.
Differentiate
ϕ ˙ = − 2 x 2 − λ 1 . \dot{\phi}
=
-2x_2-\lambda_1. ϕ ˙ = − 2 x 2 − λ 1 . Since λ 1 \lambda_1 λ 1 is constant,
ϕ ¨ = − 2 x ˙ 2 = − 2 ( − x 2 + u ) . \ddot{\phi}
=
-2\dot{x}_2
=
-2(-x_2+u). ϕ ¨ = − 2 x ˙ 2 = − 2 ( − x 2 + u ) . On the singular arc,
ϕ ¨ = 0 , \ddot{\phi}=0, ϕ ¨ = 0 , so
The control appears in the second derivative of the switching function.
Generalized Legendre–Clebsch Check ¶ For a minimization problem, a singular arc must satisfy an appropriate generalized Legendre–Clebsch condition.
Here,
ϕ ¨ = 2 x 2 − 2 u . \ddot{\phi}
=
2x_2-2u. ϕ ¨ = 2 x 2 − 2 u . Therefore,
∂ ϕ ¨ ∂ u = − 2. \frac{\partial \ddot{\phi}}{\partial u}
=
-2. ∂ u ∂ ϕ ¨ = − 2. Using the common sign convention for a first-order singular arc,
( − 1 ) 1 ∂ ϕ ¨ ∂ u = 2 > 0. (-1)^1
\frac{\partial \ddot{\phi}}{\partial u}
=
2>0. ( − 1 ) 1 ∂ u ∂ ϕ ¨ = 2 > 0. Thus, the singular control is consistent with local minimization.
Why Pure Bang-Bang Reasoning Is Insufficient ¶ A common error is to conclude that a Hamiltonian linear in the control always implies bang-bang control.
The correct statement is:
In this problem, the entire feasible optimal solution lies on the singular arc.
Alternative Direct Verification ¶ Because the dynamics imply
u = x ˙ 2 + x 2 , u=\dot{x}_2+x_2, u = x ˙ 2 + x 2 , the cost becomes
J = ∫ 0 1 x 2 ( x ˙ 2 + x 2 ) d t = ∫ 0 1 x 2 x ˙ 2 d t + ∫ 0 1 x 2 2 d t . \begin{aligned}
J
&=
\int_0^1
x_2(\dot{x}_2+x_2)\,\mathrm{d} t\\
&=
\int_0^1
x_2\dot{x}_2\,\mathrm{d} t
+
\int_0^1
x_2^2\,\mathrm{d} t.
\end{aligned} J = ∫ 0 1 x 2 ( x ˙ 2 + x 2 ) d t = ∫ 0 1 x 2 x ˙ 2 d t + ∫ 0 1 x 2 2 d t . The first term is
∫ 0 1 x 2 x ˙ 2 d t = 1 2 [ x 2 2 ( 1 ) − x 2 2 ( 0 ) ] = 0. \int_0^1
x_2\dot{x}_2\,\mathrm{d} t
=
\frac{1}{2}
\left[
x_2^2(1)-x_2^2(0)
\right]
=
0. ∫ 0 1 x 2 x ˙ 2 d t = 2 1 [ x 2 2 ( 1 ) − x 2 2 ( 0 ) ] = 0. Hence,
J = ∫ 0 1 x 2 2 ( t ) d t . J
=
\int_0^1x_2^2(t)\,\mathrm{d} t. J = ∫ 0 1 x 2 2 ( t ) d t . Also,
x 1 ( 1 ) − x 1 ( 0 ) = ∫ 0 1 x 2 ( t ) d t = 1. x_1(1)-x_1(0)
=
\int_0^1x_2(t)\,\mathrm{d} t
=
1. x 1 ( 1 ) − x 1 ( 0 ) = ∫ 0 1 x 2 ( t ) d t = 1. By Cauchy–Schwarz,
( ∫ 0 1 x 2 ( t ) d t ) 2 ≤ ( ∫ 0 1 1 2 d t ) ( ∫ 0 1 x 2 2 ( t ) d t ) . \left(
\int_0^1x_2(t)\,\mathrm{d} t
\right)^2
\leq
\left(
\int_0^1 1^2\,\mathrm{d} t
\right)
\left(
\int_0^1x_2^2(t)\,\mathrm{d} t
\right). ( ∫ 0 1 x 2 ( t ) d t ) 2 ≤ ( ∫ 0 1 1 2 d t ) ( ∫ 0 1 x 2 2 ( t ) d t ) . Therefore,
Equality occurs only when x 2 ( t ) x_2(t) x 2 ( t ) is constant. Since its average is one,
x 2 ( t ) = 1. x_2(t)=1. x 2 ( t ) = 1. Therefore,
This provides an independent global-optimality argument.
Optimal Cost ¶ Using
x 2 = 1 , u = 1 , x_2=1,
\qquad
u=1, x 2 = 1 , u = 1 , the optimal cost is
J ∗ = ∫ 0 1 1 d t = 1. \boxed{
J^*
=
\int_0^1 1\,\mathrm{d} t
=
1.
} J ∗ = ∫ 0 1 1 d t = 1. Numerical Verification in MATLAB ¶ function verify_session31_part2
tspan = [0 1];
x0 = [0;1];
u = @(t) 1;
dyn = @(t,x) [x(2); -x(2)+u(t)];
[t,x] = ode45(dyn,tspan,x0);
J = trapz(t,x(:,2).*arrayfun(u,t));
fprintf('x1(tf) = %.12f\n',x(end,1));
fprintf('x2(tf) = %.12f\n',x(end,2));
fprintf('J = %.12f\n',J);
figure;
plot(t,x,'LineWidth',1.5);
xlabel('Time');
ylabel('State');
legend('x_1','x_2');
grid on;
endRecommended Singular-Control Workflow ¶ Form the Hamiltonian.
Identify the switching function.
Determine the bang controls from its sign.
Test whether constant bang arcs satisfy the boundary conditions.
Set the switching function equal to zero for a singular arc.
Differentiate until the control appears explicitly.
Solve for the singular control.
Verify the control bounds.
Verify state and costate equations.
Check Hamiltonian constancy.
Verify second-order singular optimality conditions.
Common Errors ¶ assuming every affine-Hamiltonian problem is purely bang-bang;
forgetting to define the switching function;
stopping after ϕ = 0 \phi=0 ϕ = 0 without differentiating;
failing to test feasibility of constant bang arcs;
using the wrong sign in the costate equations;
failing to verify the control bounds;
failing to check terminal boundary conditions.
Summary ¶ The Hamiltonian is affine in the control.
The switching function is ϕ = x 2 + λ 2 \phi=x_2+\lambda_2 ϕ = x 2 + λ 2 .
The bang controls are u = 0 u=0 u = 0 and u = 2 u=2 u = 2 .
Neither constant bang control satisfies the terminal conditions.
A singular arc satisfies ϕ = 0 \phi=0 ϕ = 0 .
Differentiation yields x 2 = − λ 1 / 2 x_2=-\lambda_1/2 x 2 = − λ 1 /2 .
Since λ 1 \lambda_1 λ 1 is constant, x 2 x_2 x 2 is constant.
The state equation gives u = x 2 u=x_2 u = x 2 .
Boundary conditions imply x 2 = 1 x_2=1 x 2 = 1 .
Therefore, u ∗ = 1 u^*=1 u ∗ = 1 over the entire interval.
The optimal state is x 1 = t x_1=t x 1 = t , x 2 = 1 x_2=1 x 2 = 1 .
The optimal cost is J ∗ = 1 J^*=1 J ∗ = 1 .
Connection. Finally, neighboring optimal control uses local sensitivity information to correct a nominal solution without resolving the full nonlinear problem after every disturbance.