16.323 Principles of Optimal Control: Mit Opencourseware
16.323 Principles of Optimal Control: Mit Opencourseware
http://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
16.323 Lecture 5
Calculus of Variations
• Calculus of Variations
• Most books cover this material well, but Kirk Chapter 4 does a particularly nice
job.
x(t)
x*+ αδx(1) x*- αδx(1)
x*
αδx(1) −αδx(1)
t
t0 tf
subject to
ẋ = f (x, u, t)
x(t0), t0 given
m(x(tf ), tf ) = 0
– Call J(x(t), u(t)) a functional.
• Note that this definition used norms to compare two vectors. Can do
the same thing with functions ⇒ distance between two functions
d = �x2(t) − x1(t)�
where
1. �x(t)� ≥ 0 for all x(t), and �x(t)� = 0 only if x(t) = 0 for all t
in the interval of definition.
2. �ax(t)� = |a|�x(t)� for all real scalars a.
3. �x1(t) + x2(t)� ≤ �x1(t)� + �x2(t)�
Figure 5.1: Differential df versus increment Δf shown for a function, but the same
difference holds for a functional.
x(t)
x*+ αδx(1) x*- αδx(1)
x*
αδx(1) −αδx(1)
t
t0 tf
• Integrate by parts:
� �
udv ≡ uv − vdu
• Recall need δJ = 0 for all admissible δx(t), which are arbitrary within
(t0, tf ) ⇒ the (first order) necessary condition for a maximum or
minimum is called Euler Equation:
� �
∂g(x(t), ẋ(t), t) d ∂g(x(t), ẋ(t), t)
− =0
∂x dt ∂ ẋ
• Example: Find the curve that gives the shortest distance between 2
points in a plane (x0, y0) and (xf , yf ).
– Cost function – sum of differential arc lengths:
� xf � xf �
J = ds = (dx)2 + (dy)2
x0 x0
� � �2
� xf
dy
= 1+ dx
x0 dx
– Take y as dependent variable, and x as independent one
dy
→ ẏ
dx
– New form of the cost:
� xf � � xf
J= 1 + ẏ 2 dx → g(ẏ)dx
x0 x0
∂g d ∂g
− =0
∂x dt ∂ẋ
where x(t0) = x0 which are the given N boundary conditions, and
the remaining N more BC follow from:
– x(tf ) = xf if xf is given as fixed,
– If x(tf ) are free, then
∂g(x(t), ẋ(t), t)
=0
∂ẋ(tf )
• Note that we could also have a mixture, where parts of x(tf ) are given
as fixed, and other parts are free – just use the rules above on each
component of xi(tf )
� tf
J(x(t)) = g(x(t), ẋ(t), t)dt
t0
Figure 5.3: Comparison of possible changes to function at end time when tf is free.
• Substitute to get
� tf � �
d
δJ(x�(t), δx) = gx − gẋ δx(t)dt + gẋ(x�(tf ), ẋ�(tf ), tf )δxf
t0 dt
• Type 1: If tf and x(tf ) are free but unrelated, then δxf and δtf are
independent and arbitrary ⇒ their coefficients must both be zero.
d
gx(x�(t), ẋ�(t), t) − gẋ(x�(t), ẋ�(t), t) = 0
dt
g(x�(tf ), ẋ�(tf ), tf ) − gẋ(x�(tf ), ẋ�(tf ), tf )ẋ�(tf ) = 0
gẋ(x�(tf ), ẋ�(tf ), tf ) = 0
• Type 2: If tf and x(tf ) are free but related as x(tf ) = Θ(tf ), then
dΘ
δxf = (tf )δtf
dt
d
gx(x�(t), ẋ�(t), t) − gẋ(x�(t), ẋ�(t), t) = 0
dt
� �
dΘ
gẋ(x�(tf ), ẋ�(tf ), tf ) (tf ) − ẋ�(tf ) + g(x�(tf ), ẋ�(tf ), tf ) = 0
dt
given that t0 = 0, x(0) = 0, and tf and x(tf ) are free, but x(tf )
must line on the line
θ(t) = −5t + 15
• Since g(x, x,
˙ t) is only a function of x,
˙ Euler equation reduces to
ẋ�(t)
� �
d
=0
dt [1 + ẋ�(t)2]1/2
which after differentiating and simplifying, gives ẍ�(t) = 0 ⇒ answer
is a straight line
x�(t) = c1t + c0
but since x(0) = 0, then c0 = 0
c1 [tf − 5] + 1 = 0
• Now look at x�(t) and Θ(t) at tf
tf 1
x�(tf ) = − = ([tf − 5]2 − 1)
(tf − 5) 2
which gives tf = 3, c1 = 1/2 and x�(tf ) = t/2
• Goal: with t0, tf , x(t0), and x(tf ) fixed, minimize cost functional
� tf
J(x(t), t) = g(x(t), ẋ(t), t)dt
t0
• Now IBP
� t1 � �
d
δJ = gx − (gx˙ ) δxdt + g(t− − −
1 )δt1 + gẋ (t1 )δx(t1 )
t0 dt
� tf � �
d
+ gx − (gẋ) δxdt − g(t+ + +
1 )δt1 − gẋ (t1 )δx(t1 )
t1 dt
• Substitute:
� t1 � �
d
gx − (gẋ) δxdt + g(t− − −
δt1 + gẋ(t−
� �
δJ = 1 ) − g (t
ẋ 1 )ẋ(t1 ) 1 )δx1
t dt
� 0tf � �
d
gx − (gẋ) δxdt − g(t+ + +
δt1 − gẋ(t+
� �
+ 1 ) − g (t
ẋ 1 )ẋ(t 1 ) 1 )δx1
t1 dt
g(t− − − + + +
1 ) − gẋ (t1 )ẋ(t1 ) = g(t1 ) − gẋ (t1 )ẋ(t1 )
• Note that since g is only a function of ẋ, then solution x(t) will only
be linear in each segment (see 5–13)
segment 1 x(t) = a + bt
segment 2 x(t) = c + dt
– Terminal conditions: x(−2) = a − 2b = 0 and x(1) = c + d = 0
1 + 2t− −
1 ẋ(t1 ) 1 + 2t+ +
1 ẋ(t1 )
= � =�
1 + ẋ(t−1 ) 2 1 + ẋ(t+1)
2
which gives:
1 + 2bt1 1 + 2dt1
√ =
√
1+b 2 1 + d2
% x=[a b c d t1]; %
F=[x(1)-2*x(2);
x(3)+x(4);
(1+2*x(2)*x(5))/(1+x(2)^2)^(1/2) - (1+2*x(4)*x(5))/(1+x(4)^2)^(1/2);
x(1)+x(2)*x(5) - (x(5)^2+3);
x(3)+x(4)*x(5) - (x(5)^2+3)];
return %
x = fsolve(’myfunc’,[2 1 2 -2 0]’)
• On the extremal, the variation must be zero, but since δx(t) and
δp(t) can be arbitrary, can only occur if
� �
∂ga(x(t), ẋ(t), t) d ∂ga(x(t), ẋ(t), t)
− = 0
∂x dt ∂ ẋ
f (x(t), ẋ(t), t) = 0
– which are obviously a generalized version of the Euler equations
obtained before.
T
Ja(x(t), ν, t) = h(x(tf ), tf )+ν m(x(tf ), tf )+ g(x(t), ẋ(t), t)dt
t0
� tf � �
d
+ gx − gẋ δxdt
t0 dt