Вы находитесь на странице: 1из 313

A Primer on Pseudospectral Methods for

Solving Optimal Control Problems


Anil V. Rao
Gainesville, FL 32607
12 15 March 2012
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Preliminaries
This Primer consists of material that has been taken exclusively from the
following documents available in the public domain:
The Following Textbooks on Optimal Control:
Kirk, D. E., Optimal Control Theory: An Introduction, Dover Publications,
Mineola, New York, 2004.
Athans, M. A. and Falb, P. E., Optimal Control: An Introduction to the
Theory and Its Applications, Dover Publications, Mineola, New York, 2006.
Bryson, A. E. and Ho, Y-C, Applied Optimal Control, Hemisphere Publishing,
New York, 1975.
Dr. Anil V. Raos Lecture Notes from University of Florida Course EML
6934. URL: http://vdol.mae.u.edu.
Various Journal and Conference Articles on Pseudospectral Methods
Co-Authored by Dr. Anil V. Rao. URL: http://vdol.mae.u.edu.
Benson, D. A., A Gauss Pseudospectral Transcription for Optimal Control,
PhD Thesis, Department of Aeronautics and Astronautics, MIT, November
2004.
Copyright 20062012 Anil Vithala Rao Page 2
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Huntington, G. T., Advancement and Analysis of a Gauss Pseudospectral
Transcription for Optimal Control, PhD Thesis, Department of Aeronautics
and Astronautics, MIT, May 2007.
Darby, C. L., hp Pseudospectral Methods for Solving Nonlinear Optimal
Control Problems, PhD Thesis, Department of Mechanical and Aerospace
Engineering, University of Florida, April 2011.
Garg, D., Advancements in Global Pseudospectral Methods for Optimal
Control, PhD Thesis, Department of Mechanical and Aerospace Engineering,
University of Florida, June 2011.
Copyright 20062012 Anil Vithala Rao Page 3
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Course Schedule
Day 1
Part I: Calculus of Variations (1.5 Hour)
Part II: Optimal Control Theory (1.5 Hour)
Part III: Nonlinear Optimization (1.5 Hours)
Part IV: Numerical Methods for Optimal Control (1.5 Hours)
Day 2
Part V: Numerical Integration and Interplation (1 Hour)
Part VI: Foundation of Pseudospectral Methods (1 Hours)
Part VII: Implementation of a Pseudospectral Method (2 Hours)
Part VIII: Wrap-Up (1 Hour)
Copyright 20062012 Anil Vithala Rao Page 4
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Ingredients for Solving an Optimal Control Problem
Numerical Methods for
Solving Differential Equations
Constrained
Nonlinear Optimization
Systems of Nonlinear
Algebraic Equations
Direct
Methods
Indirect
Methods
Indirect Methods
First-Order Optimality Conditions of Continuous Problem Derived
Need to Solve Systems of Nonlinear Equations
Becomes a Root-Finding Problem
Direct Methods
Optimal Control Problem Approximated in an Appropriate Manner
Becomes a Nonlinear Programming Problem
Problem Solved Using Techniques from Nonlinear Optimization
Both Indirect and Direct Methods: Need to Solve Dierential Equations
Copyright 20062012 Anil Vithala Rao Page 5
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part I: Calculus of Variations
Copyright 20062012 Anil Vithala Rao Page 6
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Functions and Functionals
Denition 1
A function f(q) is a rule or correspondence that assigns to each element q D
an element f(q) R. The quantities D and R are called the domain and range
of the function, respectively.
Denition 2
A functional J(x) is a rule or correspondence that assigns to each function
x an element J(x) R. The quantity is the class of functions over which
the functional is dened and R is the set of real numbers.
Linearity of Functions
A function is said to be linear if the following property is satised p, q D
and , R:
f(p + q) = f(p) + f(q)
Copyright 20062012 Anil Vithala Rao Page 7
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Linearity of Functionals
A functional is said to be linear if the following property is satised x, y
and , R:
J(x + y) = J(x) + J(y)
Norms
The norm in R
n
is a rule or correspondence that assigns to each point q D a
real number. The norm of q, denoted q, satises the following properties
1. q 0, q D (q = 0)
2. q = 0 q = 0
3. q = ||q, R
4. p +q p +q, p, q D
Copyright 20062012 Anil Vithala Rao Page 8
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Norm of a Function
The norm of a function is a rule or correspondence that assigns to each
function x (where x is dened on t [t
0
, t
f
]) a real number. The norm of
x, denoted x, satises the following properties
1. x 0, x (x = 0)
2. x = 0 x 0 on t [t
0
, t
f
]
3. x = ||x, R
4. x +y x +y, x, y D
Increment of a Function
Let f be a function and let q, q D. Then the increment of the function
from q to q + q, denoted f, is dened as
f = f(q + q) f(q)
It is noted that f depends upon both q and q, i.e., f = f(q, q)
Copyright 20062012 Anil Vithala Rao Page 9
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Increment of a Functional
Let J be a functional and let x, x . Then the increment of the functional J
from x to x + x, denoted J, is dened as
J = J(x + x) J(x)
It is noted that J depends upon both x and x, i.e., J = J(x, x)
Dierential of a Function
The general form for the increment of a function is given as
f(q, q) = df(q, q) + g(q, q)q
The quantity df(q, q) is called the dierential of the function. The
dierential of a function is a linear operator on q, i.e.,
df(q, p + r) = df(q, p) + df(q, r)
Variation of a Functional
The general form for the increment of a functional is given as
J(x, x) = J(x, x) + g(x, x)x
Copyright 20062012 Anil Vithala Rao Page 10
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
The quantity J(x, x) is called the variation of the functional. The variation
of a functional is a linear operator on x, i.e.,
J(x, y + z) = J(x, y) + J(x, z)
Finally, the quantity x is called the variation of the function x.
Copyright 20062012 Anil Vithala Rao Page 11
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Minima and Maxima of Functions and Functionals
Denition 3
A function f with domain D is said to have a local extremum at the point q

if
> 0 such that q D such that q q

< , the increment f has the


same sign. If
f = f(q) f(q

) 0
then f(q

) is said to be a local minimum of f. If


f = f(q) f(q

) 0
then f(q

) is said to be a local maximum of f. If either condition is satised for


arbitrarily large , then f(q

) is said to be a global minimum or global


maximum.
Denition 4
A functional J with domain is said to have a local extremum at the function
x

if > 0 such that x such that x x

< , the increment J has


the same sign. If
J = J(x) J(x

) 0
Copyright 20062012 Anil Vithala Rao Page 12
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
then J(x

) is said to be a local minimum of J. If


J = J(x) J(x

) 0
then J(x

) is said to be a local maximum of J. If either condition is satised


for arbitrarily large , then J(x

) is said to be a global minimum or global


maximum.
Copyright 20062012 Anil Vithala Rao Page 13
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Basic Problem
Solve Basic Calculus of Variations Problem Using Variations
Specically, Will Take the First Variation of J, denoted J
Will Set J = 0
J =
_
t
f
t
0
L[x(t), x(t), t]dt
Question: Which Quantities Vary (and Which Do Not Vary)?
Quantities x(t) and x(t) Vary
However, t Does Not Vary Because It is a Dummy Variable of
Integration
Computation of J
J =
_
t
f
t
0
L[x(t), x(t), t]dt
Because t
0
and t
f
are Fixed, We Have
J =
_
t
f
t
0
L[x(t), x(t), t]dt
Copyright 20062012 Anil Vithala Rao Page 14
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Also, Because x(t) and x(t) Vary on t [t
0
, t
f
], We Have
L =
L
x
x +
L
x
x
We Then Obtain
J =
_
t
f
t
0
_
L
x
x +
L
x
x
_
dt
Applying Integration By Parts on Second Term,
_
t
f
t
0
L
x
xdt =
_
L
x
x
_
t
f
t
0

_
t
f
t
0
d
dt
_
L
x
_
xdt
Now Utilize the Following Information:
Initial and Terminal State is Fixed x
0
= x
f
= 0
Initial and Terminal Time is Fixed t
0
= t
f
= 0
Furthermore,
x
0
= x(t
0
) + x(t
0
)t
0
x
f
= x(t
f
) + x(t
0
)t
f
Copyright 20062012 Anil Vithala Rao Page 15
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Therefore, x(t
0
) = x(t
f
) = 0 Which Implies That
_
L
x
x
_
t
f
t
0
=
_
L
x
_
t
f
x(t
f
)
_
L
x
_
t
0
x(t
0
) = 0
Consequently, We Obtain
J =
_
t
f
t
0
_
L
x
x
d
dt
_
L
x
_
x
_
dt
Last Equation Can Be Rewritten As
J =
_
t
f
t
0
_
L
x

d
dt
_
L
x
__
xdt
Because J Must be Zero for All Variations,
L
x

d
dt
_
L
x
_
= 0 Euler-Lagrange Equation
Copyright 20062012 Anil Vithala Rao Page 16
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Calculus of Variations Example
Find an Extremal for the Functional
J[x(t)] =
_
t
f
t
0
_
x
2
(t) x
2
(t)
_
dt, x(0) = 0, x(/2) = 1
Solution: Euler-Lagrange Equation Given as
L
x

d
dt
_
L
x
_
= 2x 2 x = 0 = x + x = 0
General Solution of Dierential Equation:
x(t) = c
1
cos t + c
2
sin t
Applying Boundary Conditions, We Obtain c
0
= 0 and c
1
= 1. Therefore,
x

(t) = sin t
Copyright 20062012 Anil Vithala Rao Page 17
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
More General Calculus of Variations Problems
Starting Point for Functional Optimization
More General Problems: t
0
, t
f
, x(t
0
), and x(t
f
) May Be Free
x
0
and x
f
: Variation in Initial and Final value of x
x(t
0
) and x(t
f
): x Evaluated at Initial and Terminal time
Specically, x
0
= x(t
0
) + x(t
0
)t
0
and x
f
= x(t
f
) + x(t
f
)t
f
Copyright 20062012 Anil Vithala Rao Page 18
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Free Final Time Functional Optimization Problem
Consider Following Problem. Minimize
J[x(t)] J =
_
t
f
t
0
L[x(t), x(t), t]dt
Boundary Conditions:
t
0
= xed , t
f
= free
x(t
0
) = xed , x(t
f
) = xed
Copyright 20062012 Anil Vithala Rao Page 19
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Solution of Free Final Time COV Problem
Taking J Gives
J =
_
t
f
t
0
L[x(t), x(t), t]dt
Because t
f
is Free t
f
= 0. Therefore,
J =
J
t
f
t
f
+
_
t
f
t
0
L[x(t), x(t), t]dt
Applying the Fundamental Theorem of Calculus, We Have
J
t
f
= L[x(t
f
), x(t
f
), t
f
] =J = L[x(t
f
), x(t
f
), t
f
]t
f
+
_
t
f
t
0
L[x(t), x(t), t]dt
Already Have Term Inside Integral from Earlier. Therefore,
J = L[x(t
f
), x(t
f
), t
f
]t
f
+
_
L
x
_
t
f
x(t
f
)
_
L
x
_
t
0
x(t
0
)
+
_
t
f
t
0
_
L
x

d
dt
_
L
x
__
xdt
Copyright 20062012 Anil Vithala Rao Page 20
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Now t
0
is Fixed t
0
= 0. Therefore,
J = L[x(t
f
), x(t
f
), t
f
]t
f
+
_
L
x
_
t
f
x(t
f
)
+
_
t
f
t
0
_
L
x

d
dt
_
L
x
__
xdt
Now the Final Value of x is Fixed. Therefore, x
f
= 0 Which Implies That
x
f
= x(t
f
) + x(t
f
)t
f
= 0 =x(t
f
) = x(t
f
)t
f
Therefore,
J = L[x(t
f
), x(t
f
), t
f
]t
f

_
L
x
_
t
f
x(t
f
)t
f
+
_
t
f
t
0
_
L
x

d
dt
_
L
x
__
xdt
Copyright 20062012 Anil Vithala Rao Page 21
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Combining Terms, We Obtain
J =
_
L[x(t
f
), x(t
f
), t
f
]
_
L
x
_
t
f
x(t
f
)
_
t
f
+
_
t
f
t
0
_
L
x

d
dt
_
L
x
__
xdt
Now, Because x and t
f
are Independent, We have
L[x(t
f
), x(t
f
), t
f
]
_
L
x
_
t
f
x(t
f
) = 0
L
x

d
dt
_
L
x
_
= 0
Copyright 20062012 Anil Vithala Rao Page 22
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example with Free Final Time
Minimize
J[x(t)] =
_
t
f
1
_
2x(t) +
1
2
x
2
(t)
_
dt, x(1) = 4, x(t
f
) = 4. t
f
> 1
Solution:
Euler-Lagrange Equation: x = 2 =x(t) = t
2
+ c
1
t + c
2
Boundary Condition 2x(t
f
)
1
2
x
2
(t
f
) = 0
Applying Boundary Condition Gives
x(1) = 4 = 1 + c
1
+ c
2
=c
1
+ c
2
= 3
2x(t
f
)
1
2
x
2
(t
f
) = 2(t
2
f
+ c
1
t
f
+ c
2
) + 2t
f
+ c
1
= 0
Final Solution
x

(t) = t
2
6t + 9
t
f
= 5
Copyright 20062012 Anil Vithala Rao Page 23
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Free Final Endpoint Functional Optimization Problem
Consider Following Problem. Minimize
J[x(t)] J =
_
t
f
t
0
L[x(t), x(t), t]dt
Boundary Conditions
t
0
= xed , t
f
= xed
x(t
0
) = xed , x(t
f
) = free
Copyright 20062012 Anil Vithala Rao Page 24
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Minimization of Functionals of Vector Functions
In General, Functionals May be Functions of Vector Functions
Functional of a Vector Function: Let x(t) R
n
,
x(t) =
_
_
_
_
_
_
_
_
x
1
(t)
x
2
(t)
.
.
.
x
n
(t)
_

_
Functional of x(t)
J[x(t)] =
_
t
f
t
0
L[x(t), x(t), t]dt
Extremization of Functional of Vector Function
J =
_
t
f
t
0
L[x(t), x(t), t]dt = 0
Solved in a Manner Analogous to Function Optimization
Copyright 20062012 Anil Vithala Rao Page 25
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Assume That t
0
, t
f
, x(t
0
), and x(t
f
) Are Fixed
=J =
_
t
f
t
0
L[x(t), x(t), t]dt = 0
Consequently,
J =
_
t
f
t
0
_
_
L
x
_
T
x +
_
L
x
_
T
x
_
dt
Integrating Second Term of Integrand By Parts Gives
J =
_
_
L
x
_
T
x
_
t
f
t
0
+
_
t
f
t
0
_
_
L
x
_
T

d
dt
_
L
x
_
T
_
xdt
Applying Boundary Conditions x(t
0
) = x(t
f
) = 0. Therefore,
L
x

d
dt
_
L
x
_
= 0 =Vector Euler-Lagrange Equation
In Scalar Form
L
x
i

d
dt
_
L
x
i
_
= 0, (i = 1, . . . , n)
Extremization of More General Functionals Proceeds in Analogous Manner
Copyright 20062012 Anil Vithala Rao Page 26
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Summary
Calculus of Variations
Foundation for Functional Optimization
Deals with Continuous-Time (Innite-Dimensional) Problem
Candidate Optimal Solutions are Called Extremals
Determination of an Extremal Solution
Compute First Variation of Cost Functional
Set All Independent Terms in Variation to Zero
Importance of Calculus of Variations
Foundation for Optimal Control Theory
Optimal Control Problem: Application of Variational Calculus
Copyright 20062012 Anil Vithala Rao Page 27
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part II: Optimal Control Theory
Copyright 20062012 Anil Vithala Rao Page 28
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
General Optimal Control Problem
Determine x(t), u(t), and p that Minimize the Cost Functional
J = (x(t
f
), t
f
, p) +
_
t
f
t
0
L[x(t), u(t), p, t]dt
Subject to the Dynamic Constraint
x = f (x, u, p, t)
The Boundary Conditions
(x(t
0
), t
0
, x(t
f
), t
f
, p) = 0
And the Path Constraints
C
min
C(x(t), u(t), p) C
max
Copyright 20062012 Anil Vithala Rao Page 29
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Key Features of Optimal Control Problem
Functional Minimization Problem
x(t) and u(t) are Functions of Time
J is a Function of Functions x(t) & u(t) J is a Functional
Optimal Control Problems are Constrained
Constraints: Dierential Equations, Boundary Conditions, & Path
Need to Solve a Constrained Functional Minimization Problem
Broad Classes of Optimal Control Problems
Free and Fixed Terminal Times
Free Terminal State (Initial-Value Problem)
Constrained Terminal State (Boundary-Value Problem)
Path Constrained and Path Unconstrained
Copyright 20062012 Anil Vithala Rao Page 30
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Conventions Used in Derivation
Let f : R
n
R. The Gradient and Hessian of f are Dened As
f
x
=
_
f
x
1
f
x
2

f
x
n
_

2
f
x
2
=
_
_
_
_
_
_
_
_
_
_
_

2
f
x
2
1

2
f
x
2
x
1


2
f
x
n
x
1

2
f
x
1
x
2

2
f
x
2
2


2
f
x
n
x
1
.
.
.
.
.
.
.
.
.
.
.
.

2
f
x
1
x
n

2
f
x
2
x
n


2
f
x
2
n
_

_
Using Conventions,We Have

2
f
x
2
=

x
_
f
x
_
T
Let f : R
n
R
m
. Then the Jacobian of f (x) is an mn matrix, i.e.,
f
x
=
_
f
x
1
f
x
2

f
x
n
_
R
mn
Copyright 20062012 Anil Vithala Rao Page 31
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Optimal Control Problem without Path Constraints
Construct Augmented Cost Functional
J
a
=
T
+
_
t
f
t
0
_
L +
T
(f x)
_
dt
where
(t) = Costate
= Lagrange Multiplier of Boundary Condition
Make Following Assumptions (For Now)
Initial and Terminal Times are Free
Control is Unconstrained
No Path Constraints
Copyright 20062012 Anil Vithala Rao Page 32
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
First-Order Optimality Conditions
Augmented Cost Functional
J
a
=
T
+
_
t
f
t
0
_
L +
T
(f x)
_
dt
Terminology
: Lagrange Multiplier of Boundary Condition
: Costate or Adjoint of Dierential Equation
Dene
H = L +
T
f = H(x, , u)
The Quantity H is called the Hamiltonian
In Terms of the Hamiltonian We Have
J
a
=
T
+
_
t
f
t
0
_
H
T
x
_
dt
First Variation of Augmented Cost Functional
J
a
=
_

T
+
_
t
f
t
0
_
H
T
x
_
dt
_
Copyright 20062012 Anil Vithala Rao Page 33
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
which gives
J
a
=
T

T
+
_
t
f
t
0
_
H
T
x
_
dt
Now We Have
=

x(t
0
)
x(t
0
) +
_

x(t
0
)
x(t
0
) +

t
0
_
t
0
+

x(t
f
)
x(t
f
) +
_

x(t
f
)
x(t
f
) +

t
f
_
t
f
Combining Terms, We Have
=

x(t
0
)
[x(t
0
) + x(t
0
)t
0
] +

t
0
t
0
+

x(t
f
)
[x(t
f
) + x(t
f
)t
f
] +

t
f
t
f
Copyright 20062012 Anil Vithala Rao Page 34
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Terminology
x
0
, x
f
= Variations in Initial and Terminal State
x(t
0
), x(t
f
) = Variations in State at Initial
and Terminal Times
Note That x(t
0
) = x
0
and x(t
f
) = x
f
Relationships Between x
0
, x
f
and x(t
0
), x(t
f
)
x
0
= x(t
0
) + x(t
0
)t
0
x
f
= x(t
f
) + x(t
f
)t
f
In Terms of x
0
and x
f
, We Obtain
=

x(t
0
)
x
0
+

t
0
t
0
+

x(t
f
)
x
f
+

t
f
t
f
Copyright 20062012 Anil Vithala Rao Page 35
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
In a Similar Manner, We Have for That
=

x(t
0
)
x
0
+

t
0
t
0
+

x(t
f
)
x
f
+

t
f
t
f
Next, We Have

_
t
f
t
0
_
H
T
x
_
dt =
_
t
f
t
0
_
H
T
x
T
x
_
dt
+
_
H
T
x
_
t
f
t
f

_
H
T
x
_
t
0
t
0
Where
H =
_
H
x
_
x +
_
H

_
+
_
H
u
_
u
Copyright 20062012 Anil Vithala Rao Page 36
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
And, via Integration by Parts, We Have
_
t
f
t
0

T
xdt =
_

T
x
_
t
f
t
0

_
t
f
t
0

T
xdt
Important Note:
Terms Outside Integral are evaluated at t
0
and t
f
Consequently, We Have x(t
0
) and x(t
f
)
Therefore,

_
t
f
t
0
_
H
T
x
_
dt =
T
(t
0
)x(t
0
)
T
(t
f
)x(t
f
)
+
_
H(t
f
)
T
(t
f
) x(t
f
)
_
t
f

_
H(t
0
)
T
(t
0
) x(t
0
)
_
t
0
+
_
t
f
t
0
__
H
x
_
x +
_
H

_
+
_
H
u
_
u
_
dt

_
t
f
t
0
_

T
x +

T
x
_
dt
Copyright 20062012 Anil Vithala Rao Page 37
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Using the Earlier Results for x(t
0
) and x(t
f
),

_
t
f
t
0
_
H
T
x
_
dt
=
T
(t
0
) [x
0
x(t
0
)t
0
]
T
(t
f
) [x
f
x(t
f
)t
f
]
+
_
H(t
f
)
T
(t
f
) x(t
f
)
_
t
f

_
H(t
0
)
T
(t
0
) x(t
0
)
_
t
0
+
_
t
f
t
0
__
H
x
_
x +
_
H

_
+
_
H
u
_
u
_
dt

_
t
f
t
0
_

T
x +

T
x
_
dt
Rearranging Gives

_
t
f
t
0
_
H
T
x
_
dt =
T
(t
0
)x
0

T
(t
f
)x
f
+H(t
f
)t
f
H(t
0
)t
0
+
_
t
f
t
0
__
H
x
+

T
_
x +
_
H

x
T
_

+
H
u
u
_
dt
Copyright 20062012 Anil Vithala Rao Page 38
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Terms Outside Integral
Terms involving :
= 0 or (x(t
0
), t
0
, x(t
f
), t
f
) = 0
Terms involving x
0
and x
f
:
x
0
= 0 or (t
0
) =
_

x(t
0
)
_
T
+
_

x(t
0
)
_
T

x
f
= 0 or (t
f
) =
_

x(t
f
)
_
T

_

x(t
f
)
_
T

Terms involving t
0
and t
f
:
t
0
= 0 or H(t
0
) =

t
0

T

t
0
t
f
= 0 or H(t
f
) =

t
f
+
T

t
f
Copyright 20062012 Anil Vithala Rao Page 39
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Terms Inside Integral (i.e., x, u, and ):
H
x
+

T
= 0
H

x
T
= 0
H
u
= 0
Rearranging These Last Three Equations, We Obtain
x =
_
H

_
T
= f (x(t), u(t), t) State Dynamics

=
_
H
x
_
T
Costate Dynamics
_
H
u
_
T
= 0 Condition for Optimal Control
Copyright 20062012 Anil Vithala Rao Page 40
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Necessary Conditions and Extremals
Double-Boxed Terms Are Necessary Conditions
Let (x

(t),

(t), u

(t)) Satisfy Necessary Conditions


(x

(t),

(t)) is an extremal trajectory


u

(t) is an extremal control


Important Notes About Extremal Solutions
Only candidate optimal solutions
Each Extremal May Be Either
Minimum
Maximum
Saddle
Copyright 20062012 Anil Vithala Rao Page 41
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Understanding Structure of Optimality Conditions
Dynamics of Augmented System
x = H

(x, )

= H
x
(x, )
Vector Field (H

, H
x
) R
2n
is a Hamiltonian System
Time Derivative of Hamiltonian
dH
dt
=
H
t
+
_
H
x
_
T
dx
dt
+
_
H

_
T
d
dt
=
H
t
+
_
H
x
_
T
_
H

_
H

_
T
_
H
x
_
=
H
t
+H
T
x
H

H
T

H
x
But
H
T
x
H

H
T

H
x
= 0
Therefore,
dH
dt
=
H
t
Copyright 20062012 Anil Vithala Rao Page 42
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Important Properties of Hamiltonian
Total Time Derivative = Partial Derivative With Respect to Time
If Hamiltonian not an explicit function of time
=
H
t
= 0
dH
dt
= 0 H = constant
If Hamiltonian not an explicit function of time and t
f
is free
H(t
f
) =

t
f
+
T

t
f
= 0 H = 0
Copyright 20062012 Anil Vithala Rao Page 43
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example
Cost Functional
J =
1
2
_
t
f
0
(qx
2
+ ru
2
)dt
where x(t) R, u R and q > 0 and r > 0 are constants
Dynamic Constraints
x = ax + bu
where a and b are constants
Boundary Conditions
x(0) = x
0
x(t
f
) = x
f
where x
0
and x
f
are given values
Copyright 20062012 Anil Vithala Rao Page 44
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Solution to Example
Form the Hamiltonian
H = L + f =
1
2
qx
2
+
1
2
ru
2
+ (ax + bu)
State and Costate Dynamics
x = H

= ax + bu

= H
x
= qx a
Optimal Control
H
u
= ru + b = 0 u

=
b
r

Substitution of Optimal Control into State Dynamics


x = ax
b
2
r

State-Costate Dynamics Including Condition for Optimal Control
_
_
x

_
_
=
_
_
a
b
2
r
q a
_
_
_
_
x

_
_
Copyright 20062012 Anil Vithala Rao Page 45
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Transversality Conditions
=
_
_
x(0) x
0
x(t
f
) x
f
_
_
=
_
_

2
_
_
Therefore,

x(0)
=
_
_
1
0
_
_

x(t
f
)
=
_
_
0
1
_
_
We Then Obtain
(0) =
1
= Unknown
(t
f
) =
2
= Unknown
Note: Neither ((0), (t
f
)) nor (
1
,
2
) is Known
= Determining Determining
Copyright 20062012 Anil Vithala Rao Page 46
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Hamiltonian Boundary-Value Problem for Example
State-Costate Dynamics and Boundary Conditions
_
_
x

_
_
=
_
_
a
b
2
r
q a
_
_
_
_
x

_
_
,
_
_
x(0) = x
0
x(t
f
) = x
f
_
_
(0) and (t
f
) are unknown
General Form of Dynamics: Linear Time-Invariant (LTI) System
p = Ap
General Solution of First-Order LTI System
p(t) = c
1
e

1
t
w
1
+ c
2
e

2
t
w
2
where
p =
_
_
x

_
_

1
,
2
= Eigenvalues of A
w
1
, w
2
= Eigenvectors of A
Copyright 20062012 Anil Vithala Rao Page 47
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Determination of Solution to HBVP
Eigenvalues of System Matrix A
det [I A] = det
_
_
a
b
2
r
q + a
_
_
=
2
a
2

qb
2
r
= 0
Assuming That q > 0 and r > 0, We Obtain
=
_
a
2
+
qb
2
r
Note: Eigenvalues Have Same Magnitude But Opposite Sign
Let =
_
a
2
+
qb
2
r
= =
Eigenvectors of A
Eigenvector for =
_
_
a
b
2
r
q a + a
_
_
_
_
w
11
w
12
_
_
=
_
_
0
0
_
_
Copyright 20062012 Anil Vithala Rao Page 48
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
From rst equation we have
( a)w
11
+
b
2
r
w
12
= 0
Let w
11
= 1/( a). We then have
w
12
=
r
b
2
This gives
w
1
=
_
_
1/( a)
r/b
2
_
_
Eigenvector for =
_
_
a
b
2
r
q + a
_
_
_
_
w
21
w
22
_
_
=
_
_
0
0
_
_
From the rst equation we have
( + a)w
21
+
b
2
r
w
22
= 0
Let w
21
= 1/( + a). We then obtain
w
22
=
r
b
2
Copyright 20062012 Anil Vithala Rao Page 49
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Which implies that
w
2
=
_
_
1/( + a)
r/b
2
_
_
Solving for Constants c
1
and c
2
At t = 0 we have
x(0) = x
0
= c
1
w
11
+ c
2
w
21
=
c
1
a
+
c
2
+ a
At t = t
f
we have
x(t
f
) = x
f
= c
1
e
t
f
w
11
+ c
2
e
t
f
w
21
=
c
1
e
t
f
a
+
c
2
e
t
f
+ a
Solving last two equations for c
1
and c
2
gives
_
_
c
1
c
2
_
_
=
1
e
t
f
e
t
f
_
_
e
t
f
( a) ( a)
e
t
f
( + a) ( + a)
_
_
_
_
x
0
x
f
_
_
Solution for a = b = q = r = 1, t
0
= 0, x(t
0
) = 1, t
f
= (1, 5, 10, 15, 20), and
x(t
f
) = 2
Copyright 20062012 Anil Vithala Rao Page 50
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
0 5 10 15 20
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2


t
x
(
t
)
t
f
= 1
t
f
= 5
t
f
= 10
t
f
= 15
t
f
= 20
Copyright 20062012 Anil Vithala Rao Page 51
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
0 5 10 15 20
1
0.5
0
0.5
1
1.5
2
2.5


t

(
t
)
t
f
= 1
t
f
= 5
t
f
= 10
t
f
= 15
t
f
= 20
Observations of Solution Structure
For small t
f
, solution
Exhibits no decay
Moves essentially directly from initial to terminal condition
Copyright 20062012 Anil Vithala Rao Page 52
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
For large t
f
, solution
Appears to have a three-segment structure
First segment: decay from initial condition to zero
Second segment: remains very close to zero
Third segment: rapid growth to meet terminal condition
Key points
Both state and costate have decaying and growing behavior
Growth and decay show up as t
f
increases
Copyright 20062012 Anil Vithala Rao Page 53
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example: Orbit-Raising Problem
Problem: determine the thrust direction as a function of time that transfers a
spacecraft from Earth orbit to Mars orbit in minimum time (Reference: Bryson
and Ho, Applied Optimal Control, Hemisphere Publishing, New York, 1975).
Copyright 20062012 Anil Vithala Rao Page 54
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Dynamics in First-Order Form
r = u
u =
v
2
r


r
2
+
T
m
sin
v =
uv
r
+
T
m
cos
m =
T
g
0
I
sp
Astronomical System of Units (AU) Chosen Such That = 1 and Distance
of Sun to Earth is Unity
Boundary Conditions
Initial conditions: circular orbit of size 1 AU (i.e., Earth orbit)
r(0) = r
0
= 1 AU
u(0) = 0
v(0) =
_
/r
0
= 1 AU/TU
m(0) = 1
Copyright 20062012 Anil Vithala Rao Page 55
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Terminal conditions: circular orbit of size 1.5 AU (i.e., Mars orbit)
r(t
f
) = r
f
= 1.5 AU
u(t
f
) = 0
v(t
f
) =
_
/r
f
0.816496581 AU/TU
Objective Functional: Minimize Time
J =
Mayer Form

t
f
=
Lagrange Form

_
t
f
0
dt
We will use Mayer form of cost functional
Hamiltonian (Observe that L 0 and = t
f
)
H = L +
T
f =
r
r +
u
u +
v
v +
m
m
=
r
u +
u
_
v
2
r


r
2
+
T
m
sin
_
+
v
_

uv
r
+
T
m
cos
_
+
m
_

T
g
0
I
sp
_
Copyright 20062012 Anil Vithala Rao Page 56
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Costate Equations

r
=
H
r
=
u
_
v
2
r
2

2
r
3
_

v
uv
r
2

u
=
H
u
=
r
+
v
v
r

v
=
H
v
=
u
2v
r
+
v
u
r

m
=
H
m
=
u
_
T
m
2
sin
_
+
v
_
T
m
2
cos
_
Condition for Optimal Control
H

= 0 =
u
T
m
cos
v
T
m
sin = 0
Solving for Gives

= tan
1
(
u
,
v
)
Note: A four-quadrant inverse tangent is used because [, ]
Transversality Conditions
Copyright 20062012 Anil Vithala Rao Page 57
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
The boundary conditions can be written in the general form
(x(t
0
), t
0
, x(t
f
), t
f
) =
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
r(t
0
) r
0
u(t
0
)
v(t
0
)
_
/r
0
m(t
0
) m
0
r(t
f
) r
f
u(t
f
)
v(t
f
)
_
/r
f
_

_
= 0
Copyright 20062012 Anil Vithala Rao Page 58
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Let
T
= (
r0
,
u0
,
v0
,
m0
,
rf
,
uf
,
vf
)

x(t
0
)
=
_

r(t
0
)

u(t
0
)

v(t
0
)

m(t
0
)
_
=
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
0 0 0 0
0 0 0 0
0 0 0 0
_

_
Copyright 20062012 Anil Vithala Rao Page 59
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage

x(t
f
)
=
_

r(t
f
)

u(t
f
)

v(t
f
)

m(t
f
)
_
=
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1 0 0 0
0 1 0 0
0 0 1 0
_

_
Initial transversality conditions
(0) =

x(t
0
)
+
_

x(t
0
)
_
T

_
_
_
_
_
_
_

r
(0)

u
(0)

v
(0)

m
(0)
_

_
=
_
_
_
_
_
_
_

r0

u0

v0

m0
_

_
Copyright 20062012 Anil Vithala Rao Page 60
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Terminal transversality conditions
(t
f
) =

x(t
0
)

_

x(t
f
)
_
T

_
_
_
_
_
_
_

r
(t
f
)

u
(t
f
)

v
(t
f
)

m
(t
f
)
_

_
=
_
_
_
_
_
_
_

rf

uf

vf
0
_

_
Notes
Only one of the boundary costates is known
Seven unknown boundary conditions
One Last Important Point: H/ = 0 is Only a Necessary Condition
Sucient condition:
2
H/
2
> 0

2
H

2
=
u
T
m
sin
v
T
m
cos > 0
=
u
sin
v
cos > 0 =tan >

u
Therefore,

v
>

u
=
2
u
+
2
v
> 0
Copyright 20062012 Anil Vithala Rao Page 61
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Hamiltonian Boundary-Value Problem for Orbit-Transfer Problem
Dynamics (

= tan
1
(
u
,
v
)):
r = u , u =
v
2
r


r
2
+
T
m
sin

v =
uv
r
+
T
m
cos

, m =
T
g
0
I
sp

r
=
u
_
v
2
r
2

2
r
3
_

v
uv
r
2
,

u
=
r
+
v
v
r

v
=
u
2v
r
+
v
u
r
,

m
=
u
_
T
m
2
sin

_
+
v
_
T
m
2
cos

_
Boundary Conditions:
r(t
0
) = r
0
, u(t
0
) = 0 , v(t
0
) =
_
/r
0
, m(t
0
) = m
0
,
r(t
f
) = r
f
, u(t
f
) = 0 , v(t
f
) =
_
/r
f
,
m
(t
f
) = 0
Notes:
Initial and Terminal Conditions are Incomplete
Half of the initial conditions and terminal conditions are specied
Copyright 20062012 Anil Vithala Rao Page 62
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
The Minimum Principle of Pontryagin
In General, the Optimal Control Satises the Condition
J(u) J(u

) 0
for all u suciently close to u

Therefore J(u) = J(u

) + J(u

, u)
Then, from Variation of Augmented Cost Functional
J(u

, u) =
_
t
f
t
0
_
H
u
_
u

udt
Term in Integrand Given As
_
H
u
_
u

u = H(x

, u

+ u,

) H(x

, u

) + higher order terms


Consequently, to First Order
J(u

, u) =
_
t
f
t
0
[H(x

, u

+ u,

) H(x

, u

)] dt 0
Copyright 20062012 Anil Vithala Rao Page 63
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Because J(u

, u) > for All Admissible Variations in u,


H(x

, u

) H(x

, u

+ u,

)
Leads to Following Condition for Optimal Control
u

= arg min
uU
H(x

, u,

), U = Admissible Control Set


Possibilities for Determining Optimal Control
Control Lies Interior to U
H
u
= 0 =Strong Form of Minimum Principle
Control Lies on Boundary of U
One-sided dierential must use weak form of minimum principle
u

= arg min
uU
H(x

, u,

) Weak Form of Minimum Principle


Example: Hamiltonian linear in control
H = L(x) +
T
f (x) +
T
u
H/u provides no information about u
Must use weak form of minimum principle
Copyright 20062012 Anil Vithala Rao Page 64
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example: Minimum-Time Double Integrator
Consider the Following Optimal Control Problem. Minimize
J = t
f
=
_
t
f
0
dt
Subject to
x
1
= x
2
x
2
= u
with
x
1
(0) = x
10
, x
1
(t
f
) = 0
x
2
(0) = x
20
, x
2
(t
f
) = 0
and
|u| 1 1 u 1
Problem in Words
Determine the optimal trajectory and control that steers the system from
an initial nonzero state to the origin in minimum time.
Copyright 20062012 Anil Vithala Rao Page 65
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Solution of Double Integrator Minimum Time Example
Hamiltonian (Using Lagrange Form of Problem)
H = 1 +
1
x
2
+
2
u
Optimal Control
H/u gives no information
Need to apply general form of minimum principle
u

= arg min
u[1,1]
H = sgn
2
= 1
where sgn() is the sign or signum function
Costate Equations

1
= H/x
1
= 0 =
1
(t) = constant =
10

2
= H/x
2
=
1
=
2
(t) =
10
t +
20
Observation:
2
(t) is a Straight Line
Four Possibilities for
2
(t) (Depending on Sign of
10
)
Copyright 20062012 Anil Vithala Rao Page 66
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage

2
(t) is always positive

2
(t) is always negative

2
(t) switches from positive to negative

2
(t) switches from negative to positive
Copyright 20062012 Anil Vithala Rao Page 67
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
0 0.5 1 1.5
2
1
0
1
2


0 0.5 1 1.5
2
1
0
1
2


0 0.5 1 1.5
2
1
0
1
2


0 0.5 1 1.5
2
1
0
1
2

1
(t)

1
(t)

1
(t)
1
(t)

2
(
t
)

2
(
t
)

2
(
t
)

2
(
t
)
u(t)
u(t)
u(t) u(t)
t t
t t

1
0,
2
0
1
0,
2
0

1
> 0,
2
> 0
1
< 0,
2
< 0
Four Possible Optimal Controls: {1} , {+1} , {1, +1} , {+1, 11}
Copyright 20062012 Anil Vithala Rao Page 68
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Suppose we let s = 1. Then we have
x
2
(t) = st + x
20
x
1
(t) =
1
2
st
2
+ x
20
t + x
10
We can then eliminate t from above equations to obtain
x
1
= x
10
+
1
2
sx
2
2

1
2
sx
2
20
t = s(x
2
x
20
)
Copyright 20062012 Anil Vithala Rao Page 69
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
3 2 1 0 1 2 3
2
1.5
1
0.5
0
0.5
1
1.5
2


x
1
x
2
s = 1
s = 1
Important Notes
Control must steer initial state to origin
Copyright 20062012 Anil Vithala Rao Page 70
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
As a result, the extremal solution must include one of the parabolas
that pass through the origin
Structure of Optimal Solution
Case 1: Follow thick green curve into origin: u = 1
Case 2: Follow thick blue curve into origin: u = +1
Case 3: start on a green curve and switch to thick blue curve: u = 1
followed by u = +1
Case 4: start on a blue curve and switch to thick green curve: u = 1
followed by u = 1
Form of optimal control; bang-bang
u

is never on the interior of admissible control set


u

is always at its minimum or maximum value


Physical Example: Liquid Rocket Thruster: T [0, T
max
]
Copyright 20062012 Anil Vithala Rao Page 71
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Singular Arcs
Recall the Minimum Principle of Pontryagin
H(x

, u

) H(x

, u,

)
Suppose Now that There Exists an Interval [t
1
, t
2
] Such That
u

(t) cannot be determined from Minimum Principle


Then [t
1
, t
2
] is called a singular interval or singular arc
In General, Singular Intervals are Dicult to Detect
Certain Classes of Problems: Singular Problems May Be Solvable
Hamiltonian not an explicit function of time H

is constant
Can use conditions on H

to assist with singular arc detection


Copyright 20062012 Anil Vithala Rao Page 72
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Determination of Singular Arc Conditions
Consider a Problem where H

is constant
Let [t
1
, t
2
] be an Interval Such That
Optimal control cannot be determined from necessary conditions
Auxiliary conditions must be used to determine u

(t) on [t
1
, t
2
]
Approach for Determining Singular Arc Conditions
Dierentiate H with respect to time q times until control appears
Because H

is constant, we know that


d
(q)
H
dt
(q)
= 0
Furthermore, dH
(q)
/dt
(q)
is an explicit function of control
Thus, dH
(q)
/dt
(q)
can be used to solve for control on [t
1
, t
2
]
Copyright 20062012 Anil Vithala Rao Page 73
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Singular Arc Example: Goddard Rocket Problem
Maximize h(t
f
) Subject to
Dynamics

h(t) = v
v(t) =
T(t)D(v,h)
m
g
m(t) =
T(t)
c
Boundary Conditions
h(0) = 0
v(0) = 0
m(0) = m
0
= given
h(t
f
) = Free
v(t
f
) = Free
m(t
f
) = m
f
= Given
Control constraint: 0 T(t) T
max
Copyright 20062012 Anil Vithala Rao Page 74
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Goddard Rocket Problem (Continued)
Hamiltonian
H =
h
v +
v
_
T D
m
g
_

m
T
c
=
h
v +
_

v
m


m
c
_
T
v
_
D
m
+ g
_
Key Issue
Optimal control may not be bang-bang
Reason: depends upon sign of
v
/m
m
/c
Possibilities
T

(t) =
_

_
0 ,
v
/m
m
/c > 0
0 T

(t) T
max
,
v
/m
m
/c = 0
T
max
,
v
/m
m
/c < 0
Suppose that
v
/m
m
/c = 0 = Singular Arc
Copyright 20062012 Anil Vithala Rao Page 75
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Goddard Rocket Problem (Continued)
H Does Not Depend Explicitly on t =H

is constant
All Time Derivatives of H

are Zero
In This Case, on Singular Arc We Have

v
m


m
c
= 0 =c
v
m
m
= 0
Can Let I =
v
/m
m
/c
Dierentiate I with Respect to t Until Control Appears
This Problem: Control Appears in

I and We Know

I

= 0
The Condition

I

= 0
Enables determining the control on the singular arc
Gives a feedback law for optimal control on singular arc
Copyright 20062012 Anil Vithala Rao Page 76
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Summary
Optimal Control Theory Founded on Calculus of Variations
Using This Approach, Must Formulate
First-Order Optimality Conditions of Continuous Problem
Leads to a Hamiltonian Boundary-Value Problem
Determination of Optimal Control
If Control is Interior to Feasible Control Set: H
u
= 0
If Control Lies on Boundary of Control Set
u

= arg min
uU
H(x

, u

, t

)
Even in Numerical Methods, Optimal Control Theory Important
Provides Systematic Means of Formulating Problem
Enables Analysis of Solution
Later: Will Discuss Solution Methods for HBVP
Copyright 20062012 Anil Vithala Rao Page 77
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part III: Nonlinear Optimization
Copyright 20062012 Anil Vithala Rao Page 78
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Preliminaries
A scalar is any real number, i.e., x is a scalar if x R where R is the set of
real numbers
A column vector x lies in n-dimensional real space, i.e., x is a column
vector if x R
n
and is dened as
x =
_
_
_
_
_
_
_
_
x
1
x
2
.
.
.
x
n
_

_
A row vector lies in n-dimensional real space, i.e., y is a row vector if
y R
n
and is dened as
y = [
y
1
y
2
y
n
] (y
1
, y
2
, . . . , y
n
)
Copyright 20062012 Anil Vithala Rao Page 79
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
A matrix A R
mn
is dened as
A =
_
_
_
_
_
_
_
_
a
11
a
12
a
1n
a
21
a
22
a
2n
.
.
.
.
.
.
.
.
.
.
.
.
a
m1
a
m2
a
mn
_

_
The Transpose of a Matrix A R
mn
, Denoted A
T
, is Dened as
A
T
=
_
_
_
_
_
_
_
_
a
11
a
12
a
1m
a
21
a
22
a
2m
.
.
.
.
.
.
.
.
.
.
.
.
a
n1
a
m2
a
nm
_

_
Column Vectors and Row Vectors related by a transpose, i.e.,
x is a column vector x
T
is a row vector
Conventions Used for Vector Functions
The notation R
m
R
n
means mapping from R
m
to R
n
.
Copyright 20062012 Anil Vithala Rao Page 80
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Let F : R
n
R. Then the gradient of F is a column vector and is
dened as
G(x)
F
x
=
_
F
x
1
F
x
2

F
x
n
_
Let f : R
n
R
m
be a function that maps vectors from R
n
to R
m
. Then
h(x) is a column vector dened as
f (x) =
_
_
_
_
_
_
_
_
f
1
(x)
f
2
(x)
.
.
.
f
m
(x)
_

_
where f
i
(x) f
i
(x
1
, . . . , x
n
), i = 1, . . . , m.
The Jacobian matrix or Jacobian of f (x), dened as J(x) R
mn
,
J(x)
f
x
=
_
f
x
1
f
x
2

f
x
n
_
Copyright 20062012 Anil Vithala Rao Page 81
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
where f /x
j
, (j = 1, . . . , n) are m-dimensional column vectors, i.e.,
f
x
j
=
_
_
_
_
_
_
_
_
f
1
x
j
f
2
x
j
.
.
.
f
n
x
j
_

_
In terms of f
1
(x), . . . , f
m
(x) and x
1
, . . . , x
n
the Jacobian can be written as
J(x) =
_
_
_
_
_
_
_
_
f
1
x
1
f
1
x
2

f
1
x
n
f
2
x
1
f
2
x
2

f
2
x
n
.
.
.
.
.
.
.
.
.
.
.
.
f
m
x
1
f
m
x
2

f
m
x
n
_

_
R
mn
Using These Conventions, for the special case of a function F : R
n
R,
the gradient and Jacobian of F are dened, respectively, as
G(x) =
F
x

x
F
J(x) =
G
x


2
F
x
2
H(x) =
2
x
F
Copyright 20062012 Anil Vithala Rao Page 82
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
where the function H(x) has a special name called the Hessian of F. The
Hessian of F is written explicitly in terms of the gradient as
H(x) =
_
G
x
1
G
x
2

G
x
n
_
or, alternatively, in terms of F as
H(x) =
_
_
_
_
_
_
_
_

2
F
x
2
1

2
F
x
2
x
1


2
F
x
n
x
1

2
F
x
1
x
2

2
F
x
2
2


2
F
x
n
x
2
.
.
.
.
.
.
.
.
.
.
.
.

2
F
x
1
x
n

2
F
x
2
x
n


2
F
x
2
n
_

_
R
nn
It is noted that the Hessian is symmetric.
Important Notes: Using the above conventions, the Hessian is derivative
of the transpose of the gradient, i.e.,
H(x) =

x
_
G
T
(x)
_
The Hessian matrix H(x) is symmetric, i.e., H = H
T
Abbreviated Notation for Gradient, Jacobian, and Hessian
Copyright 20062012 Anil Vithala Rao Page 83
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Gradient of a Scalar Function F(x):
G(x)
F
x
F
x
Hessian of a Scalar Function F(x):
H(x)

2
F
x
2
F
xx
Jacobian of a Vector Function f (x):
J(x)
f
x
f
x
Copyright 20062012 Anil Vithala Rao Page 84
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Unconstrained Optimization
Let F : R
n
R. Then x

is called a strong minimum of F if there exists


R such that
F(x

) < F(x

+ x)
for all 0 < x < . Similarly, x

is called a weak minimum of F if x

is not a strong minimum and there exists R such that


F(x

) F(x

+ x)
0 < x < .
Global vs. Local Minimum
x

is said to be a global minimum of F if = .


x

is said to be a local minimum of F if < .


In general, a scalar function F(x) will have many local minima of which
one of them may be a global minimum.
Copyright 20062012 Anil Vithala Rao Page 85
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Necessary & Sucient Conditions for a Local Minimum
Assume F(x) is Twice Dierentiable in a Neighborhood of x

, We Have
F(x

) F(x

+ x) +
_
F
x
_
x

x +
1
2
x
T
_

2
F
x
2
_
x

x
= F(x

+ x) +G
T
(x

)x +
1
2
x
T
H(x)x
x

is said to be a stationary point of F(x) if


G(x

) = 0
Necessary Conditions
G(x

) = 0, i.e., x

must be a stationary point of F


H(x

) 0, (i.e., H(x

) is positive semi-denite)
Sucient Conditions
G(x

) = 0, i.e., x

must be a stationary point of F


H(x

) > 0, (i.e., H(x

) > 0, is positive denite)


Copyright 20062012 Anil Vithala Rao Page 86
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Solution of Unconstrained Optimization Problems
What Needs to Be Done
Determine stationary points from G(x): give candidate local minima
Check deniteness of H(x) at all stationary points
Accept all stationary points where H is either PD or PSD
Reject all stationary points where H is neither PD nor PSD
Above Mathematical Approach Nice in Theory
General Problem
No analytic solution
Need to solve numerically
Numerical methods are generally iterative
Categories of numerical methods for unconstrained optimization
Univariate (functions of a single variable) problems
Multivariate (functions of many variables) problems
Copyright 20062012 Anil Vithala Rao Page 87
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Univariate Optimization
Consider the following problem where x R:
min
xR
F(x)
Necessary & sucient conditions for a minimum are
F

(x) =
dF
dx
= 0 , F

(x) =
d
2
F
dx
2
> 0
Complicated F: Need to Employ an Iterative Method
First Step: Bracket the Minimum
Know values of F at x
1
, x
2
, and x
3
Condition: F(x
2
) < F(x
1
) and F(x
2
) < F(x
3
)
Copyright 20062012 Anil Vithala Rao Page 88
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
x
x
1
x
2
x
3
F(x)
Take an Additional Point x
4
x
x
1
x
2
x
3
x
4
F(x)
Then
F(x
4
) < F(x
2
) New Interval: (x
1
, x
4
, x
2
)
F(x
4
) > F(x
2
) New Interval: (x
4
, x
2
, x
3
)
Question: How Do We Choose x
4
?
Copyright 20062012 Anil Vithala Rao Page 89
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Commonly Used Methods
Golden section
Polynomial approximation
Copyright 20062012 Anil Vithala Rao Page 90
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Golden Section Search
Let L = x
3
x
1
and =
x
2
x
1
x
3
x
2
, i.e.,
=
x
2
x
1
x
3
x
2
=
_
_
_
x
2
x
1
=
L
1+
x
3
x
2
=
L
1+
1
x
x
1
x
2
x
3
L
L
1+
L
1+

Goal: Maximize Reduction in Bracket at Each Step


Choose x
4
To Be in Larger Interval
Copyright 20062012 Anil Vithala Rao Page 91
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
1
x
x
1
x
2
x
3
x
4
L
L
1+
L
1+

Want New Interval to Have Same Ratio as Original Interval


1
1
x
x
1
x
2
x
3
x
4
L
L
1+
L
1+

L
2
(1+)
2
L
(1+)
2
Copyright 20062012 Anil Vithala Rao Page 92
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Therefore,
x
2
x
4
=
1
1 +
L
1 +
=
L
(1 + )
2
Want x
2
x
1
to equal x
3
x
4
Which Implies That
x
2
x
1
x
3
x
4
=
L
1 +
Using the constraint that x
2
x
1
= x
3
x
4
, we obtain
L = x
3
x
1
= x
4
x
1
+ x
3
x
4
=
L
2
(1 + )
2
+
L
1 +
Rearranging, we obtain
(1 + )
2
= (1 + ) +
2
=
2
1 = 0
Roots of Polynomial:

1,2
=
1

5
2
Because Must Be Greater Than Unity (and Positive),
=
1 +

5
2
= Golden Ratio
Copyright 20062012 Anil Vithala Rao Page 93
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Algorithm 1 (Golden Section)
1. Given Interval (x
1
, x
2
, x
3
) Where F(x
2
) < F(x
1
) and F(x
2
) < F(x
3
)
2. Choose x
4
To Be in Large Part of Interval Such That Ratio of Large Part
of Interval is
3. Find F(x
4
)
4. If F(x
4
) > F(x
2
), New Interval is (x
1
, x
2
, x
4
), Otherwise New Interval is
(x
2
, x
4
, x
3
)
5. Assign New Interval = (x
1
, x
2
, x
3
)
6. Tolerance met? Yes Stop; Otherwise Step 2
Copyright 20062012 Anil Vithala Rao Page 94
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Polynomial Line Search
Key Attributes of Golden Section
No assumptions were made about function
Very robust, but has slow (linear) convergence
Would like a method with faster convergence
Faster Convergence: Quadratic Approximation to F
Approach: Assume F(x) is Well-Behaved
Start with three points x
1
, x
2
, and x
3
Fit quadratic through these points, i.e.,
p(x) = a(x b)
2
+ c
x
4
obtained where p(x) is minimized (i.e., x = b)
After some algebra, it turns out that
b =
1
2
F(x
1
)(x
2
3
x
2
2
) + F(x
2
)(x
2
1
x
2
3
) + F(x
3
)(x
2
2
x
2
1
)
F(x
1
)(x
3
x
2
) + F(x
2
)(x
3
x
1
) + F(x
3
)(x
2
x
1
)
Benets of Quadratic Line Search
Copyright 20062012 Anil Vithala Rao Page 95
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Much faster convergence than golden section
Near minimum: superlinear convergence
Caution: no such thing as a free lunch
Quadratic line search can fail
May need to use a less aggressive approach
Polynomial Line Search Can Be of Any Order
For N
th
-degree approximation, need N + 1 points
Generally only need to go as high as a cubic
Algorithm for Quadratic Line Search
Algorithm 2 (Quadratic Line Search)
1. Given Interval (x
1
, x
2
, x
3
) Where F(x
2
) < F(x
1
) and F(x
2
) < F(x
3
)
2. Approximate F by a Quadratic p(x) Using x
1
, x
2
, and x
3
3. Determine x
4
from Minimum of p(x)
4. If F(x
4
) > F(x
2
), New Interval is (x
1
, x
2
, x
4
), Otherwise New Interval is
(x
2
, x
4
, x
3
)
Copyright 20062012 Anil Vithala Rao Page 96
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
5. Assign New Interval = (x
1
, x
2
, x
3
)
6. Tolerance met? Yes Stop; Otherwise Step 2
Copyright 20062012 Anil Vithala Rao Page 97
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Multivariate Unconstrained Optimization
Supply an initial guess of x

, i.e., x
0
Perform an update at each step k as follows:
x
k+1
= x
k
+
k
D
k
p
k
where p
k
is the search direction,
k
is the step length and is
determined via a line search, and D
k
R
nn
is a positive denite matrix.
Algorithm 3 (Unconstrained Minimization)
1. Set k = 0 and choose initial guess, x
k
= x
2. Test for convergence: G(x
k
) = 0 and H(x
k
) > 0 ?
3. If answer to step (2) is yes, then quit
4. Otherwise, compute
(a) search direction, p
k
(b) step length,
k
(c) Positive denite matrix, D
k
Copyright 20062012 Anil Vithala Rao Page 98
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
5. Update x
k
as
x
k+1
= x
k
+
k
D
k
p
k
6. Return to step (2)
Copyright 20062012 Anil Vithala Rao Page 99
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Methods for Determination of p
k
,
k
, and D
k
Determination of p
k
and D
k
First-order methods
Use gradient information
Common method: steepest descent
Second-order methods
Use both gradient and Hessian information
Common method: Newton method
Quasi-Newton methods
Use an approximation to Hessian
Common methods: DFP and BFGS
Methods for Determination of Step Length,
k
Step Length Determined from Univariate Optimization Methods
Exact Line Search
Inexact Line Search
Copyright 20062012 Anil Vithala Rao Page 100
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Method of Steepest Descent
Want a Search Direction that Decreases Value of F at Each Step
Perform a Taylor Series Expansion About x
k
F(x
k+1
) F(x
k
) +G
T
(x
k
)(x
k+1
x
k
)
= F(x
k
) +G
T
k
(
k
D
k
p
k
)
This last result implies that
x
k+1
x
k
=
k
D
k
p
k
Now assume that
k
> 0 and is chosen such that the function F decreases
in moving from x
k
to x
k+1
, i.e., F(x
k+1
) < F(x
k
). Then it must be the
case that
G
T
k
D
k
p
k
< 0
Suppose We Choose p
k
= G
k
and D
K
= I. Then
x
k+1
x
k
=
k
G
k
=x
k+1
= x
k

k
G
k
The Direction p
k
= G
k
is Called the Direction of Steepest Descent
Copyright 20062012 Anil Vithala Rao Page 101
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Newton Method
Suppose at Each Step we Choose x
k+1
Such That
G(x
k+1
) = 0
Then
G(x
k+1
) G(x
k
) +
_
G
x
_
x
k
(x
k+1
x
k
) = 0
But We Know That
_
G
x
_
x
k
= H(x
k
)
Solving for x
k+1
, we obtain the Newton Method
x
k+1
= x
k
H
1
(x
k
)G(x
k
)
Therefore, for a Newton Method,
D
k
= H
1
(x
k
) ; p
k
= G(x
k
) ;
k
= 1
Copyright 20062012 Anil Vithala Rao Page 102
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Comparison Between Steepest Descent & Newton Iteration
Steepest Descent
Simple Iterative Approach: Uses Only First-Derivatives
Slow (Linear) Convergence, But Very Reliable
Newton Method
More Sophisticated: Uses Second-Derivatives
Much Faster Convergence (Quadratic)
Not As Reliable
H May Not Remain Positive Denite
Known to Diverge Depending Upon Initial Guess
Want an Iterative Procedure with Fast Convergence and Reliability
Common Balanced Approach: Quasi-Newton Methods
Copyright 20062012 Anil Vithala Rao Page 103
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Quasi-Newton Methods
Denition of a Quasi-Newton Method
x
k+1
= x
k

k
D
k
G
k
where D
k
is an approximation to the inverse of the Hessian at each step
Key Idea: Approximate Convexity (i.e., Second Derivative)
Does Not Require Computation the Hessian of F
Requires Only Information Functions and Gradients
Construct Quasi-Newton Approximation to H
Consider two successive iterates x
k
and x
k+1
We know that
G(x
k+1
) G(x
k
) +H
k
(x
k+1
x
k
)
=G(x
k+1
) G(x
k
) H
k
(x
k+1
x
k
)
G
k+1
G
k
H
k
(x
k+1
x
k
)
Copyright 20062012 Anil Vithala Rao Page 104
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Suppose now that we let
q
k
= G
k+1
G
k
Then, using the fact that p
k
= x
k+1
x
k
, we have
p
T
k
H
k
p
k
(G
k+1
G
k
)
T
p
k
= q
T
k
p
k
It is noted that p
T
k
H
k
p
k
is an approximation to the curvature of F
along p
k
.
Approximation to Hessian Constructed Using Information from
Previous Iterations
Suppose Now That We Have B
k
, where B
k
is an Approximation to H
k
At Step k + 1, B
k
Updated Using Update Matrix U
k
As
B
k+1
= B
k
+U
k
B
k+1
must satisfy the Quasi-Newton condition
B
k+1
p
k
= q
k
Copyright 20062012 Anil Vithala Rao Page 105
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Assume now that U
k
= vw
T
. Then
B
k+1
p
k
= (B
k
+vw
T
)p
k
= q
k
=v(w
T
p
k
) = q
k
B
k
p
k
Can Be Shown That
B
k+1
= B
k
+
1
w
T
p
k
(q
k
B
k
p
k
) w
T
Well-Known Quasi-Newton Update Algorithms
Davidon-Fletcher-Powell (DFP)
B
k+1
= B
k

B
k
p
k
p
T
k
B
k
p
T
k
B
k
p
k
+
q
k
q
T
k
q
T
k
p
k
+
_
p
T
k
B
k
p
T
k
_
y
k
y
T
k
where
y
k
=
q
k
q
T
k
p
k

B
k
p
k
p
T
k
B
k
q
k
Broyden-Fletcher-Goldfarb-Shanno (BFGS)
B
k+1
= B
k

B
k
p
k
p
T
k
B
K
p
T
k
B
k
p
k
+
q
k
q
T
k
q
T
k
p
k
Copyright 20062012 Anil Vithala Rao Page 106
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Using the Quasi-Newton Approximation to the Inverse of the Hessian (B
k
),
x
k+1
= x
k
+
k
B
k
p
k
Important Points About Quasi-Newton Updates
B
0
Positive Denite B
k
Remains Positive Denite
B
0
Generally Taken As Identity Matrix
Copyright 20062012 Anil Vithala Rao Page 107
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Line Search
What is the Best Value of
k
?
Obtain
k
from Solution of Minimization Problem
min

k
0
F(x
k
+
k
p
k
)
Solution of Line Search Minimization Problem
Optimal value of
k
: exact line search
Suboptimal value of
k
: inexact line search
Reasons to employ inexact line search
Exact line searches are inecient and add little to increase rate of
convergence
Inexact line searches are fast and ecient
Commonly Used Inexact Line Search Methods
Golden Section
Bisection
Polynomial Approximations
Copyright 20062012 Anil Vithala Rao Page 108
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Important Points About Line Search
A line search is a univariate optimization problem
Line searches satisfy Goldstein-Armijo condition:
0
1

k
F

(0) F(0) F(
k
)
2

k
F

(0)
Copyright 20062012 Anil Vithala Rao Page 109
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Trust Region Methods
Pose the Following Constrained Optimization Problem:
min
p
G
T
k
p +
1
2
p
T
H
k
p subject to p
T
p <
Idea: is a Trust-Radius
Property: for R The Solution p of
(H
K
+ I)p = G
k
Solves the problem if either
= 0 and p
T
p
or
0 and p
T
p =
Properties of Trust Region Methods
Suciently large Newton method
0 and p 0 p Approaches Steepest Descent Direction
Copyright 20062012 Anil Vithala Rao Page 110
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example of Unconstrained Optimization
Quartic Unconstrained Minimization Problem:
min
x
1
,x
2
F(x
1
, x
2
)
where
F(x
1
, x
2
) = 100(x
1
x
2
2
)
2
+ (1 x
1
)
2
Necessary Conditions for Optimality
F
x
1
= 200(x
1
x
2
2
) 2(1 x
1
) = 0
F
x
2
= 400x
2
(x
1
x
2
2
) = 0
Stationary Points
(x
1
, x
2
) = (101, 0)
(x
1
, x
2
) = (1, 1)
Hessian of F
H =
_
_
200 400x
2
400x
2
1200x
2
2
_
_
Copyright 20062012 Anil Vithala Rao Page 111
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Check Deniteness of H at Each Stationary Point
H(x
1
= 101, x
2
= 0) =
_
_
200 0
0 0
_
_
0
H(x
1
= 1, x
2
= 1) =
_
_
200 400
400 1200
_
_
> 0
= Optimal solution is (x
1
, x
2
) = (1, 1)
Copyright 20062012 Anil Vithala Rao Page 112
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Solution of Example Via Iteration
Use Various Iterative Approaches to Solve Example
MATLAB: can use fminunc (Code on Next Slides)
Three dierent Hessian updates: steepest descent, DFP, and BFGS
Need to set tolerances on x and F: Choose 10
5
Results
Copyright 20062012 Anil Vithala Rao Page 113
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
0 100 200 300 400 500
0
0.5
1
1.5
2
2.5
3
3.5
Iterations
L
2

N
o
r
m

E
r
r
o
r


Steepest Descent
DFP
BFGS
Copyright 20062012 Anil Vithala Rao Page 114
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
FMINUNC Code for Quartic Example Problem
global xpath iters;
xpath = zeros(10000,2);
iters = 0;
xlow = -Inf*ones(2,1);
xupp = Inf*ones(2,1);
opt = optimset(fminunc);
opt = optimset(opt,Hessupdate,steepdesc,gradobj,on,Display, ...
iter,LargeScale,off,InitialHessType,identity, ...
tolfun,1e-5,tolx,1e-5,MaxFunEvals,100000,MaxIter, ...
10000,OutputFcn,@quartic_outfun);
x0 = [-1.9 2];
xout_gradsearch = fminunc(@quartic_usrfun,x0,opt);
xpath_gradsearch = xpath(1:iters,:);
xpath = zeros(10000,2);
iters = 0;
opt = optimset(fminunc);
opt = optimset(opt,Hessupdate,bfgs,gradobj,on,Display, ...
iter,LargeScale,off,InitialHessType,identity, ...
tolfun,1e-5,tolx,1e-5,MaxFunEvals,100000,OutputFcn,@ ...
quartic_outfun);
xout_bfgssearch = fminunc(@quartic_usrfun,x0,opt);
xpath_bfgssearch = xpath(1:iters,:);
xpath = zeros(10000,2);
iters = 0;
opt = optimset(fminunc);
opt = optimset(opt,Hessupdate,dfp,gradobj,on,Display, ...
iter,LargeScale,off,InitialHessType,identity, ...
tolfun,1e-5,tolx,1e-5,MaxFunEvals,100000,OutputFcn,@ ...
quartic_outfun);
xout_dfpsearch = fminunc(@quartic_usrfun,x0,opt);
Copyright 20062012 Anil Vithala Rao Page 115
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
xpath_dfpsearch = xpath(1:iters,:);
x_ex = [1 1];
x_exact = [ones(length(xpath_gradsearch),1) ones(length(xpath_gradsearch),1)];
err_grad = xpath_gradsearch-x_exact;
err_grad = sqrt(dot(err_grad,err_grad,2));
x_exact = [ones(length(xpath_bfgssearch),1) ones(length(xpath_bfgssearch),1)];
err_bfgs = xpath_bfgssearch-x_exact;
err_bfgs = sqrt(dot(err_bfgs,err_bfgs,2));
x_exact = [ones(length(xpath_dfpsearch),1) ones(length(xpath_dfpsearch),1)];
err_dfp = xpath_dfpsearch-x_exact;
err_dfp = sqrt(dot(err_dfp,err_dfp,2));
figure(1);
hh1=plot(xpath_gradsearch(:,1),xpath_gradsearch(:,2),o);
hold on;
hh2=plot(x_ex(1),x_ex(2),d);
set(hh2,MarkerSize,12,MarkerFaceColor,Black);
print -depsc2 quartic_iterations.eps;
figure(2);
hh1=plot(xpath_bfgssearch(:,1),xpath_bfgssearch(:,2),x);
hold on;
hh2=plot(x_ex(1),x_ex(2),d);
set(hh2,MarkerSize,12,MarkerFaceColor,Black);
figure(3);
hh1=plot(xpath_dfpsearch(:,1),xpath_dfpsearch(:,2),x);
hold on;
hh2=plot(x_ex(1),x_ex(2),d);
set(hh2,MarkerSize,12,MarkerFaceColor,Black);
figure(4);
iters_grad =length(err_grad);
iters_bfgs =length(err_bfgs);
iters_dfp =length(err_dfp);
n_grad = 1:iters_grad;
Copyright 20062012 Anil Vithala Rao Page 116
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
n_bfgs = 1:iters_bfgs;
n_dfp = 1;iters_dfp;
hh=plot(n_grad,err_grad,-x,n_bfgs,err_bfgs,-o,n_dfp,err_dfp,-^);
set(hh,LineWidth,1.5);
grid on;
xl=xlabel(Iterations);
yl=ylabel(L_2-Norm Error);
ll=legend(Steepest Descent,DFP,BFGS);
set(xl,FontName,Times,FontSize,16);
set(yl,FontName,Times,FontSize,16);
set(ll,FontName,Times,FontSize,16);
% Quartic Objective Function
function [F,G] = quartic_usrfun(x);
if size(x,1)==2,
x=x;
end;
F = 100*(x(:,2)-x(:,1).^2).^2+(1-x(:,1)).^2;
G = [100*(4*x(1)^3-4*x(1)*x(2))+2*x(1)-2; 100*(2*x(2)-2*x(1)^2)];
return;
% Quartic Output Function
function stop = quartic_outfun(x,optimValues,state,varargin)
global xpath iters;
stop=[];
persistent history
persistent searchdir
hold on
switch state
case init
history = []; searchdir = [];
case iter
% Concatenate current point and objective function value
% with history. x must be a row vector.
history = [history;[x optimValues.fval]];
% Concatenate current search direction with searchdir.
Copyright 20062012 Anil Vithala Rao Page 117
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
searchdir = [searchdir; optimValues.searchdirection];
plot(x(1),x(2),o);
% Label points with iteration number.
text(x(1)+.15,x(2),num2str(optimValues.iteration));
iters = iters+1;
xpath(iters,:) = x;
case done
assignin(base,hist, history);
assignin(base,search, searchdir);
otherwise
end
hold off
return;
Copyright 20062012 Anil Vithala Rao Page 118
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Constrained Optimization
Most Optimization Problems are Constrained
Dierent Types of Constraints
Equality: constraints are active at optimal solution
Inequality: constraints may be either active or inactive at optimal
solution
General form of constrained optimization problem:
min
x
F(x)
s.t.
g(x) = 0
h(x) 0
where g : R
n
R
m
and h : R
n
R
p
Above Optimization Problem is Called a Nonlinear Programming Problem
(NLP)
Copyright 20062012 Anil Vithala Rao Page 119
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Following Discussion
Nonlinear equality-constrained problem (NEP)
Nonlinear inequality-constrained problem (NIP)
Copyright 20062012 Anil Vithala Rao Page 120
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Equality Constraints
Nonlinear Equality-Constrained Problem (NEP)
min
x
F(x)
s.t.
g(x) = 0
Lagrangian Function
L(x, ) = F(x) +
m

i=1

i
g
i
(x)
Dene the following quantities:
Jacobian of the constraints as
A(x) =
g
x
R
mn
Hessian of the constraints, dened as

H
i
(x) =

2
g
i
x
2
R
nn
, (i = 1, . . . , m)
Copyright 20062012 Anil Vithala Rao Page 121
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
where A
i
(x) is the i
th
column of A(x)
A matrix Z(x) such that
Z(x

) R
nm
=Z
T
R
mn
where the columns of Z(x

) form a basis for the set of vectors


orthogonal to the rows of A(x

)
The Hessian of Lagrangian: W(x, ) = H(x)

m
i=1

i

H
i
R
nn
Theorem 1 (Necessary Conditions for NEP)
1. g(x

) = 0
2. Z
T
(x

)G(x

) = 0 G(x

) = A
T
(x

3. Z
T
(x

)W(x

)Z(x

) 0 (i.e., PSD)
Theorem 2 (Sucient Conditions for NEP)
1. g(x

) = 0
2. Z
T
(x

)G(x

) = 0 G(x

) = A
T
(x

3. Z
T
(x

)W(x

)Z(x

) > 0
Copyright 20062012 Anil Vithala Rao Page 122
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Inequality Constraints
Nonlinear Inequality-Constrained Problem (NIP)
min
x
F(x)
s.t.
g(x) = 0
h(x) 0
Lagrangian Function
L(x, ) = F(x) +
m

i=1

i
g
i
(x) +
p

i=1

i
h
i
(x)
Dene the following quantities at optimal solution:
q = number of active constraints
a(x

) = vector of all active constraints


= vector of Lagrange multipliers corresponding to a(x

)
Furthermore, dene the following quantities:
Copyright 20062012 Anil Vithala Rao Page 123
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Jacobian of the active constraints as
A(x) =
a
x
R
qn
Hessian of the active constraints,

H
i
(x) =

2
a
i
x
2
R
nn
, (i = 1, . . . , q)
where A
i
(x) is the i
th
column of A(x)
A matrix Z(x) such that
Z(x

) R
nq
=Z
T
R
qn
where the columns of Z(x

) form a basis for the set of vectors orthogonal to


the rows of A(x

)
The Hessian of the Lagrangian Function
W(x, ) = H(x)
m

i=1

i

H
i
R
nn
Associate the Following Two Sets with the Inequality Constraints
A(x) = {j | h
j
(x) = 0}
A

(x) = {j | h
j
(x) < 0}
Copyright 20062012 Anil Vithala Rao Page 124
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Theorem 3 (Necessary Conditions for NIP)
1. g(x

) = 0 and h(x

) 0
2. Z
T
(x

)G(x

) = 0 G(x

) = A
T
(x

3.

i
0
4. Z
T
(x

W(x

)Z(x

) 0
Theorem 4 (Sucient Conditions for NIP)
1. g(x

) = 0 and h(x

) 0
2. Z
T
(x

)G(x

) = 0 G(x

) = A
T
(x

3.

i
0
4. Z
T
(x

W(x

)Z(x

) > 0
Copyright 20062012 Anil Vithala Rao Page 125
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Numerical Solution of General NLP
General NLP Must Be Solved Numerically
Commonly Used Approaches for Solving NLPs
Sequential Quadratic Programming (SQP)
Approximate Lagrangian as a quadratic
Linearize Constraints
Make progress to optimal solution based on a merit function
Interior Point (Barrier)
Equality Constraints Enforced Using Quadratic Penalty Term
Inequality Constraints Managed via a Barrier Function
Sequence of Problems Solved Using Homotopy Parameter
Notation
x: Optimization Variables
: Lagrange Multipliers of equality Constraints
: Lagrange Multipliers of inequality Constraints
Copyright 20062012 Anil Vithala Rao Page 126
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Sequential Quadratic Programming (SQP)
Choose an initial guess (x., )
Approximate L by a Quadratic, i.e.,
L(x, , ) g
T
p +
1
2
p
T
Hp
Linearize Constraints
_
g
x
_
x
k
p
k
= g
k
_
h
x
_
x
k
p
k
h
k
Equations Form a Quadratic Program (QP)
QP Solved to Determine
Search direction, p
Estimates of active constraints and Lagrange multipliers
Globalization Strategy: Use a Merit Function
Used to maintain progress toward optimal solution
Copyright 20062012 Anil Vithala Rao Page 127
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
At optimal solution, merit function = cost function
Types of merit functions
Penalty functions
Barrier functions
Copyright 20062012 Anil Vithala Rao Page 128
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Penalty Functions
Let
c(x) =
_
_
g(x)
h(x)
_
_
Penalty Function:
P(x, ) = F(x) +

2
c
T
(x)c(x)
where is a penalty parameter.
Algorithm 4 (Penalty Function Method)
1. If x
k
satises the optimality conditions, then terminate.
2. Using the current iterate x
k
, solve the unconstrained subproblem
min
xR
n
P(x,
k
)
3. Set
k+1
>
k
, increment counter k k + 1, and return to step 1
Can be shown that
lim

() = x

Copyright 20062012 Anil Vithala Rao Page 129


May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Penalty Function Method (Continued)
Issues with Standard Penalty Function
As Unconstrained Problem Becomes Dicult to Solve
Need to Overcome Ill-Conditioning
Augmented Lagrangian Penalty Function
P(x) = L(x, , ) +

2
c
T
(x)c(x)
= F(x)
T
c(x) +

2
c
T
(x)c(x)
Improvements of Augmented Lagrangian Penalty Function
Avoids Ill-Conditioning of Penalty Function
Converges for Finite Value of
However, Choosing reasonable Value of is Dicult
Copyright 20062012 Anil Vithala Rao Page 130
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Barrier Function Method
Quadratic Penalty Functions
Generate Infeasible Iterates
Inappropriate When Necessary to Maintain Feasibility
Solution: Use a Feasible-Point Method
Barrier Method is Such an Approach
Idea of a Barrier Function
Choose a Function that Prevents Infeasibilities
Common to Choose a Logarithmic Barrier Function, i.e.,
B(x, r) = F(x) r
m

i=1
ln c
i
(x)
where r is the Barrier parameter
Can Be Shown That
lim
r0
x

(r) = x

Copyright 20062012 Anil Vithala Rao Page 131


May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Well-Known NLP Solvers
NPSOL
Dense NLP Solver
Good for Problem Up To A Few Hundred Variables
SNOPT
Sparse NLP Solver: Uses SQP Quasi-Newton Method
Capable of Solving Problems with Thousands of Variables & Constraints
IPOPT
Also a Sparse NLP Solver: Uses a Barrier Method
Capable of Using Either Quasi-Newton or Newton Method
Capable of Solving Problems with Thousands of Variables & Constraints
Will Show Examples Using SNOPT and IPOPT
Copyright 20062012 Anil Vithala Rao Page 132
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example Using SNOPT
Consider the Following Optimization Problem
minimize F(x) = (x
1
x
2
)
2
+ (x
2
x
3
)
3
+ (x
3
x
4
)
4
+ (x
4
x
5
)
4
subject to
x
3
+ x
4
+ x
5
3
x
1
+ x
2
2
+ x
3
3
= 3
x
1
+ x
2
1
x
2
x
2
3
+ x
4
= 1
x
1
x
5
= 1
Constraint Jacobian and Objective Function Sparsity Pattern
Copyright 20062012 Anil Vithala Rao Page 133
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
1 2 3 4 5
1 0 0 1 1 1
2 1 1 1 0 0
3 1 1 0 0 0
4 0 1 1 1 0
5 1 0 0 0 1
6 1 1 1 1 1
Observations
12 Out of 30 Derivatives Are Zero
Percentage of Nonzeros = 18/30 = 60%
Can Take Advantage of Sparsity in SNOPT
Problem Solved More Eciently Using Sparse Linear Algebra
Copyright 20062012 Anil Vithala Rao Page 134
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Code for SNOPT Example
Main Function Code
function [x,F,xmul,Fmul,INFO] = hsmain()
snprint(hsmain.out);
hsmain.spc = which(hsmain.spc);
snspec (hsmain.spc);
snseti(Major Iteration limit, 250);
[x,xlow,xupp,xmul,xstate,Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow, ...
A,iAfun,jAvar,iGfun,jGvar] = snoptExampleData;
[x,F,xmul,Fmul,INFO]= snsolve( x, xlow, xupp, xmul, xstate, ...
Flow, Fupp, Fmul, Fstate, ...
ObjAdd, ObjRow, A, iAfun, jAvar,...
iGfun, jGvar, snoptExampleFun);
snprint off; % Closes the file and empties the print buffer
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [x,xlow,xupp,xmul,xstate,Flow,Fupp,Fmul,Fstate,ObjAdd,ObjRow, ...
A,iAfun,jAvar,iGfun,jGvar] = snoptexampledata()
neF = 6; % Number of Functions (Including Objective Function)
n = 5; % Number of Variables
Obj = 6; % Objective Function Row
ObjRow = 6; % Objective Function Row
% Assign the Sparsity Pattern for the Non-Constant Elements
% Column
Copyright 20062012 Anil Vithala Rao Page 135
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
% | 1 2 3 4 5
% +----------------------
% 1 |
% 2 | 6 7
% 3 |
% 4 | 8
% 5 | 9 10
% row 6 | 1 2 3 4 5 Objective row
%
G = [ Obj, 1;
Obj, 2;
Obj, 3;
Obj, 4;
Obj, 5;
2, 2;
2, 3;
4, 3;
5, 1;
5, 5 ];
iGfun = G(:,1); jGvar = G(:,2);
% Assign the Sparsity Pattern for the Constant Derivatives
% Column
% | 1 2 3 4 5
% +----------------------
% 1 | 4 5 6
% 2 | 1
% 3 | 7 8
% 4 | 2 3
% 5 |
% row 6 | Objective row
%
A = [ 2, 1, 1;
4, 2, 1;
4, 4, 1;
1, 3, 1;
Copyright 20062012 Anil Vithala Rao Page 136
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
1, 4, 1;
1, 5, 1;
3, 1, 1;
3, 2, 1 ];
iAfun = A(:,1); jAvar = A(:,2); A = A(:,3);
ObjAdd = 0;
% Initial Guess of Solution
x = [ 2;
sqrt(2) - 1 ;
sqrt(2) - 1 ;
2;
0.5 ];
% Set Lower and Upper Bounda on Variables and Constraints
xlow = -Inf*ones(n,1);
xupp = Inf*ones(n,1);
xstate = zeros(n,1);
xmul = zeros(n,1);
Flow = -Inf*ones(neF,1);
Fupp = Inf*ones(neF,1);
Flow(1) = 3;
Flow(2) = 3;
Fupp(2) = 3;
Flow(3) = 1;
Flow(4) = 1;
Fupp(4) = 1;
Flow(5) = 1;
Fupp(5) = 1;
Fmul = zeros(neF,1);
Fstate = zeros(neF,1);
Copyright 20062012 Anil Vithala Rao Page 137
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Code to Compute Functions
function [F,G] = snoptExampleFun(x)
% Computes the Functions for the SNOPT Example
% Part 1: Define the Nonlinear Part of Functions and Derivatives for SNOPT Example
F = [ 0;
x(2)*x(2) + x(3)*x(3)*x(3);
0;
-x(3)*x(3);
x(1)*x(5);
(x(1)-x(2))^2 + (x(2)-x(3))^3 + (x(3)-x(4))^4 + (x(4)-x(5))^4 ];
% Part 2: Compute Derivatives of Functions
Obj = 6; % Objective Function is the 6th Row
G = [ Obj, 1, 2*(x(1)-x(2));
Obj, 2, 3*(x(2)-x(3))^2 - 2*(x(1)-x(2));
Obj, 3, 4*(x(3)-x(4))^3 - 3*(x(2)-x(3))^2;
Obj, 4, 4*(x(4)-x(5))^3 - 4*(x(3)-x(4))^3;
Obj, 5, -4*(x(4)-x(5))^3;
2, 2, 2* x(2);
2, 3, 3* x(3)^2;
4, 3, -2* x(3);
5, 1, x(5);
5, 5, x(1) ];
G = G(:,3);
Copyright 20062012 Anil Vithala Rao Page 138
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example Using IPOPT
Consider the Following Optimization Problem
minimize x
3
+ x
1
x
4
3

i=1
x
i
subject to the constraints
x
i
1, (i = 1, . . . , 4)
x
i
5, (i = 1, . . . , 4)
x
1
x
2
x
3
x
4
25

4
i=1
x
2
i
= 40
To Use IPOPT in Newton Mode, Must Supply
Objective Function, Gradient, Constraints, and Jacobian
Hessian of NLP Lagrangian
Sparsity Pattern for Jacobian and Hessian
This Example: Will Show How to Supply These Functions in IPOPT
Copyright 20062012 Anil Vithala Rao Page 139
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Code for IPOPT Example
function [x, info] = exampleipopt
% Test IPOPT Problem Using Matlab Interface
% Reference: Hock and Schittowski (1981), Test Examples for
% Nonlinear Programming Codes. Lecture Nodes in Economics and
% Mathematical Systems, Vol. 187, Springer-Verlag.
x0 = [1 5 5 1]; % Initial Guess of Solution
xlb = [1 1 1 1]; % Lower Bound on Decision Variables
xub = [5 5 5 5]; % Upper Bound on Decision Variables
clb = [25 40]; % Lower Bound on Constraints
cub = [inf 40]; % Upper Bound on Constraints
options.lb = xlb;
options.ub = xub;
options.cl = clb;
options.cu = cub;
% Initialize the dual point.
options.zl = [1 1 1 1];
options.zu = [1 1 1 1];
options.lambda = [1 1];
% Set the IPOPT options.
options.ipopt.mu_strategy = adaptive;
options.ipopt.tol = 1e-7;
% The callback functions.
funcs.objective = @objective;
funcs.constraints = @constraints;
funcs.gradient = @gradient;
funcs.jacobian = @jacobian;
funcs.jacobianstructure = @jacstructure;
funcs.hessian = @hessian;
funcs.hessianstructure = @hessstructure;
Copyright 20062012 Anil Vithala Rao Page 140
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
% Run IPOPT.
[x info] = ipopt(x0,funcs,options);
% ----------------------------------------------------------------------
function f = objective(x)
f = x(1)*x(4)*sum(x(1:3)) + x(3);
% ----------------------------------------------------------------------
function g = gradient (x)
g = [ x(1)*x(4) + x(4)*sum(x(1:3))
x(1)*x(4)
x(1)*x(4) + 1
x(1)*sum(x(1:3)) ];
% ----------------------------------------------------------------------
function c = constraints(x)
c = [prod(x);sum(x.^2)];
% ----------------------------------------------------------------------
function J = jacobian(x)
J = sparse([prod(x)./x; 2*x]);
% ----------------------------------------------------------------------
function S = jacstructure
S = sparse(ones(2,4));
% ----------------------------------------------------------------------
function H = hessian (x, sigma, lambda)
H = sigma*[ 2*x(4) 0 0 0;
x(4) 0 0 0;
x(4) 0 0 0;
2*x(1)+x(2)+x(3) x(1) x(1) 0 ];
Copyright 20062012 Anil Vithala Rao Page 141
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
H = H + lambda(1)*[ 0 0 0 0;
x(3)*x(4) 0 0 0;
x(2)*x(4) x(1)*x(4) 0 0;
x(2)*x(3) x(1)*x(3) x(1)*x(2) 0 ];
H = H + lambda(2)*diag([2 2 2 2]);
H = sparse(H);
function HS = hessstructure
HS = sparse(tril(ones(4)));
Copyright 20062012 Anil Vithala Rao Page 142
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Summary
Nonlinear Optimization
Foundation for Function Optimization
Deals with Discrete (Finite-Dimensional) Problem
Formulated as a Nonlinear Programming Problem (NLP)
Candidate Optimal Solutions are Called Extrema
Determination of an Extreme Solution
Compute First Derivative of Augmented Cost Function
Set All Independent Terms in Variation to Zero
In Practice, NLPs Solved Numerically via Iteration
SQP Methods
Barrier Methods
Trust-Region Methods
Previously Developed Sophisticated NLP Software Has Been Described
Copyright 20062012 Anil Vithala Rao Page 143
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part IV: Numerical Methods for Optimal Control
Copyright 20062012 Anil Vithala Rao Page 144
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Overview
Parts I and II of Course
Optimal Control Theory
Nonlinear Optimization
This Part of Course
We Develop Numerical Methods Using Parts I and II
Numerical Methods Consist of Three Parts
Solution of Dierential Equations
Application of Methods for Root-Finding
Application of Nonlinear Optimization
Categories of Numerical Methods for Optimal Control
Indirect Methods: Combine Dierential Equations with Root-Finding
Direct Methods: Combine Dierential Equations with Nonlinear
Optimization
Copyright 20062012 Anil Vithala Rao Page 145
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Overview of Indirect Methods
Indirect Methods
Use Optimal Control Theory
Develop First-Order Optimality Conditions from Calculus of Variations
(Part I of Course)
Attempt to Solve Hamiltonian Boundary-Value Problem (HBVP)
Recall State-Costate Dynamics
( x,

) = (H

, H
x
)
Boundary Conditions on State and Costate
(x(t
0
, t
0
, x(t
f
), t
f
) = 0
(t
0
) =

x(t
0
)
+
_

x(t
0
)
_
T

(t
f
) =

x(t
f
)

_

x(t
f
)
_
T

Copyright 20062012 Anil Vithala Rao Page 146


May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Overview of Direct Methods
Calculus of Variation is Not Used = Optimality conditions are not derived
Instead
State and/or Control Parametrized Using Function Approximation
Dynamics are Integrated Either Explicitly or Implicitly (Will Explain)
Cost functional Replaced with Integral Approximation (Quadrature)
Innite-Dimensional Optimal Control Problem = Nonlinear
Programming Problem (NLP)
NLP solved by well-known methods
Copyright 20062012 Anil Vithala Rao Page 147
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Commonly Used Indirect Methods
Shooting Method
Guess Made of Unknown Initial and/or Terminal Conditions
State-Costate Dynamics Integrated from t
0
to t
f
Error in Initial and Terminal Boundary Conditions Assessed
Iterated Until All Boundary Conditions are Satised
Multiple-Shooting Method
Time Interval Divided Into Segments
Guess Made of Unknown Initial Conditions at Start of Each Segment
State-Costate Dynamics Integrated on Each Segment
Errors at Each Segment Interface and Boundary Conditions Assessed
Iterated Until All Boundary Conditions are Satised
Copyright 20062012 Anil Vithala Rao Page 148
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Indirect Shooting Method
Consider the Following HBVP
p = G(p), p = (x, ), G(p) = (H

, H
x
)
with boundary conditions
(p(t
0
), t
0
, p(t
f
), t
f
) = 0
Observation: Do Not Have complete Set of Initial and/or Terminal Conditions
Iterative Procedure (Indirect Shooting)
Guess Made of of p(t
0
) = p
0
and, possibly, t
0
and t
f
Integrate p = G(p) From t
0
to t
f
At t
f
, have p
f
from Integration
Compute ( p(t
0
), t
0
, p(t
f
), t
f
) and Assess Proximity to Zero
Iterate on Unknown Components of p(t
0
), t
0
, & t
f
Until <
Observe That Error in Depends Upon p
0
; Can Solve Using Newton method
Copyright 20062012 Anil Vithala Rao Page 149
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Schematic of Indirect Shooting Method
Target
Bulls-Eye
Cannon
Copyright 20062012 Anil Vithala Rao Page 150
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Appeal of Indirect Shooting Method
Shooting is a Simple Root Finding Problem
Number of Variables In Root-Finding Problem is Small
Only Number of Unknown Initial Conditions
Low-Dimensional Problem Requires Little Memory on a Computer
Why Not Always Use Indirect Shooting?
Hamiltonian Systems are Unstable in Either Direction of Time
Error in Unknown Initial Conditions Grows When Integrating t
0
to t
f
Even for Simple Problem, Indirect Shooting Can Break Down
Next Slides: Example of Diculties Using Indirect Shooting
Copyright 20062012 Anil Vithala Rao Page 151
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Hamiltonian Boundary-Value Problem for Simple LQ Problem
State-Costate Dynamics and Boundary Conditions
_
_
x

_
_
=
_
_
a
b
2
r
q a
_
_
_
_
x

_
_
,
_
_
x(0) = x
0
x(t
f
) = x
f
_
_
General Solution of First-Order LTI System
p(t) = c
1
e

1
t
w
1
+ c
2
e

2
t
w
2
where
p =
_
_
x

_
_

1
,
2
= Eigenvalues of A
w
1
, w
2
= Eigenvectors of A
Eigenvalues of System Matrix A
det [I A] = det
_
_
a
b
2
r
q + a
_
_
=
2
a
2

qb
2
r
= 0
Copyright 20062012 Anil Vithala Rao Page 152
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Assuming That q > 0 and r > 0, We Obtain
=
_
a
2
+
qb
2
r
Real Eigenvalues with Opposite Sign
Consider Solution for a = b = q = r = 1, t
0
= 0, x(t
0
) = 1,
t
f
= (1, 5, 10, 15, 20), and x(t
f
) = 2
0 5 10 15 20
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
2
t
x
(
t
)


Fint=1
Fint=5
Fint=10
Fint=15
Fint=20
Copyright 20062012 Anil Vithala Rao Page 153
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
0 5 10 15 20
1
0.5
0
0.5
1
1.5
2
2.5
t
l
a
m
b
d
a
(
t
)


Fint=1
Fint=5
Fint=10
Fint=15
Fint=20
Key points
Both state and costate have decaying and growing behavior
Growth and decay show up as t
f
increases
Copyright 20062012 Anil Vithala Rao Page 154
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Solution of LQ Problem Using Indirect Shooting
Two missing boundary conditions: (0) and (t
f
)
Can develop iteration as follows:
Integrate state-costate dynamics either
From t
0
to t
f
= need to iterate on (0)
From t
f
to t
0
= need to iterate on (t
f
)
Issue
A has both a positive and negative eigenvalue
State-costate dynamics are unstable in either direction of time
Numerical Problems Arise When t
f
is Large
Growing Component of Dynamics Due to Eigenvalue at = +
Let
0
be Error in Guess of (0)
Then Error in Initial Condition Given as
p(0) =
_
_
0

0
_
_
Copyright 20062012 Anil Vithala Rao Page 155
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Resulting Error at t
f
p(t
f
) = e
At
f
p(0)
Now e
At
f
has a Mode That Grows Like e
t
Suciently large t
f
e
t
f
will Result in Overow on a Computer
Note: Overow will Eventually occur t
f
Suciently Large, Even for
extremely small (0)
Numerical Solution of a HBVP Can be Extremely Dicult
Overcoming Diculties of Indirect Shooting: Indirect
Multiple-Shooting Method
Copyright 20062012 Anil Vithala Rao Page 156
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example: Orbit-Transfer Problem
Hamiltonian Boundary-Value Problem
r = u
u =
v
2
r


r
2
+
T
m
sin

v =
uv
r
+
T
m
cos

m =
T
g
0
I
sp

r
=
u
_
v
2
r
2

2
r
3
_

v
uv
r
2

u
=
r
+
v
v
r

v
=
u
2v
r
+
v
u
r

m
=
u
_
T
m
2
sin

_
+
v
_
T
m
2
cos

_
Copyright 20062012 Anil Vithala Rao Page 157
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
r(t
0
) = r
0
, u(t
0
) = 0
v(t
0
) =
_
/r
0
, m(t
0
) = m
0
r(t
f
) = r
f
, u(t
f
) = 0
v(t
f
) =
_
/r
f
,
m
(t
f
) = 0
Notes:
Initial and Terminal Conditions are Incomplete
Half of the initial conditions and terminal conditions are specied
Solved Numerically in MATLAB Using Indirect Shooting Method
Copyright 20062012 Anil Vithala Rao Page 158
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Code for Orbit Transfer (Uses SNOPT)
% Minimum-Time Orbit Transfer Example
% Solves Hamiltonian Boundary-Value Problem
% Using SNOPT with Feasible Point Option
clear snoptcmex
clear all
close all
clc
warning off
mu = 1;
r0 = 1;
u0 = 0;
v0 = 1;
m0 = 1;
rf = 1.5;
uf = 0;
vf = sqrt(mu/rf);
lam0 = [-1; -1; 1; 1];
tf0 = 2;
guess = [lam0; tf0];
global xpath iters;
iters = 0;
xlow = -50*ones(5,1);
xupp = 50*ones(5,1);
Flow = [-Inf; zeros(4,1)];
Fupp = [+Inf; zeros(4,1)];
snset(Feasible Point);
userfun = orbitObjandCons;
snscreen on
[xout,F,inform,xmul,Fmul] = snopt(guess,xlow,xupp,Flow,Fupp,userfun);
p0 = [r0; u0; v0; m0; xout(1:4)];
pf = [rf; uf; vf; xout(1:4); 0];
tspan = linspace(0,xout(5),40);
Copyright 20062012 Anil Vithala Rao Page 159
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
odeopts = odeset(RelTol,1e-12,AbsTol,1e-12);
[tout,pout]=ode15s(@orbitode_bvp,tspan,p0,odeopts);
alpha = unwrap(atan2(pout(:,6),pout(:,7)))*180/pi;
orbitIndirectTraj = [tout pout alpha];
save orbitIndirectTraj.mat orbitIndirectTraj;
figure(1);
pp = plot(tout,pout(:,1),-o,tout,pout(:,2),-d,tout,pout(:,3),-s,tout,pout(:,4),-v);
set(pp,LineWidth,1.5,MarkerSize,6);
xl = xlabel(Time);
yl = ylabel(States);
ll = legend(r,u,v,m,Location,NorthWest);
set(xl,FontSize,12);
set(yl,FontSize,12);
set(ll,FontSize,16);
set(gca,FontName,Times,FontSize,12);
grid on;
print -depsc2 orbitRaisingIndirectShootingStates.eps
figure(2);
pp = plot(tout,pout(:,5),-o,tout,pout(:,6),-d,tout,pout(:,7),-s,tout,pout(:,8),-v);
set(pp,LineWidth,1.5,MarkerSize,6);
xl = xlabel(Time);
yl = ylabel(Costates);
ll = legend(lamr,lamu,lamv,lamm,Location,NorthWest);
set(xl,FontSize,12);
set(yl,FontSize,12);
set(ll,FontSize,16);
set(gca,FontName,Times,FontSize,12);
grid on;
print -depsc2 orbitRaisingIndirectShootingCostates.eps
figure(3);
pp = plot(tout,alpha,-o);
set(pp,LineWidth,1.5,MarkerSize,6);
xl = xlabel(Time);
yl = ylabel(Control);
Copyright 20062012 Anil Vithala Rao Page 160
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
set(xl,FontSize,12);
set(yl,FontSize,12);
set(gca,FontName,Times,FontSize,12);
grid on;
print -depsc2 orbitRaisingIndirectShootingControl.eps
function C = orbitObjandCons(x);
mu = 1;
r0 = 1;
u0 = 0;
v0 = sqrt(mu/r0);
m0 = 1;
rf = 1.5;
uf = 0;
vf = sqrt(mu/rf);
pfinal = [rf; uf; vf];
pinitial =[r0; u0; v0; m0];
p = [r0; u0; v0; m0; x(1:4)];
target = [pfinal; 0];
tf = x(5);
tspan = linspace(0,tf,100);
opts = odeset(RelTol,1e-3);
[tout,pout]=ode15s(@orbitode_bvp,tspan,p,opts);
error = target-[pout(end,1:3) pout(end,8)].;
C = [0; error];
function pdot = orbitode_bvp(t,p);
mu = 1;
T = 0.1405;
mass_flow_rate = 0.0749;
r = p(1);
u = p(2);
v = p(3);
m = p(4);
lamr = p(5);
lamu = p(6);
Copyright 20062012 Anil Vithala Rao Page 161
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
lamv = p(7);
lamm = p(8);
%sinalpha = lamu./sqrt(lamu.^2+lamv.^2);
%cosalpha = lamv./sqrt(lamu.^2+lamv.^2);
alpha = atan2(lamu,lamv);
sinalpha = sin(alpha);
cosalpha = cos(alpha);
pdot = zeros(8,1);
rdot = u;
udot = v.^2./r-mu./r.^2+(T./m).*sinalpha;
vdot = -(u.*v)./r+(T./m).*cosalpha;
mdot = -mass_flow_rate;
lamrdot = lamu.*(v.^2./r.^2-2*mu./r.^3)-lamv.*(u.*v)./r.^2;
lamudot = -lamr+lamv.*v./r;
lamvdot = -lamu.*(2.*v./r)+lamv.*(u./r);
lammdot = lamu.*(T.*sinalpha./m.^2)+lamv.*(T.*cosalpha./m.^2);
pdot(1:8) = [rdot; udot; vdot; mdot; lamrdot; lamudot; lamvdot; lammdot];
Copyright 20062012 Anil Vithala Rao Page 162
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
State Solution of Orbit Transfer Problem
0 0.5 1 1.5 2 2.5 3 3.5
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6


r
u
v
m
S
t
a
t
e
s
t
Copyright 20062012 Anil Vithala Rao Page 163
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Control Solution of Orbit Transfer Problem
0 0.5 1 1.5 2 2.5 3 3.5
0
50
100
150
200
250
300
350
C
o
n
t
r
o
l
t
Copyright 20062012 Anil Vithala Rao Page 164
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Costate Solution of Orbit Transfer Problem
0 0.5 1 1.5 2 2.5 3 3.5
20
15
10
5
0
5
10
15
20
25

m
C
o
s
t
a
t
e
s
t
Copyright 20062012 Anil Vithala Rao Page 165
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
The Indirect Multiple-Shooting Method
Basics of Multiple-Shooting Method
Break time interval into subintervals
Shoot over each subinterval
Implementation of a Multiple-Shooting Method
Let I
s
= [t
s
, t
s+1
] , (s = 1, . . . , S)
Ensure following conditions

S
s=1
I
s
=

S
s=1
I
s
= [t
0
, t
f
]
Integrate over each subinterval I
s
Need to enforce continuity constraints at interior interfaces
x(t

s
) = x(t
+
s
)
(t

s
) = (t
+
s
)
Copyright 20062012 Anil Vithala Rao Page 166
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Pros and Cons of Indirect Multiple-Shooting
Pros
Integration Performed Over Shorter Time Intervals
Does Not Allow Hamiltonian Dynamics to Blow Up
Can Overcome Diculties Associated with Indirect Shooting
Increases Range of Problems
Cons
Need to guess values at beginning of each subinterval
p(t
+
s
), (s = 2, . . . , S 1) Become Additional Variables in Problem
Total Set of Variables Increased With Each Added Subinterval
Many more variables and constraints in problem
Guessing Values of p(t
+
s
), (s = 2, . . . , S 1) Usually Not Intuitive
Root-Finding Problem of Much Higher-Dimension Than Indirect
Shooting
Copyright 20062012 Anil Vithala Rao Page 167
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Other General Problems with Indirect Methods
Need to Derive First-Order Optimality Conditions
Costate Equations
Transversality Conditions
Why is Deriving Such Conditions Problematic?
Functions May Be Very Complex
Some Functions May Not Even Have Analytic Forms (Table
Interpolation)
Becomes Very Dicult for Practical Problem
Multiple-Phase Problems
Dynamics and Path Constraints May Be Dierent in Each Phase
Extremely Cumbersome to Derive Conditions for Complex Problem
Bottom Line: Dont Want to Have to Derive Optimality Conditions
Copyright 20062012 Anil Vithala Rao Page 168
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Direct Methods
Optimality conditions are not derived. Instead
State and/or Control Parametrized Using Function Approximation
Cost Approximated Using Quadrature
Optimal Control Problem Converted to an NLP
Innite-dimensional problem nite-dimensional problem
Direct Methods Divided Into Two General Categories
Control Parametrization: Shooting and Multiple-Shooting
State & Control Parametrization: Collocation
Copyright 20062012 Anil Vithala Rao Page 169
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Direct Methods
Control Parameterization State & Control Parameterization
Shooting Multiple-Shooting Local Collocation Global Collocation
Orthogonal
Collocation
Implicit/Explicit
Integration
Pseudospectral
Methods
Control Parametrization: Simple, But Not As Capable
State & Control Parametrization: More Capable, But More Involved
Will Discuss Both Types of Methods
Copyright 20062012 Anil Vithala Rao Page 170
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Direct Shooting Method
Step 1: Choose a Function Approximation for Control
u(t) =
N

k=0
c
k

k
(t)
Basis Functions
0
(t), . . . ,
N
(t) Arbitrary
Usually Choose Polynomials
Step 2: Guess Unknown Coecients (c
0
, . . . , c
N
)
Step 3: Integrate Dynamics from t
0
to t
f
Iterate on Coecients Until Cost Minimized and Constraints Satised
Copyright 20062012 Anil Vithala Rao Page 171
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example: Linear-Tangent Steering Problem
Cost Function: J = t
f
Dynamics
x
1
= x
3
x
2
= x
4
x
3
= a cos(u)
x
4
= a sin(u)
Initial Conditions: (x
1
(0), x
2
(0), x
3
(0), x
4
(0)) = (0, 0, 0, 0)
Terminal Conditions: (x
2
(t
f
), x
3
(t
f
), x
4
(t
f
)) = (5, 45, 0)
Copyright 20062012 Anil Vithala Rao Page 172
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Code for Linear Tangent Problem
global CONSTANTS
CONSTANTS.polynomialDegree = 3;
CONSTANTS.a = 100;
x10 = 0;
x20 = 0;
x30 = 0;
x40 = 0;
x2f = 5;
x3f = 45;
x4f = 0;
tfMin = 0.01;
tfMax = 100;
CONSTANTS.initialState = [x10; x20; x30; x40];
CONSTANTS.terminalState = [x2f; x3f; x4f];
tfGuess = 10;
z0 = [ones(CONSTANTS.polynomialDegree+1,1); tfGuess];
zlow = [-10*ones(CONSTANTS.polynomialDegree+1,1); tfMin];
zupp = [+10*ones(CONSTANTS.polynomialDegree+1,1); tfMax];
Flow = [tfMin; zeros(size(CONSTANTS.terminalState))];
Fupp = [tfMax; zeros(size(CONSTANTS.terminalState))];
snscreen on
snprint(snoptmain.out);
snseti(Derivative Option,0);
snseti(Print Level,10);
[z,F,inform,zmul,Fmul] = snopt(z0,zlow,zupp,Flow,Fupp,linearTangentObjandCons);
p0 = CONSTANTS.initialState;
tspan = [0 z(end)];
opts = odeset(RelTol,1e-3);
[tout,pout]=ode45(@linearTangentOde,tspan,p0,opts,z(1:end-1));
uout = polyval(z(1:end-1),tout);
figure(1);
Copyright 20062012 Anil Vithala Rao Page 173
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
pp = plot(tout,pout(:,1),-o,tout,pout(:,2),-d,tout,pout(:,3),-s,tout,pout(:,4),-v);
set(pp,LineWidth,1.5,MarkerSize,8);
xl = xlabel(Time);
yl = ylabel(States);
ll = legend(State1(t),State2(t),State3(t),State4(t),Location,NorthWest);
set(xl,FontSize,12);
set(yl,FontSize,12);
set(ll,FontSize,16);
set(gca,FontName,Times,FontSize,12);
grid on;
print -depsc2 linearTangentDirectShootingState.eps
figure(2);
pp = plot(tout,uout,-o);
set(pp,LineWidth,1.5,MarkerSize,8);
xl = xlabel(Time);
yl = ylabel(Control);
set(xl,FontSize,12);
set(yl,FontSize,12);
set(gca,FontName,Times,FontSize,12);
grid on;
print -depsc2 linearTangentDirectShootingControl.eps
function C = linearTangentObjandCons(z);
global CONSTANTS
controlCoefs = z(1:end-1);
tf = z(end);
p0 = CONSTANTS.initialState;
tspan = [0 tf];
opts = odeset(RelTol,1e-3);
[tout,pout]=ode45(@linearTangentOde,tspan,p0,opts,controlCoefs);
C = [tf; pout(end,2:4).-CONSTANTS.terminalState];
function pdot=linearTangentOde(t,p,c);
Copyright 20062012 Anil Vithala Rao Page 174
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
global CONSTANTS
u = 0;
u = polyval(c,t);
p1dot = p(3);
p2dot = p(4);
p3dot = CONSTANTS.a*cos(u);
p4dot = CONSTANTS.a*sin(u);
pdot = [p1dot; p2dot; p3dot; p4dot];
Copyright 20062012 Anil Vithala Rao Page 175
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Direct Shooting Solution of Linear-Tangent Problem
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
0
5
10
15
20
25
30
35
40
45
50


x
1
(t)
x
2
(t)
x
3
(t)
x
4
(t)
S
t
a
t
e
s
t
Copyright 20062012 Anil Vithala Rao Page 176
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
1.5
1
0.5
0
0.5
1
1.5
C
o
n
t
r
o
l
t
Copyright 20062012 Anil Vithala Rao Page 177
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example: Direct Shooting Solution of Orbit-Raising Problem
Will Formulate Problem Using Two Control Parametrization
Parametrization 1: Global Polynomial
(t)
5

k=0
c
k
t
k
Degree 5 Polynomial
Parametrization 2: Arc-tangent of Ratio of Two Polynomials
(t) tan
1
(n(t), d(t))
n(t) =

5
k=0
n
k
t
k
d(t) =

5
k=0
d
k
t
k
Ratio of Two Degree 5 Polynomials
Objective of Comparison
Show How Quality of Direct Shooting Solution Depends on Control
Parametrization
Need Some Insight to Use Appropriate Control Parametrization
Copyright 20062012 Anil Vithala Rao Page 178
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Control Solution to Orbit-Raising Problem Using Polynomial Control
0 0.5 1 1.5 2 2.5 3 3.5
150
100
50
0
50
100
150
200
250
300
350


Direct
Indirect
C
o
n
t
r
o
l
t
Copyright 20062012 Anil Vithala Rao Page 179
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Control Solution to Orbit-Raising Problem Using tan
1
Control
0 0.5 1 1.5 2 2.5 3 3.5
0
50
100
150
200
250
300
350


Direct
Indirect
C
o
n
t
r
o
l
t
Copyright 20062012 Anil Vithala Rao Page 180
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Code for Direct Shooting Solution of Orbit-Raising Problem
clear snoptcmex
clear all
close all
global CONSTANTS numseg breaks nstates nterminal numcons degree control_type
control_type = polynomial;
% control_type = arctangent;
degree = 5;
numseg = 1;
nstates = 4;
nterminal = 3;
numcons = (numseg-1)*nstates+nterminal;
numvars = (numseg-1)*nstates+numseg*(degree+1)+1;
width = 1/numseg;
breaks = width:width:1;
CONSTANTS.mu = 1;
CONSTANTS.T = 0.1405;
CONSTANTS.Ve = 1.8758;
r0 = 1; rf = 1.5;
u0 = 0; uf = 0;
v0 = 1; vf = sqrt(CONSTANTS.mu/rf);
m0 = 1;
rmin = 1;
rmax = 2;
umin = -0.1;
umax = 0.5;
vmin = 0.5;
vmax = 1.1;
mmax = 1.05;
mmin = 0.5;
stateLow = [rmin; umin; vmin; mmin];
stateUpp = [rmax; umax; vmax; mmax];
tfMin = 2;
Copyright 20062012 Anil Vithala Rao Page 181
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
tfMax = 3.6;
CONSTANTS.initialState = [r0; u0; v0; m0];
CONSTANTS.terminalState = [rf; uf; vf];
tfGuess = 3;
coefsGuess = [zeros(degree,1); 0.2];
z0 = coefsGuess;
coefMax = 3;
zlow = -coefMax*ones(degree+1,1);
zupp = coefMax*ones(degree+1,1);
Flow = [];
Fupp = [];
rr = [0.5; 0.5; 0.5; 0.5];
for i=2:numseg;
z0 = [z0; rr; coefsGuess];
zlow = [zlow; stateLow; -coefMax*ones(degree+1,1)];
zupp = [zupp; stateUpp; coefMax*ones(degree+1,1)];
Flow = [Flow; zeros(nstates,1)];
Fupp = [Fupp; zeros(nstates,1)];
end;
z0 = [z0; tfGuess];
zlow = [zlow; tfMin];
zupp = [zupp; tfMax];
Flow = [Flow; zeros(nterminal,1)];
Fupp = [Fupp; zeros(nterminal,1)];
Flow = [-inf; Flow];
Fupp = [inf; Fupp];
snscreen on
if isequal(control_type,polynomial),
snprint(snoptmainShootingPolynomial.out);
else
snprint(snoptmainShootingArctangent.out);
end;
snsetr(Optimality Tolerance,1e-5);
snsetr(Feasibility Tolerance,1e-5);
snseti(Derivative Option,0);
snseti(Print Level,10);
ObjAdd = 0;
Copyright 20062012 Anil Vithala Rao Page 182
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
ObjRow = 1;
A = [];
iAfun = []; jAvar = [];
JJ = ones(numcons+1,numvars);
[iGfun,jGvar]=find(JJ);
userfun = orbitRaisingObjandCons;
[z,F,inform,zmul,Fmul] = snopt(z0,zlow,zupp,Flow,Fupp,userfun,0,1,A,iAfun,jAvar,iGfun,jGvar);
p0 = CONSTANTS.initialState;
tfOptimal = z(end);
tfuse = tfOptimal*breaks;
opts = odeset(RelTol,1e-10);
istart = 1;
ifinish = degree+1;
controlCoefs = z(istart:ifinish);
tspan = [0:tfuse(1):tfuse(1)];
[tout,pout]=ode45(@orbitRaisingOde,tspan,p0,opts,controlCoefs);
ttot = tout;
ptot = pout;
if isequal(control_type,polynomial),
utot = polyval(controlCoefs,ttot);
else
lc = length(controlCoefs);
numerator = polyval(controlCoefs(1:lc/2),tout);
denominator = polyval(controlCoefs(lc/2+1:end),tout);
utot = atan2(numerator,denominator);
end;
if 0,
for jj=2:numseg;
istart = ifinish+1;
ifinish = istart+nstates+degree;
zuse = z(istart:ifinish);
p0 = zuse(1:nstates);
controlCoefs = zuse(nstates+1:nstates+degree+1);
tspan = [tfuse(jj-1):(tfuse(jj)-tfuse(jj-1))/10:tfuse(jj)];
[tout,pout]=ode45(@orbitRaisingOde,tspan,p0,opts,controlCoefs);
% uout = polyval(controlCoefs,tout);
numerator = polyval(controCoefs(1:lc/2,tout));
Copyright 20062012 Anil Vithala Rao Page 183
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
denominator = polyval(controCoefs(lc/2+1:end,tout));
uout = atan2(numerator,denominator);
% uout = polyval(controlCoefs,tout);
ttot = [ttot; tout];
ptot = [ptot; pout];
utot = [utot; uout];
end;
end;
utot = unwrap(utot)*180/pi;
figure(1);
pp = plot(ttot,ptot(:,1),-o,ttot,ptot(:,2),-d,ttot,ptot(:,3),-s,ttot,ptot(:,4),-v);
set(pp,LineWidth,1.5,MarkerSize,8);
xl = xlabel(Time);
yl = ylabel(States);
ll = legend(r,u,v,m,Location,Northwest);
set(xl,FontSize,12);
set(yl,FontSize,12);
set(ll,FontSize,16);
set(gca,FontName,Times,FontSize,12);
grid on;
if isequal(control_type,polynomial),
print -depsc2 orbitRaisingDirectShootingStatePolynomial.eps
else
print -depsc2 orbitRaisingDirectShootingStateArctangent.eps
end;
currdir = pwd;
cd(../../../Indirect/orbitRaising);
load orbitIndirectTraj.mat;
cd(currdir);
tindirect = orbitIndirectTraj(:,1);
uindirect = orbitIndirectTraj(:,end);
figure(2);
pp = plot(ttot,utot,-o,tindirect,uindirect,-d);
set(pp,LineWidth,1.5,MarkerSize,8);
xl = xlabel(Time);
Copyright 20062012 Anil Vithala Rao Page 184
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
yl = ylabel(Control);
ll = legend(Direct,Indirect,Location,Northwest);
set(xl,FontSize,12);
set(yl,FontSize,12);
set(ll,FontSize,16);
set(gca,FontName,Times,FontSize,12);
grid on;
if isequal(control_type,polynomial),
print -depsc2 orbitRaisingDirectShootingControlPolynomial.eps
else
print -depsc2 orbitRaisingDirectShootingControlArctangent.eps
end;
function C = orbitRaisingObjandCons(z);
global CONSTANTS numseg breaks nstates nterminal numcons degree
tf = z(end);
tfuse = tf*breaks;
C = zeros(numcons+1,1);
opts = odeset(RelTol,1e-10);
p0 = CONSTANTS.initialState;
istart = 1;
ifinish = degree+1;
controlCoefs = z(istart:ifinish);
tspan = [0 tfuse(1)];
[tout,pout]=ode45(@orbitRaisingOde,tspan,p0,opts,controlCoefs);
lastStateSave = pout(end,:).;
lastDerivativeSave = orbitRaisingOde(tspan(end),pout(end,:).,controlCoefs);
err = [];
derr = [];
for jj=2:numseg;
istart = ifinish+1;
ifinish = istart+nstates+degree;
zuse = z(istart:ifinish);
p0 = zuse(1:nstates);
err(:,jj-1) = p0-lastStateSave;
Copyright 20062012 Anil Vithala Rao Page 185
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
controlCoefs = zuse(nstates+1:nstates+degree+1);
tspan = [tfuse(jj-1) tfuse(jj)];
dp0 = orbitRaisingOde(tspan(1),p0,controlCoefs);
% derr(:,jj-1) = dp0-lastDerivativeSave;
[tout,pout]=ode45(@orbitRaisingOde,tspan,p0,opts,controlCoefs);
lastStateSave = pout(end,:).;
lastDerivativeSave = orbitRaisingOde(tspan(end),pout(end,:).,controlCoefs);
end;
errtot = [err; derr];
Errorf = pout(end,1:3).-CONSTANTS.terminalState;
C = [tf; errtot(:); Errorf];
function pdot=orbitRaisingOde(t,p,c);
global CONSTANTS control_type
r = p(1); u = p(2); v = p(3); m = p(4);
if isequal(control_type,polynomial),
alpha = polyval(c,t);
else
lc = length(c);
numerator = polyval(c(1:lc/2),t);
denominator = polyval(c(lc/2+1:end),t);
alpha = atan2(numerator,denominator);
end;
rdot = u;
udot = v^2/r-CONSTANTS.mu/r^2+CONSTANTS.T*sin(alpha)/m;
vdot = -u*v/r +CONSTANTS.T*cos(alpha)/m;
mdot = -CONSTANTS.T/CONSTANTS.Ve;
pdot = [rdot; udot; vdot; mdot];
Copyright 20062012 Anil Vithala Rao Page 186
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Lessons Learned from Direct Shooting
Pros
No Need to Derive Complicated Optimality Conditions
Integrate Only State Dynamics, Not Costate Dynamics
Coding is Very Straightforward
Cons
Solution Very Sensitive to Choice of Control
Without Insight Into Problem, Low-Quality Solution Produced
Modication of Direct Shooting: Direct Multiple Shooting
Copyright 20062012 Anil Vithala Rao Page 187
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Direct Multiple-Shooting
Let t
0
=Start Time of Phase and t
f
=Terminus Time of Phase
Divide Trajectory Into Segments, t
0
< t
1
< t
2
< < t
N1
< t
N
where
t
N
= t
f
Points t
0
, t
1
, t
2
, . . . , t
N
Called Grid Points or Mesh Points
Parametrize the Control in Each Segment As
u
(s)
(t) =
N

k=0
c
(s)
k

(s)
k
(t)
Connect Segments with Continuity Constraint on State
x(t

s
) = x(t
+
s
), s = 1, . . . , S 1
Total Cost = Sum of Cost in Each Segment
Enforce Boundary Conditions in First and Last Segment
Copyright 20062012 Anil Vithala Rao Page 188
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Schematic of Multiple-Shooting
Direct Shooting Performed
On Each Subinterval
State Forced To Be Continuous
At Each Segment Interface
S
t
a
t
e
Time
Segment Break Times
Copyright 20062012 Anil Vithala Rao Page 189
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example: Orbit-Raising Problem
Same Problem as Solved Earlier Using Indirect and Direct Shooting
In This Example We Choose
Number of Segments = 10
Degree of Polynomial Approximation in Each Segment = 3
Problem Divided Into Equal Width Segments
Copyright 20062012 Anil Vithala Rao Page 190
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Direct Multiple-Shooting Solution to Orbit-Raising Problem
0 0.5 1 1.5 2 2.5 3 3.5
0
50
100
150
200
250
300
350


C
o
n
t
r
o
l
t
Direct
Indirect
Copyright 20062012 Anil Vithala Rao Page 191
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Comments on Direct Multiple-Shooting
Improves Solution Over Naively Implemented Direct Shooting
More Complex Than Direct Shooting
Need to Add Continuity Constraints on State at Segment Interfaces
Increases the Size of the Problem (More Variables, More Constraints)
May Obtain Discontinuous Control (Even if True Optimal Control is
Continuous)
Benets of Direct Multiple Shooting
Improves the Quality of the Control over Direct Shooting
Allows for Possible Control Discontinuities
Copyright 20062012 Anil Vithala Rao Page 192
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Limitations with Shooting Methods
Generally Produces Low-Accuracy Solutions
Computationally Inecient
May Not Converge to Solution for Inappropriate Control Approximations
Serious Limiting Factors: Inclusion of Constraints
Control Constraints: Dicult to Place Bounds on Control
State Path Constraints
Need to Formulate Problem Using Dierential-Algebraic Equations
(DAEs)
DAEs dicult to Solve via Explicit Integration
Path Constraints Dicult to Include in Problem
Copyright 20062012 Anil Vithala Rao Page 193
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Added Complexity: Phases
Real Optimal Control Problems are Modeled Using Phases
What is a Phase? a Distinct Chunk of the Trajectory
How are Phases Implemented?
Divide Problem into Phases
Each Phase has
Its Own Dynamics and Path Constraints
Dynamics May Be Dierent from Phase to Phase
Phases are Linked Using Continuity Conditions on State

min
(p
s
f
, t
s
f
, p
s+1
0
, t
s+1
0
)
max
where s [1, . . . , S] are the phases in the problem
Why Phases Are Important
Consider the Problem of a Two-Stage Launch Vehicle
Stage 1: First Engine Burns; Dry Mass Jettisoned at End of Stage
Stage 2: Second Engine Burns; Dry Mass Jettisoned at End of Stage
Copyright 20062012 Anil Vithala Rao Page 194
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Connection Between Stages: Position and Velocity Continuous; Mass
Discontinuous
Problem Cannot Be Solved Using a Single Phase
Shooting Methods Become Even More Complex With Multiple-Phase
Problems
Need Approach That Scales to Complex Problems
More Sophisticated Approach: Direct Collocation
Copyright 20062012 Anil Vithala Rao Page 195
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Direct Collocation Methods for Optimal Control
Generally, Structure of Optimal Control Not Known a Priori
Would Like a Computationally Ecient Method That Is Flexible
Does Not Require an a Priori Knowledge of Control
Provides Greater Accuracy As Compared with Shooting
More Sophisticated Class of Direct Methods: Collocation
Collocation: State and Control Parameterization Methods
Allows for Very Flexible Formulation of Optimal Control Problem
Multiple Phases
Path Constraints (Equality and Inequality)
In Collocation, Dynamics are Not Propagated
Instead, Dierential Equations Converted to Algebraic Constraints
Leads to NLP: min f(z) subject to g(z) = 0 and h
min
h(z) h
max
Entire System Then Optimized Simultaneously for State and Control
Copyright 20062012 Anil Vithala Rao Page 196
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example of Collocation: Euler Forward
Euler Forward Integration: Given (t
k
, u
k
, x
k
), Determine x
k+1
x
k+1
= x
k
+ hf(x
k
, u
k
, t
k
)
However, We Could Write Euler Forward As Follows
x
1
= x
0
+ hf(x
0
, u
0
, t
0
)
x
2
= x
1
+ hf(x
1
, u
1
, t
1
)
.
.
.
x
M
= x
M1
+ hf(x
M1
, u
M1
, t
M1
)
Rearranging, We Have a System of Simultaneous Equations
x
1
x
0
hf(x
0
, u
0
, t
0
) = 0
x
2
x
1
hf(x
1
, u
1
, t
1
) = 0
.
.
.
x
M
x
M1
hf(x
M1
, u
M1
, t
M1
) = 0
Copyright 20062012 Anil Vithala Rao Page 197
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Approximation of Cost
J (x
0
, t
0
, x
M
, t
M
) + h
M1

k=1
L[x
i
, u
i
, t
i
]
Boundary Conditions
(x
0
, t
0
, x
M
, t
M
) = 0
Result: We End Up with an NLP of the Form
minimize f(z)
Subject to
g(z) = 0
NLP Variables: z = (x
0
, . . . , x
M
, u
0
, . . . , u
M1
)
NLP Constraints
System of Equations Resulting from Euler Discretization
Boundary Conditions
Copyright 20062012 Anil Vithala Rao Page 198
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Euler Forward Provides Key Features of Collocation
M=Number of Intervals Number of Time Steps
As M Gets Large
Problem Divided Into Increasingly More Subintervals
Number of NLP Variables 2M
More General Result
Suppose We Have n States and m Controls
Number of NLP Variables M(n + m)
Suppose M = 1000, n = 6, and m = 3 M(n + m) 9000
Complex Problem
Thousands to Tens of Thousands Variables and Constraints
NLP Using Direct Collocation is Huge
Question: Is Direct Collocation Computationally Viable?
Copyright 20062012 Anil Vithala Rao Page 199
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Why Use a Collocation Method?
At First Glance
Seems As If Weve Made Problem Harder
Many Equations in Many Unknowns
As It Happens, Collocation Methods Are
Computationally Ecient
Robust to Initial Guesses
Why?
Advanced NLP Solvers Designed to Solve Large Sparse Problems
Using Collocation Leads to a Large Sparse NLP
What is a Sparse NLP?
Problem May Have Many Variables and Constraints
But Derivatives of Functions Have Large Number of Zeros
Sparsity Makes It Possible to Develop Ecient Iteration Methods
Copyright 20062012 Anil Vithala Rao Page 200
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Collocation Formulation
Divide Phase into Segments
t
0
< t
1
< t
2
< < t
N1
< t
N
where t
N
= t
f
Points t
0
, t
1
, t
2
, . . . , t
N
Called Grid Points or Mesh Points
Now Consider a Segment I
s
= [t
k
, t
k+1
]
Treat state and control as variables in discretization
Dierential equations replaced by algebraic approximations
All constraints will have the general form
c
L
c(y) c
U
where
c(y) =
_

1
,
2
, . . . ,
M1
, , g
1
, . . . , g
M
_
Note that y = Vector of Variables in Discretized Problem
Copyright 20062012 Anil Vithala Rao Page 201
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Common Discretization Schemes
Euler Method
Variables: y = (x
1
, u
1
, . . . , x
M
, u
M
)
Defects:

k
= x
k+1
x
k
h
k
f
k
Classical Runge-Kutta Method
Variables: (x
1
, u
1
, u
2
, . . . , u
M
, x
M
, u
M
)
Defects

k
= x
k+1
x
k

1
6
(k
1
+ 2k
2
+ 2k
2
+k
3
)
where
k
1
= h
k
f
k
k
2
= h
k
f
_
x
k
+
1
2
k
1
, u
k+1
, t
k
+
1
2
h
k
_
k
3
= h
k
f
_
x
k
+
1
2
k
2
, u
k+1
, t
k
+
1
2
h
k
_
k
4
= h
k
f (x
k
+k
3
, u
k+1
, t
k
+ h
k
)
u
k+1
=
1
2
(u
k
+u
k+1
)
Hermite-Simpson Method
Copyright 20062012 Anil Vithala Rao Page 202
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Variables: y = (x
1
, u
1
, u
2
, . . . , u
M
, x
M
, u
M
)
Defects:

k
= x
k+1
x
k

1
6
h
k
_
f
k
+ 4

f
k+1
+f
k+1
_
where
x
k+1
=
1
2
(x
k
+x
k+1
) +
1
8
h
k
(f
k
f
k+1
)

f
k+1
= f
_
x
k+1
, u
k+1
, t
k
+
1
2
h
k
_
Copyright 20062012 Anil Vithala Rao Page 203
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Variable-Length Phase Durations
Phase Duration May Be a Variable, i.e., t
0
and t
f
May Not Be Fixed
For Variable-Length Phase,
Need to include t
0
and/or t
f
as variables in discretization
Discretization step must be altered such that
h
k
=
k
(t
f
t
0
) =
k
t
where t = t
f
t
0
and 0 <
k
< 1
Essentially, t
0
and t
f
change like an accordion
Copyright 20062012 Anil Vithala Rao Page 204
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Highlights of Direct Approach
Continuous-Time Dynamics = Algebraic Equations
Algebraic Equations Have Defects
Objective: Make Defects Zero
In Other Words, Defects are Equality Constraints
Problem is Transcribed to an NLP
Basic Structure of NLP
Minimize
f(z)
subject to
g(z) = 0
h
min
h(z) h
max
_
_
_
=
Contains Disretized Dynamics
Path Constraints, and Boundary Conditions
Copyright 20062012 Anil Vithala Rao Page 205
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Other Positive Attributes of Collocation Methods
Inclusion of Path Constraints Much Easier
To See This, Consider Euler Collocation Method Again
Recall NLP Variables in Euler Scheme: z = (x
0
, . . . , x
M
, u
0
, . . . , u
M1
)
Suppose We Have Path Constraint C(x, u) 0
Then We Can Enforce Path Constraint at Collocation Points As
C(x
i
, u
i
) 0, (i = i, . . . , M 1)
Observations
Path Constraints No More Complicated Than Dynamic Constraints
Can Be Inequalty or Equality
Does Not Require Ad Hoc Procedure to Include
Copyright 20062012 Anil Vithala Rao Page 206
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Trade-O Between Indirect and Direct Methods
Indirect Methods
Beautiful mathematics (calculus of variations)
If solvable, HBVP produces state, control, and costate
Can gain great insight into structure of solution (e.g., LQR problem)
We know how close to optimal is the solution (because we have costate)
However,
Small radii of convergence
Dicult to solve HBVP
Often, cannot even derive optimality conditions
Indirect methods are generally intractable
Direct Methods
Mathematics not so elegant (nite-dierence methods)
No costate produced from solution to NLP
Dicult to gain insight into structure of solution
Do not know how close we are to true optimal solution
Copyright 20062012 Anil Vithala Rao Page 207
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
However,
Large radii of convergence
Much easier to solve NLP than to solve HBVP
No need to derive optimality conditions
Direct methods are highly tractable
So What is Ideal
Want Direct Method
Want Direct Method to Have Features of Indirect Method
In particular, want an accurate costate
Then we eectively have same information as an indirect method
Question: Do Such Methods Exist?
Answer: Yes
Question: What Are These Methods?
Answer: Pseudospectral Methods
Copyright 20062012 Anil Vithala Rao Page 208
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part V: Numerical Integration & Interpolation
Copyright 20062012 Anil Vithala Rao Page 209
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Numerical Quadrature and Interpolation
Numerical Quadrature
Need to Accurately Approximate Integral of a Function
Quadrature Approximations
Sample Function at Points in the Interval (Support Points)
Use a Weighted Sum of These Points (Quadrature Weights)
Generally Quadrature Approximations Done on [1, +1].
_
+1
1
f()d =
N

i=1
w
i
f(
i
)
Interpolation
Function Values Given at Discrete Points (
1
, . . . ,
N
)
Need to Construct Continuous Approximation
f() F() =
N

i=1
c
i

i
()

i
() are Trial or Basis Functions
Copyright 20062012 Anil Vithala Rao Page 210
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Methods for Numerical Integration
Shooting and Multiple-Shooting Require Numerical Integration
Methods for Numerical Integration: Initial-Value Problems
Consider Integration from t
i
to t
i+1
p
i+1
= p
i
+
_
t
i+1
t
i
G(p, t)dt
Consider a Multi-Stage Method of The Form

j
= t
i
+ h
i

j
where 0
1

2

k
1 and 1 j k
Now Apply a Quadrature Formula of The Form
_
t
i+1
t
i
G(p)dt h
i
k

j=1

j
G
j
where G
j
= G(p
j
,
j
)
Copyright 20062012 Anil Vithala Rao Page 211
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Next Apply a Quadrature within a Quadrature of the Form
_

j
t
i
G(p)dt h
i
k

l=1

jl
G
l
for 1 j k
Popular Multi-Stage Methods: Runge-Kutta
p
i+1
= p
i
+ h
i
k

j=1

j
G
ij
where
G
ij
= G
__
p
i
+ h
i
k

l=1

jl
G
il
__
Copyright 20062012 Anil Vithala Rao Page 212
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Runge-Kutta Schemes Visualizable Using a Butcher Array

1

11

12

1k

2

21

22

2k
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

k

k1

k2

kk

1

2

k
Runge-Kutta Schemes Are
Explicit:
jl
= 0 for l j
Implicit: otherwise
Common Runge-Kutta Schemes
Euler Method (explicit, k = 1)
0 0
1
p
i+1
= p
i
+ h
i
G
i
Copyright 20062012 Anil Vithala Rao Page 213
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Trapezoidal Method (implicit, k = 2)
0 0 0
1 1/2 1/2
1/2 1/2
p
i+1
= p
i
+
1
2
h
i
(G
i
+G
i+1
)
Classical Runge-Kutta Method (explicit, k = 4)
0 0 0 0 0
1/2 1/2 0 0 0
1/2 0 1/2 0 0
1 0 0 1 0
1/6 1/3 1/3 1/6
k
1
= h
i
G
i
k
2
= h
i
G
_
p
i
+
1
2
k
1
, t
i
+
1
2
h
i
_
k
3
= h
i
G
_
p
i
+
1
2
k
2
, t
i
+
1
2
h
i
_
k
4
= h
i
G(p
i
+k
3
, t
i+1
)
Copyright 20062012 Anil Vithala Rao Page 214
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
p
i+1
= p
i
+
1
6
(k
1
+ 2k
2
+ 2k
3
+k
4
)
Hermite-Simpson (implicit, k = 3)
0 0 0 0
1/2 5/24 1/3 1/24
1 1/6 2/3 1/6
1/6 2/3 1/6
p =
1
2
(p
i
+p
i+1
) +
1
8
h
i
(G
i
G
i+1
)

G = G
_
p, t
i
+
1
2
h
i
_
p
i+1
= p
i
+
1
6
h
i
_
G
i
+ 4

G+G
i+1
_
Alternate Motivation for Runge-Kutta Methods
Suppose p(t) is approximated on [t
i
, t
i+1
] by the function p(t) as
p(t) p(t) =
m

k=1
a
k
(t t
i
)
k
where (a
0
, . . . , a
k
) are chosen such that p(t
i
) = p
i
Copyright 20062012 Anil Vithala Rao Page 215
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Choose a nite set of points
1
, . . . ,
k
, i.e.,

p(
j
) = G[p(
j
)]
Last equation is called a collocation condition
Thus, Runge-Kutta Methods are Collocation Methods
Three Common Forms of Collocation
Lobatto methods: both endpoints included in collocation
Radau methods: one endpoint included in collocation
Gauss methods: neither endpoint included in collocation
Examples of Dierent Forms of Collocation
Midpoint rule Gauss method
p
i+1
= p
i
+ h
i
G
_
1
2
(p
i
+p
i+1
) , t
i
+
1
2
h
1
_
Euler backward rule Radau method
p
i+1
= p
i
+ h
i
G
i+1
Hermite-Simpson (see above) Lobatto method
Copyright 20062012 Anil Vithala Rao Page 216
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Convergence Rate of Low-Order Integrators
2 2.5 3 4 5
4
6
8
10
12
l
o
g
1
0
E
r
r
o
r
log
10
Number of Approximating Intervals
3.5 4.5
Figure 2-3. Error vs. Number of Intervals for Trapezoid Rule Approximation of
Copyright 20062012 Anil Vithala Rao Page 217
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Gaussian Quadrature
Using Evenly Spaced Points = Poor Convergence of Integral
Alternative: Choose Points to Minimize Error in Quadrature
Approximation
Suppose We Want to Approximate
_
+1
1
g()d Using N Points. Then
_
+1
1
p()d
N

k=1
w
k
p(
k
)
Error in Quadrature Approximation, E(g)
E(g) =
_
+1
1
g()d
N

k=1
w
k
g(
k
)
Gaussian Quadature Points Chosen to Minimize E(p)
Question: Why Use Gaussian Quadrature Points for Collocation?
Answer: Exponential Convergence for Smooth Functions
Copyright 20062012 Anil Vithala Rao Page 218
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Family of Gaussian Quadrature Points
Let P
N
() Be the N
th
-Degree Legendre Polynomial
Gaussian Quadrature Collocation Points
Legendre-Gauss: Roots of P
N
()
Legendre-Gauss-Radau: Roots of P
N
() + P
N1
()
Legendre-Gauss-Lobatto: Roots of

P
N1
() Together with = 1 and
= +1
Exactness of Gaussian Quadrature Approximations
Legendre-Gauss (LG): polynomial of degree 2N 1
Legendre-Gauss-Radau (LGR): polynomial of degree 2N 2
Legendre-Gauss-Lobatto (LGL): polynomial of degree 2N 3
Copyright 20062012 Anil Vithala Rao Page 219
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Exactness of Gaussian Quadrature
Let
(
1
, . . . ,
N
) be the roots of P
N
()
g() be a polynomial of degree at most 2N 1
Will Show That
_
+1
1
g()d
is Exact if g() is a Polynomial of Degree at Most 2N 1
First, Because g() is a Polynomial of Degree at Most 2N 1, g() Can Be
Written as
g() = P
N
()f() + h()
Where f() and h() are Polynomials of Degree at most N 1
Then,
_
+1
1
g()d =
_
+1
1
(P
N
()f() + h()) d =
_
+1
1
P
N
()f()d+
_
+1
1
h()d
Copyright 20062012 Anil Vithala Rao Page 220
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Because f() is a Polynomial of Degree at Most N 1,
f() =
N1

i=0
c
i
P
i
(), P
i
() = i
th
Degree Legendre Polynomial
Next, P
N
() is Orthogonal to All Other Legendre Polynomials. Therefore
_
+1
1
P
N
()f()d =
_
+1
1
P
N
()
N1

i=0
c
i
P
i
()d
=
N1

i=0
c
i
_
+1
1
P
N
()P
i
()d = 0
Consequently,
_
+1
1
g()d =
_
+1
1
h()d
Recall Now that h() is
A Polynomial of Degree at Most N 1
Thus, h() can be decomposed in term of a basis of N Lagrange
Copyright 20062012 Anil Vithala Rao Page 221
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
polynomials that are each of degree N 1,
h() =
N

i=1
h(
i
)L
i
(), L
i
() =
N

j=1
i=j

j

j
Therefore,
_
+1
1
h()d =
N

i=1
_
+1
1
N

i=1
h(
i
)L
i
()d =
N

i=1
h(
i
)
_
+1
1
L
i
()d
Because g() = P
N
()f() + h() g(
i
) = P
N
(
i
)f(
i
) + h(
i
)
But P
N
(
i
)f(
i
) = 0 Because (
1
, . . . ,
N
) are the Roots of P
N
()
Consequently, g(
i
) = h(
i
)
Copyright 20062012 Anil Vithala Rao Page 222
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
We Then Obtain
_
+1
1
g()d =
_
+1
1
h()d =
N

i=1
h(
i
)
_
+1
1
L
i
()d
=
N

i=1
g(
i
)
_
+1
1
L
i
()d
=
N

i=1
w
i
g(
i
)
Where
w
i
=
_
+1
1
L
i
()d = Quadrature Weight
Thus,
_
+1
1
g()d =
N

i=1
w
i
g(
i
)
is Exact if g() is a Polynomial of Degree at Most 2N 1
Copyright 20062012 Anil Vithala Rao Page 223
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Accuracy of LGR and LGL Quadrature
Legendre-Gauss-Radau Quadrature
LGR Points: N 1 roots on (1, +1] of P
N
() + P
N1
(), Together
with
1
= 1
Because
1
= 1 is specied = have N 1 free points
Can use similar argument for LGR as was used for LG with following
changes
Given N 1 free points on (1, +1],
_
+1
1
g()d =
N

i=1
w
i
g(
i
),
1
= 1
is exact if g() is a polynomial of degree at most 2N 2
Legendre-Gauss-Lobatto Quadrature
LGL Points: N 2 roots on (1, +1) of

P
N
(), Together with
1
= 1
and
N
= +1
Because
1
= 1 and
N
= +1 are specied = have N 2 free points
Copyright 20062012 Anil Vithala Rao Page 224
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Can use similar argument for LGL as was used for LG with following
changes
Given N 2 free points on (1, +1),
_
+1
1
g()d =
N

i=1
w
i
g(
i
),
1
= 1
is exact if g() is a polynomial of degree at most 2N 3
Key Result: Given Desire to Approximate
_
+1
1
g()d via N Point
Quadrature,
LG quadrature is exact if g() is a polynomial of degree 2N 1 or less
LGR quadrature is exact if g() is a polynomial of degree 2N 2 or less
LGL quadrature is exact if g() is a polynomial of degree 2N 3 or less
Copyright 20062012 Anil Vithala Rao Page 225
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Formulae for LG, LGR, and LGL Quadrature Weights
LG
w
i
=
2
1
2
i

P
2
N
(
i
)
, i = 1, . . . , N
LGR
w
1
=
2
N
2
w
i
=
1
(1
i
)

P
2
N
1
(
i
)
LGL
w
1
= w
N
=
2
N(N1)
w
i
=
2
N(N1)P
2
N
1
(
i
)
Copyright 20062012 Anil Vithala Rao Page 226
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example of Exponential Convergence of Gaussian Quadrature
Approximate (/4)
_
+1
1
cos(/2)d (Exact Integral =1)
0


N
l
o
g
1
0
e
LG
LGR
LGL
2 4 6 8 10 12
-2
-4
-6
-8
-10
-12
-14
-16
Note: All Gaussian Quadrature Rules Convergence Exponentially
Copyright 20062012 Anil Vithala Rao Page 227
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Function Approximation and Interpolation
Solving Continuous-Time Problem Numerically
Continuous problem replaced with discrete approximation
Discrete approximation require that functions be approximated
Approximations generally computed using polynomials
In Principle, Any Polynomial Can Be Used
Practically, Easier to Utilize Lagrange Interpolating Polynomials
Copyright 20062012 Anil Vithala Rao Page 228
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Lagrange Interpolating Polynomials
Given Samples of a Function f(t) at Support Points (t
1
, . . . , t
N
)
Using (t
1
, . . . , t
N
), Construct N Lagrange Polynomials of Degree N 1
L
i
(t) =
N

k=1
k=i
t t
k
t
i
t
k
, (i = 1, . . . , N),
Isolation Property of Lagrange Interpolating Polynomials
L
i
(t
k
) =
_
_
_
1 , i = k
0 , i = k
Now Construct Interpolant for f(t) Using L
i
(t), (i = 1, . . . , N)
f(t)

f(t) =
N

i=1
c
i
L
i
() =c
i
= f(t
i
)
Consequently, Interpolated Value at Support Points = Function Value!
Copyright 20062012 Anil Vithala Rao Page 229
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Choice of Support Points for Lagrange Polynomials
Theoretically, Can Choose Any Values for (t
1
, . . . , t
N
)
Reality: Problems Arise When Support Points Not Chosen Well
Simplest Choice: Uniformly-Spaced Points
Consider the Following Function
f() =
1
1 + 25
2
, [1, +1]
Next Four Slides
8 and 32 uniformly-spaced points
8 and 32 Legendre-Gauss points
Uniformly-spaced = Runge phenomenon
Legendre-Gauss: Runge phenomenon disappears
Copyright 20062012 Anil Vithala Rao Page 230
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Behavior Using 8 Uniformly-Spaced Points
0
0 1 0.5 0.5
1
1
0.2
0.4
0.6
0.8
f ()

f ()
f
(

A 8 Uniform Support Points.


Copyright 20062012 Anil Vithala Rao Page 231
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Behavior Using 32 Uniformly-Spaced Points
0
0 1 0.5 0.5 1
200
400
600
800
200
f ()

f ()
f
(

B 32 Uniform Support Points.


Copyright 20062012 Anil Vithala Rao Page 232
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Behavior Using 8 LG Points
1.2
0.2
0
0 1 0.5 0.5
1
1
0.2
0.4
0.6
0.8
f ()
f
(

f ()
A 8 LG Support Points.
Copyright 20062012 Anil Vithala Rao Page 233
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Behavior Using 32 LG Points
0
0 1 0.5 0.5
1
1
0.2
0.4
0.6
0.8
f ()
f
(

f ()
B 32 LG Support Points.
Copyright 20062012 Anil Vithala Rao Page 234
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Motivation for a Pseudospectral Method
Gaussian Quadrature
High-accuracy approximation to integral
Small number of support points needed
Lagrange Interpolating Polynomials
Polynomial coecients = function values at support points
Poorly chosen support point = Runge phenomenon
Choose Gaussian quadrature points = no Runge phenomenon
Pseudospectral Method
Uses Gaussian quadrature points to approximate integral of a function
Employs Lagrange polynomials for function approximation
Next Part of Course: Foundations of Pseudospectral Methods
Copyright 20062012 Anil Vithala Rao Page 235
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part VI: Foundations of Pseudospectral Methods
Copyright 20062012 Anil Vithala Rao Page 236
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Pseudospectral Methods
Collocation Points are Nodes of a Gaussian Quadrature
_
1
1
f()d
N

k=1
w
i
f(
i
)
Basis Functions are Lagrange Polynomials
L
i
() =
N

j=M
j=i

j

j
, L
i
(
j
) =
_
_
_
0 , i = j
1 , i = j
=Isolation Property
Three Sets of Gaussian Quadrature Collocation Points
LG: strictly on open interval (1, +1)
LGR: half-open interval [1, +1) or (1, +1]
LGL: closed interval [1, +1]
High Accuracy+Low-Dimensionality
x() X() =
N

k=M
X
i
L
i
(), (M = 0 or M = 1)
Copyright 20062012 Anil Vithala Rao Page 237
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
X(
i
) = X
i
=Due to Isolation Property
Key Question: What is the Dierence Between LG, LGR, and LGL Points?
First Glance
All three Gaussian quadrature rules extremely accurate
Only dier by one polynomial degree LG LGR LGL
Obtain Exponential Convergence for Integral of a Smooth Function
Will Begin with Global Pseudospectral Methods
Simplied Problem Used to Develop Methods
Minimize the Cost Functional
J = (x(+1))
Dynamic Constraints
x = f (x, u)
Initial Condition
x(1) = x
0
Copyright 20062012 Anil Vithala Rao Page 238
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Schematic of Gaussian Quadrature Points
-1 -0.5 0 0.5 1
LG Points Include Neither Endpoint
LGR Points Include Endpoint = 1
Flipped LGR Points Include Endpoint = +1
LGL Points Include Both Endpoints = 1 and = +1

LGL
LGR
Flipped LGR
LG
Copyright 20062012 Anil Vithala Rao Page 239
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Notation and Conventions
This Presentation: Treat State and Control as Row Vectors
State, x() R
n
x() =
_
x
1
() x
n
()
_
Control, u() R
m
u() =
_
u
1
() u
m
()
_
Vectorization of State and Control Approximations
X
i:j
=
_

_
X
i
.
.
.
X
j
_

_
, U
i:j
=
_

_
U
i
.
.
.
U
j
_

_
Dierentiation Matrix: D
i:j
= Columns i Through j of D
D
i:j
=
_
D
i
D
j
_
Copyright 20062012 Anil Vithala Rao Page 240
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Optimal Control Functions Vectorized in Similar Manner
F
i:j
=
_

_
f (X
i
, U
i
)
.
.
.
f (X
j
, U
j
)
_

_
Notation is Similar To That Used for MATLAB Operations
For Example: DX Matrix-Vector Multiplication
Collocation Equations Can Then Be Written As
DX = F
Copyright 20062012 Anil Vithala Rao Page 241
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Gauss Pseudospectral Method (GPM)
State Approximation:
x() X() =

N
i=0
X
i
L
i
() =N
th
-Degree Polynomial
x(
k
)

X(
k
) =
N

i=0
X
i

L
i
(
k
) =
N

i=0
D
ki
X
i
=(N 1)
th
-Degree Polynomial
NLP:
minimize (X
N+1
)
subject to DX = F(X
LG
, U
LG
) , X
N+1
= X
0
+w
T
F(X
LG
, U
LG
),
X
0
= x
0
Can Divide D Into: D = [D
0
D
1:N
] where D
1:N
is Square
Have Proven Following Theorems About D Matrix for GPM
D
1:N
is Nonsingular
D
1
1:N
D
0
= 1
D
1
1:N
= A where A is the Gauss Integration Matrix
Copyright 20062012 Anil Vithala Rao Page 242
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Key Result: GPM is an Implicit Integration Method
X
LG
= 1X
0
+AF
LG
=IMPLICIT INTEGRAL FORM OF GPM
In Other Words
GPM Can Be Written in Either Dierential or Integral Form
Dierential Form Integral Form
GPM Is an Integral Method
Copyright 20062012 Anil Vithala Rao Page 243
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Radau Pseudospectral Method (RPM)
State Approximation:
x() X() =

N+1
i=1
X
i
L
i
() =N
th
-Degree Polynomial
x(
k
)

X(
k
) =
N

i=0
X
i

L
i
(
k
) =
N+1

i=1
D
ki
X
i
=(N1)
th
-Degree Polynomial
NLP:
minimize (X
N+1
)
subject to DX = F(X
LGR
, U
LGR
)
X
1
= x
0
Can Divide D Into: D = [D
1
D
2:N+1
] where D
2:N+1
is Square
Have Proven Following Theorems About D Matrix for RPM
D
2:N+1
is Nonsingular
D
1
2:N+1
D
1
= 1
D
1
2:N+1
= A where A is the Radau Integration Matrix
Copyright 20062012 Anil Vithala Rao Page 244
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Key Result: RPM is an Implicit Integration Method
X
2:N+1
= 1X
0
+AF
LGR
=IMPLICIT INTEGRAL FORM OF RPM
In Other Words
RPM Can Be Written in Either Dierential or Integral Form
Dierential Form Integral Form
RPM Is an Integral Method
Copyright 20062012 Anil Vithala Rao Page 245
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Structure Common to Both GPM and RPM
Right-Hand and Left-Hand Sides of Collocation Equations
Right-Hand Side Includes Only Collocation Points
Left-Hand Side: Includes Collocation Points Plus One Endpoint
Dierentiation Matrices Have One More Column Than Row
(Size= N (N + 1))
Key Property of GPM and RPM Dierentiation Matrices
Eliminating First Column, Remaining Square Matrix is Invertible
Remaining Square Matrix is the Integration Matrix
GPM/RPM are Integration Methods
Copyright 20062012 Anil Vithala Rao Page 246
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Why Choose Dierential Form Over Integral Form?
GPM/RPM are Integration Methods
Seems more natural to choose integral form
Why choose dierential form?
Answer: Dierential Form is Much More Sparse
Collocation Equations in Dierential Form
DX = F =Each Equation Involves Only One Value of Right-Hand Side
Collocation Equations in Integral Form
X = AF =Each Equation Involves All Values of Right-Hand Side
Dierential Form Computationally More Ecient
Copyright 20062012 Anil Vithala Rao Page 247
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Lobatto Pseudospectral Method (LPM)
State Approximation:
x() X() =

N
i=1
x
i
L
i
() =(N 1)
th
-Degree Polynomial
x(
k
) =
N

i=1
X
i

L
i
(
k
) =
N

i=1
D
ki
X
i
=(N 2)
th
-Degree Polynomial
LPM NLP:
minimize (X
N
)
subject to DX = F(X, U)
X
1
= x
0
LPM Dierentiation Matrix is Square and Singular
Integral and Dierential Form of LPM Not Equivalent = LPM Not an
Integration Method
Copyright 20062012 Anil Vithala Rao Page 248
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Comparison of GPM/RPM/LPM
Methods Appear Similar, But Appearances are Deceiving
Gauss and Radau Pseudospectral Methods
Polynomial Degree of X() = N (=Number of Collocation Points)
Non-Square and Full Rank Dierentiation Matrix
Dierential Form = Implicit Integral Form
Lobatto Pseudospectral Method (LPM)
Polynomial Degree of X() = N 1 (< Number of Collocation Points)
Square and Singular Dierentiation Matrix
Dierential Form = Implicit Integral Form
How Do These Dierences Play Out in Practice?
GPM/RPM State & Control Converge Much Faster Than LPM
On Even Simple Example, LPM Costate Does Not Converge
NLPs for GPM/RPM Can Be Smaller Than NLP for LPM
Copyright 20062012 Anil Vithala Rao Page 249
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Costate Estimation Using Pseudospectral Methods
GPM Costate

N+1
=
N+1
Costate at = +1

i
=
i
/w
i
+
N+1
Costate at LG Points

0
=
N+1
D
T
0

LG
Costate at = 1 Via Integral Approximation of

RPM Costate

i
=
i
/w
i
Costate at LGR Points

N+1
= D
T
N+1

LGR
Costate at = +1 Via Integral Approximation of

LPM Costate

i
=
i
/w
i
Costate at LGL Points
As with State Approximation,
GPM/RPM Endpoint Costate Obtained via Quadrature
LPM Costate Not Obtained via Numerical Integration!
Copyright 20062012 Anil Vithala Rao Page 250
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example
Minimize J = y(2)
Subject To The Dynamic Constraint y =
5
2
(y + yu u
2
)
Initial Condition: y(0) = 1
Optimal Solution:
y

(t) = 4/a(t),
u

(t) = y

(t)/2,

y
(t) = exp(2 ln(a(t)) 5t/2)/b,
a(t) = 1 + 3 exp(5t/2),
b = exp(5) + 6 + 9 exp(5).
Problem Solved Using GPM, RPM, and LPM for N = (5, 10, 15, 20, 25, 30).
Copyright 20062012 Anil Vithala Rao Page 251
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
State Errors Using GPM, RPM, and LPM
-2
-4
-6
-8
-10
-12
-14
-16
5 10 15 20 25 30
0
e
y
=
l
o
g
1
0
|
|
y
(

k
)

k
)
|
|

N
Gauss
Radau
Lobatto
Copyright 20062012 Anil Vithala Rao Page 252
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Control Errors Using GPM, RPM, and LPM
-2
-4
-6
-8
-10
-12
-14
-16
5 10 15 20 25 30
0
e
u
=
l
o
g
1
0
|
|
u
(

k
)

k
)
|
|

N
Gauss
Radau
Lobatto
Copyright 20062012 Anil Vithala Rao Page 253
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Costate Errors Using GPM, RPM, and LPM
-5
-10
-15
5
5
10
10 15 20 25 30
0
e

y
=
l
o
g
1
0
|
|

y
(

k
)

y
(

k
)
|
|

N
Gauss
Radau
Lobatto
Copyright 20062012 Anil Vithala Rao Page 254
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example
Minimize J = r(t
f
)
Subject To The Dynamic Constraints
r = v
r
,

= v

/r,
v
r
= v
2

/r /r
2
+ a sin ,
v

= v
r
v

/r + a cos ,
Boundary Conditions
(r(0), (0), v
r
(0), v

(0)) = (1, 0, 0, 1),


(v
r
(t
f
), v

(t
f
)) = (0,
_
/r(t
f
)),
Where
a a(t) =
T
m
0
| m|t
. (1)
Constants: = 1, T = 0.1405, m
0
= 1, m = 0.0749, and t
f
= 3.32.
Copyright 20062012 Anil Vithala Rao Page 255
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Costate Solution for N = 64 Using GPM
2.5
-1.5
-2
1.5
1.5 2 2.5 3 3.5
-1
-0.5
0
0
0.5
0.5
1
1

(
t
)
=
(

r
(
t
)
,

r
v
(
t
)
,

v
r
(
t
)
,

(
t
)
)
[
G
a
u
s
s
]
t (TU)

r
(t)

(t)

v
r
(t)

(t)
Copyright 20062012 Anil Vithala Rao Page 256
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Costate Solution for N = 64 Using RPM
2.5
-1.5
-2
1.5
1.5 2 2.5 3 3.5
-1
-0.5
0
0
0.5
0.5
1
1

(
t
)
=
(

r
(
t
)
,

r
v
(
t
)
,

v
r
(
t
)
,

(
t
)
)
[
R
a
d
a
u
]
)
t (TU)

r
(t)

(t)

v
r
(t)

(t)
Copyright 20062012 Anil Vithala Rao Page 257
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Costate Solution for N = 64 Using LPM
-2
-3
-4
1.5
2
2 2.5
3
3 3.5
4
-1
0
0 0.5
1
1

(
t
)
=
(

r
(
t
)
,

r
v
(
t
)
,

v
r
(
t
)
,

(
t
)
)
[
L
o
b
a
t
t
o
]
t (TU)

r
(t)

(t)

v
r
(t)

(t)
Copyright 20062012 Anil Vithala Rao Page 258
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Key Features of Solution Errors
Gauss and Radau State, Control, and Costate Converge Exponentially
Lobatto Scheme
State and control errors decrease at much slower rate than either Gauss
or Radau
Costate does not converge
Upshot of Examples
Gauss and Radau
Both are implicit Gaussian quadrature schemes
For a problem with smooth solution, Gauss quadrature converges
exponentially
Lobatto is not an implicit integration method
At best, converges much more slowly than either Gauss or Radau
Costate potentially nonconvergent
Copyright 20062012 Anil Vithala Rao Page 259
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part VII: Pseudospectral Method Implementation
Copyright 20062012 Anil Vithala Rao Page 260
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Use of Multiple-Interval Pseudospectral Methods
Global Collocation is Adequate for Simple Problems
Most Problems of Practical Interest
May Have Rapid Changes in Behavior
May Have Points of Nonsmoothness
For Such Problems, Global Collocation is Inadequate
Multiple-Interval Pseudospectral Methods
Time Interval t [t
0
, t
f
] Divided Into Mesh Intervals
Each Mesh Interval
Dierent Degree State Approximation
Dierent Width
Leads to hp-Adaptive Pseudospectral Methods
Copyright 20062012 Anil Vithala Rao Page 261
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Development of Multiple-Interval Formulation
Transformation of Time: t = (t
f
t
0
)s/2 + (t
f
+ t
0
)/2 where s [1, +1]
Minimize the Cost Functional
J = (x(1), t
0
, x(+1), t
f
) +
t
f
t
0
2
_
+1
1
L(x(s), u(s), s; t
0
, t
f
) ds
Dynamic Constraints
dx
ds
=
t
f
t
0
2
f (x(s), u(s), s; t
0
, t
f
),
Path Constraints
c
min
c(x(s), u(s), s; t
0
, t
f
) c
max
,
Boundary Conditions
b
min
b(x(1), t
0
, x(+1), t
f
) b
max
.
Copyright 20062012 Anil Vithala Rao Page 262
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Multiple-Interval Bolza Problem
Divide s [1, +1] into K Mesh Intervals [s
k1
, s
k
], k = 1, . . . , K
Mesh Points: 1 = s
0
< s
1
< s
2
< < s
K
= s
f
= +1.
Let x
(k)
(s) and u
(k)
(s) be the State and Control in mesh interval k.
Minimize the Cost Functional
J = (x
(1)
(1), t
0
, x
(K)
(+1), t
f
) +
t
f
t
0
2
K

k=1
_
s
k
s
k1
L(x
(k)
(), u
(k)
(), ; s
k1
, s
k
) d
Dynamic Constraints in Mesh Interval k = 1, . . . , K:
dx
(k)
(s)
ds
=
t
f
t
0
2
f (x
(k)
(s), u
(k)
(s), s; t
0
, t
f
)
Path Constraints
c
min
c(x
(k)
(s), u
(k)
(s), s; t
0
, t
f
) c
max
.
Boundary Conditions
b
min
b(x
(1)
(1), t
0
, x
(K)
(+1), t
f
) b
max
.
Continuity in State at Mesh Points: x(s

k
) = x(s
+
k
), be
Copyright 20062012 Anil Vithala Rao Page 263
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Choice of Multiple-Interval Pseudospectral Method
Gauss Pseudospectral Method (GPM)
Additional Quadrature Equation Required to Estimate Final State in a
Mesh Interval
Control at Mesh Point Not an NLP Variable
Lobatto Pseudospectral Method (LPM)
Contains Redundant State and Control at Mesh Point
Derivative Approximation at Mesh Point Inconsistent Between Adjacent
Mesh Intervals
Radau Pseudospectral Method (RPM)
No Redundancy in Control at Mesh Points
Overlap is Ideal for Multiple-Interval Formulation
Is Most Natural to Implement
Copyright 20062012 Anil Vithala Rao Page 264
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Schematic of Two-Interval GPM and RPM
GPM
First and Last
LG Points
First and Last
LG Points
No Value of Control
at Mesh Point
RPM
First and Last
LGR Points
First and Last
LGR Points
Control at
Mesh Point
Copyright 20062012 Anil Vithala Rao Page 265
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Observations of Structure GPM and RPM
GPM
Has elegant mathematical structure
Easy to see equivalence between direct and indirect forms
Unfortunately, dicult to use in multiple -interval form
RPM
Not intuitive, but shares same mathematical properties as GPM
As a result, actually is just as accurate as GPM
Is much more natural for multiple-interval use
Conclusion: Radau Method is Best Choice
Copyright 20062012 Anil Vithala Rao Page 266
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Multiple-Interval Radau Pseudospectral Method
State Approximation in Mesh Interval k [1, . . . , K]:
x
(k)
(s) X
(k)
(s) =
N
k
+1

j=1
X
(k)
j

(k)
j
(s),
(k)
j
(s) =
N
k
+1

l=1
l=j
s s
(k)
l
s
(k)
j
s
(k)
l
,
where (s
(k)
1
, . . . , s
(k)
N
k
) are the LGR Points in Mesh Interval k.
Derivative Approximation of State
dX
(k)
(s)
ds
=
N
k
+1

j=1
X
(k)
j
d
(k)
j
(s)
ds
.
Discrete Approximation of Cost Functional
J (X
(1)
1
, t
0
, X
(K)
N
K
+1
, t
K
) +
K

k=1
N
k

j=1
t
f
t
0
2
w
(k)
j
g(X
(k)
j
, U
(k)
j
, s
(k)
j
; s
k1
, s
k
),
w
(k)
j
= LGR Quadrature Weights (j = 1, . . . , N
k
)
U
(k)
j
= Control Approximations (j = 1, . . . , N
k
)
X
(k)
j
= State Approximations (j = 1, . . . , N
k
+ 1)
Copyright 20062012 Anil Vithala Rao Page 267
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Collocation Conditions
N
k
+1

j=1
D
(k)
ij
X
(k)
j

t
f
t
0
2
a(X
(k)
i
, U
(k)
i
, t
(k)
i
) = 0, (i = 1, . . . , N
k
).
where t = (t
f
t
0
)/2s + (t
f
+ t
0
)/2
Radau Dierentiation Matrix (N
k
(N
k
+ 1))
D
(k)
ij
=
_
_
d
(k)
j
(s)
ds
_
_
s
(k)
i
, (i = 1, . . . , N
k
, j = 1, . . . , N
k
+ 1, k = 1, . . . , K),
Path Constraints
c
min
c(X
(k)
i
, U
(k)
i
, t
(k)
i
) c
max
, (i = 1, . . . , N
k
).
Boundary Conditions
b
min
b(X
(1)
1
, t
0
, X
(K)
N
K
+1
, t
f
) b
max
.
State Continuity at Mesh Points
X
(k)
N
k
+1
= X
(k+1)
1
, (k = 1, . . . , K 1),
Copyright 20062012 Anil Vithala Rao Page 268
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Vectorized Form of Multiple-Interval Radau Method
Quantities in Each Mesh Interval
s
(k)
=

s
(k)
i

1
N
k
, k = 1, . . . , K 1 , s
(K)
=

s
(K)
i

1
N
K
+1
,
t
(k)
=

t
(k)
i

1
N
k
, k = 1, . . . , K 1 , t
(K)
=

t
(K)
i

1
N
K
+1
,
X
(k)
=

X
(k)
i

1
N
k
, k = 1, . . . , K 1 , X
(K)
=

X
(K)
i

1
N
K
+1
,
U
(k)
=

U
(k)
i

1
N
k
, k = 1, . . . , K , g
(k)
=

g(X
(k)
i
, U
(k)
i
, t
(k)
i
)

1
N
k
, k = 1, . . . , K
A
(k)
=

a(X
(k)
i
, U
(k)
i
, t
(k)
i
)

1
N
k
, k = 1, . . . , K , C
(k)
=

c(X
(k)
i
, U
(k)
i
, t
(k)
i
)

1
N
k
, k = 1, . . . , K
w
(k)
= [w
i
]
1
N
k
, k = 1, . . . , K , N =
K

k=1
N
k
.
Copyright 20062012 Anil Vithala Rao Page 269
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Cumulative Quantities
s =

s
(1)
.
.
.
s
(K)

, t =

t
(1)
.
.
.
t
(K)

,
w =

w
(1)
.
.
.
w
(K)

, X =

X
(1)
.
.
.
X
(K)

,
U =

U
(1)
.
.
.
U
(K)

, g =

g
(1)
.
.
.
g
(K)

,
A =

A
(1)
.
.
.
A
(K)

, C =

C
(1)
.
.
.
C
(K)

.
Vectorized Version of Cost
J (X
1
, t
0
, X
N+1
, t
f
) +
t
f
t
0
2
w
T
g
Copyright 20062012 Anil Vithala Rao Page 270
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Vectorized Version of Dynamics
= DX
t
f
t
0
2
A = 0,
Vectorized Version of Path Constraints
C
min
C C
max
Vectorized Version of Boundary Conditions
b
min
b(X
1
, t
0
, X
N+1
, t
f
) b
max
.
Copyright 20062012 Anil Vithala Rao Page 271
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Structure of Radau Pseudospectral Dierentiation Matrix
Block 1
Block 2
Block 3
Block K
(2) Zeros Except in Blocks
(1) Block k is of Size N
k
by N
k
+1
(3) Total Size N by N+1
Copyright 20062012 Anil Vithala Rao Page 272
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Key Features of Multiple-Interval Radau Method
Defect Constraints for Single Interval (Global) Method
Left-Hand Side: LGR Points + Final Point
Right-Hand Side: Only LGR Points
Dierentiation Matrix is Size N (N + 1)
Defect Constraints for Multiple Interval Method
Left-Hand Side: LGR Points in Each Mesh Interval + Final Point
Right-Hand Side: LGR Points in Each Mesh Interval
Dierentiation Matrix is Size N (N + 1) where
N =
K

k=1
N
k
Equations Have Identical Form for Both Global and Multiple Interval
Method
Copyright 20062012 Anil Vithala Rao Page 273
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Implementation of Radau Pseudospectral Method
Assume a Method with a Fixed Degree in Each Segment
Choose
Number of Segments, S
Let K = Number LGR Points on Each Segment
Then N = KS and N + 1 = KS + 1 =Total Number of Points
State Approximations at N LGR Points Plus Final Point
X =
_
_
_
_
_
_
_
_
x
1
x
2
.
.
.
x
N+1
_

_
Copyright 20062012 Anil Vithala Rao Page 274
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Control Approximation Includes Only LGR Points
U =
_
_
_
_
_
_
_
_
u
1
u
2
.
.
.
u
N
_

_
Treat t
0
and t
f
as Optimization Variables
Copyright 20062012 Anil Vithala Rao Page 275
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
LGR Points, Quadrature Weights, & Dierentiation Matrix
Compute LGR Points and Weights in Each Segment
[1, +1) = K LGR Points
W [1, +1) = K LGR Weights
Transform the LGR Points on [1, +1) to [s
k1
, s
k
] via
s =
s
k
s
k1
2
+
s
k
+ s
k1
2
.
Transform the LGR Weights on [1, +1) to [s
k1
, s
k
) via
w =
s
k
s
k1
2
W
Compute Dierentiation Matrix, d, on [1, +1)
Transform d from [1, +1) to D in s [s
k1
, s
k
) via
D =
2
s
k
s
k1
d
Copyright 20062012 Anil Vithala Rao Page 276
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
s R
N
, w R
N
, and D R
N(N+1)
Used to Construct NLP Functions
Construction of Objective Function
J = (X
1
, t
0
, X
N+1
, t
f
) +
t
f
t
0
2
N

k=1
w
i
L(X
k
, U
k
)
Construction of N Defect Constraints

i
=
N+1

j=1
D
ij
X
j

t
f
t
0
2
f (X
i
, U
i
) = 0, i = 1, . . . , N, k = 1, . . . , n
Note
Left-Hand Side of Defects: LGR Points Plus Final Point
N+1

j=1
D
ij
X
j
= Note That Summation Runs From 1 N + 1
Right-Hand Side of Defects: Only LGR Points
t
f
t
0
2
f (X
i
, U
i
) Note That i (1, . . . , N)
Copyright 20062012 Anil Vithala Rao Page 277
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Construction of NLP for SNOPT
SNOPT Needs Following Information
Bounds on NLP Variables and Constraints
Objective Function and Constraints File
Gradient of Objective and Jacobian of Constraints
Sparsity Pattern of Objective/Constraints
NLP Functions (Rows)
First Row for Objective Function Gradient
Discretized Continuous Functions: Defect and Path Constraints
Discretized Point Functions: Boundary Conditions
NLP Variables (Columns)
Components of State at LGR Points Plus Final Point
Components of Control at LGR Points Plus Final Point
Initial and Terminal Values of Time
Copyright 20062012 Anil Vithala Rao Page 278
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
More Details on Sparsity Pattern
Defect Constraints Consist of Main-Diagonals and O-Diagonals
Main Diagonal
Derivative of i
th
dierential equation with respect to i
th
state
Contains dierentiation matrix
O Diagonal
Derivative of i
th
dierential equation with respect to j
th
state (i = j)
Does Not Contain Dierentiation Matrix
Derivatives of Defects with Respect to Controls: Same as O-Diagonal
Defect
Derivatives of Path Constraints: Same as O-Diagonal Defect
Boundary Conditions: Only Derivatives with Respect to Endpoint Values
of State and Time
Copyright 20062012 Anil Vithala Rao Page 279
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Bounds on NLP Variables
Bounds on Variables Corresponding to State (LGR Points Plus Final Point)
x
0,min
X
1
x
0,max
Initial Condition=First LGR Point
x
min
X
2
x
max
First Interior Point
.
.
.
.
.
.
x
min
X
N
x
max
Last Interior Point=Last LGR Point
x
f,min
X
N+1
x
f,max
Terminal Point (Not an LGR Point)
Bounds on Variables Corresponding to Control
u
min
U
1
u
max
First LGR Point
.
.
.
u
min
U
N
u
max
Last LGR Point
Bounds on Initial and Terminal Time
t
0,min
t
0
t
0,max
Bounds on Initial Time
t
f,min
t
f
t
f,max
Bounds on Terminal Time
Copyright 20062012 Anil Vithala Rao Page 280
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Main Diagonal Block of Defect Constraint
Block 1
Nonlinear Element
Linear Element
Block 2
Block 3
Block K
Nonlinear Elements
Lie on Diagonal
of Dierentiation Matrix
First LGR Point No Collocation
Last LGR Point
Copyright 20062012 Anil Vithala Rao Page 281
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
O-Diagonal Block of Defect Constraint
First LGR Point No Collocation
Last LGR Point
Copyright 20062012 Anil Vithala Rao Page 282
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Path Constraints and Boundary Conditions
Path Constraints
Included Identically to O-Diagonals of Defect Constraints
Result: Path Constraint Sparsity Pattern is Purely Nonlinear
Boundary Conditions Are Functions of X
1
, X
N+1
, t
0
and t
f
Copyright 20062012 Anil Vithala Rao Page 283
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Path Constraint Sparsity Pattern Block
First LGR Point No Collocation
Last LGR Point
Copyright 20062012 Anil Vithala Rao Page 284
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Quantities on Diagonal Blocks
State Diagonal Blocks
_
D
1:N

t
f
t
0
2
diag
_
f
i
x
i
_
D
N+1
_
R
N(N+1)
State O-Diagonal Blocks
_

t
f
t
0
2
diag
_
f
i
x
j
_
0
_
R
N(N+1)
Control Blocks

t
f
t
0
2
diag
_
f
i
u
j
_
R
NN
State Path Blocks
_
diag
_
c
i
x
j
_
0
_
R
N(N+1)
Control Path Blocks
diag
_
c
i
u
j
_
R
NN
Copyright 20062012 Anil Vithala Rao Page 285
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Boundary Conditions With Respect to Initial and Terminal State
_
_
_
_
_
_
_
_
b
1
x
1
0
1(N1)
b
1
x
2
0
1(N1)
b
1
x
3
0
1(N1)
b
1
x
n
b
2
x
1
0
1(N1)
b
2
x
2
0
1(N1)
b
1
x
3
0
1(N1)
b
2
x
n
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
b
n
b
x
1
0
1(N1)
b
n
b
x
2
0
1(N1)
b
1
x
3
0
1(N1)
b
n
b
x
n
_

_
Final Two Columns for Derivatives With Respect to t
0
and t
f
Derivatives with Respect to t
0
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_

1
2
[f
1
]
1
N
+
t
f
t
0
2
f
1
t
0
.
.
.

1
2
[f
n
x
]
1
N
+
t
f
t
0
2
f
n
t
0
c
1
t
0
.
.
.
c
n
c
t
0
b
1
t
0
.
.
.
b
n
b
t
0
_

_
Copyright 20062012 Anil Vithala Rao Page 286
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Derivatives with Respect to t
f
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
1
2
[f
1
]
1
N
+
t
f
t
0
2
_
f
1
t
f
_
1
N
.
.
.
1
2
[f
n
]
1
N
+
t
f
t
0
2
_
f
n
t
f
_
1
N
c
1
t
f
.
.
.
c
n
c
t
f
b
1
t
f
.
.
.
b
n
b
t
f
_

_
Copyright 20062012 Anil Vithala Rao Page 287
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Complete Sparsity Pattern for RPM Constraint Jacobian
D
e
f
e
c
t

1
{ State 1 { State 2 { State ny
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k


Z
e
r
o
s

o
r

D
i
a
g
o
n
a
l
B
l
o
c
k
+
D
-
M
a
t
r
i
x


Z
e
r
o
s

o
r

D
i
a
g
o
n
a
l
B
l
o
c
k
+
D
-
M
a
t
r
i
x
{
D
e
f
e
c
t

2
{
D
e
f
e
c
t

n
y
{
{ Control 1 { Control nu
P
a
t
h

1
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
{
P
a
t
h

n
c
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
{
B
o
u
n
d
a
r
y
C
o
n
d
i
t
i
o
n
s
{
Either Zeros or
Endpoints only
Either Zeros or
Endpoints only
All Zeros
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k


Z
e
r
o
s

o
r

D
i
a
g
o
n
a
l
B
l
o
c
k
+
D
-
M
a
t
r
i
x
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
E
i
t
h
e
r

Z
e
r
o
s

o
r
D
i
a
g
o
n
a
l

B
l
o
c
k
t0 tf
Copyright 20062012 Anil Vithala Rao Page 288
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example 1
Minimize the Cost Functional
J =
1
2
_
t
f
t
0
(x
2
+ u
2
)dt
Dynamic Constraint
x = f(x, u) = x
3
+ u
Boundary Conditions
x(0) = x
0
(x
1
= x
0
)
x(t
f
) = x
f
(x
N+1
= x
f
)
This Example: t
0
and t
f
are Fixed
Copyright 20062012 Anil Vithala Rao Page 289
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Bounds on NLP Variables
Bounds on Variables Corresponding to State (LGR Points Plus Final Point)
x
0
x
1
x
0
Initial Condition=First LGR Point
x
min
x
2
x
max
First Interior Point
.
.
.
.
.
.
x
min
x
N
x
max
Last Interior Point=Last LGR Point
x
f
x
N+1
x
f
Terminal Point (Not an LGR Point)
Bounds on Variables Corresponding to Control
u
min
u
1
u
max
First LGR Point
.
.
.
u
min
u
N
u
max
Last LGR Point
Bounds on Initial and Terminal Time
t
0,min
t
0
t
0,max
t
f,min
t
f
t
f,max
Copyright 20062012 Anil Vithala Rao Page 290
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Sparsity Patterns for Hyper-Sensitive Problem
0 20 40 60 80 100 120 140 160 180
0
10
20
30
40
50
60
70
80
90
nz = 573
0 20 40 60 80 100 120 140 160 180
0
10
20
30
40
50
60
70
80
90
nz = 1805
Copyright 20062012 Anil Vithala Rao Page 291
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Example 2
Minimize the Cost Functional
J = r(t
f
)
Dynamic Constraints ( = 1)
r = u , u =
v
2
r


r
2
+
T
m
w
1
v =
uv
r
+
T
m
w
2
, m =
T
g
0
I
sp
Boundary Conditions
r(0) = r
0
= 1 , u(0) = 0
v(0) =
_
/r
0
= 1 , m(0) = 1
r(t
f
) = r
f
= 1 , u(t
f
) = 0
v(t
f
) =
_
/r
f
, m(t
f
) = FREE
Copyright 20062012 Anil Vithala Rao Page 292
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Mesh Renement
Usually Desire Solutions of a Specied Accuracy
Critical to Properly Choose Mesh Points and Number of Collocation Points
A Priori Knowledge Not Possible in General
Iterative Method Required to Construct Ecient Mesh
This Part of Course
Discussion of Mesh Renement Algorithm
Specically, will Discuss hpAdaptive Mesh Renement
Copyright 20062012 Anil Vithala Rao Page 293
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Concept of hpAdaptive Mesh Renement
Limitations with Global Pseudospectral Method
Accuracy Increased Simply By Increasing Degree of Global
Approximation
Computationally intractable as N increases due to global D Matrix
Error tolerance not achievable using global polynomial approximation
Need to Divide Time Interval Into Segments
Increases NLP sparsity
Makes high-accuracy solutions possible
Ecient Implementations of Methods Require Use of
As few mesh intervals as possible
The lowest possible polynomial degree approximation in each mesh
interval
Copyright 20062012 Anil Vithala Rao Page 294
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Generation of New Mesh
Mesh Iteration g
Mesh Iteration g+1
Mesh Points Added
to Improve Accuracy
Unnecessary Mesh
Points Deleted
New Mesh Generated to
Improve Solution Accuracy
Degree of Approximating Polynomial
in Each Mesh Interval May Change from
Grid g to Grid g+1
Copyright 20062012 Anil Vithala Rao Page 295
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Setting an Initial Mesh
Solution to General Problem Not Known A Priori
In Particular, Following are Not Known:
Regions where solution changes rapidly
Locations of discontinuities in control or state derivative
Strategy for Initial Mesh
Choose Small Number of Evenly Spaced Mesh Intervals
Use Low-Order Approximation in Each Interval
Strategy Enables Fast Computation of Solution on First Grid
Copyright 20062012 Anil Vithala Rao Page 296
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
How to Change or Add Mesh Intervals
Recall Terminology:
Mesh intervals [s
k1
, s
k
], k = 1, . . . , K
N
k
=degree of polynomial approximation in mesh interval k
Mesh Intervals Can Be Changed in One of Two Ways
Degree of polynomial approximation can be increased
Location of s
k1
and/or s
k
can be changed
Criteria for Changing Polynomial Degree N
k
Need to assess if solution in mesh interval k is smooth
If so, can use global polynomial approach and increase N
k
Criteria for Changing s
k1
and/or s
k
Need to assess if solution is either nonsmooth/rapidly changing
If so, need to determine locations where nonsmoothness occurs
Divide mesh interval at locations of predicted rapid changes
Copyright 20062012 Anil Vithala Rao Page 297
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Determining if a Mesh Interval Needs to Be Modied
Choose an Integer L
Let
_
s
(k)
1
, ..., s
(k)
L
_
Be Arbitrary Points in Mesh Interval k
Compute a Dierentiation Matrix,

D, Using
_
s
(k)
1
, ..., s
(k)
L
_
Compute x
i
(s) at
_
s
(k)
1
, ..., s
(k)
L
_
Using

D
Compute Error in Dynamic Constraints at
_
s
(k)
1
, ..., s
(k)
L
_

x
(k)
i
(

t
(k)
l
) f
(k)
i
(X
(k)
l
, U
(k)
l
,

t
(k)
l
)

= a
(k)
li
, i [1, . . . , L] j [1, . . . , n].
Use a
li
To Determine if Mesh in Interval k Should Be Modied
Copyright 20062012 Anil Vithala Rao Page 298
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Determining if a Mesh Interval Needs to Be Modied (Continued)
Let x
(k)
m
(s) Be Component of State with Largest Value of a
(k)
li
Let r
max
Be a User-Dened Parameter
Compute Curvature in Mesh Interval k

(k)
(s) =
| x
(k)
m
(s)|

_
1 + x
(k)
m
(s)
2
_
3/2

.
Let
(k)
max
=Maximum Curvature
Let
(k)
=Average Curvature
Let r
k
=
(k)
max
/
(k)
If r
k
< r
max
, Then Polynomial Degree N
k
Must Be Increased
If r
k
> r
max
, Then Mesh Interval Must Be Divided
Copyright 20062012 Anil Vithala Rao Page 299
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Increasing Degree of Polynomial or Rening Mesh
Increasing Polynomial Degree
New Polynomial Degree, N
k
, Computed As
N
k
= M +ceil(log
10
(e
(k)
max
/)) + 1
e
(k)
max
=Maximum Value of a
(k)
li
Rening Mesh
New Number of Mesh Intervals Computed As
n
k
= ceil(2 log
10
(e
(k)
max
/)),
Locations of New Mesh Points Determined from
Let () be given as
(s) = c(s)
1/3
,
where c is a constant chosen so that
_
+1
1
()d = 1.
Copyright 20062012 Anil Vithala Rao Page 300
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Let F() be given as
F(s) =
_
s
1
()d.
New Mesh Points, n
k
, Chosen So That
F(s
i
) =
i 1
n
k
, 1 i n
k
+ 1.
Copyright 20062012 Anil Vithala Rao Page 301
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
hpAdaptive Mesh Renement Algorithm
1. Solve the NLP using the current mesh.
Begin: For k = 1, . . . , K,
2. If e
(k)
max
, then continue (proceed to next k).
3. If either r
k
r
max
or N
k
> M, then rene the k
th
mesh interval into n
k
subintervals, Set the degree of the polynomials on each of the
subintervals to be M and proceed to the next k.
4. Otherwise, set the degree of the polynomials on the k
th
subinterval to
be N
k
.
End: For k = 1, . . . , K.
5. Return to Step 1 Until Error Tolerance is Met.
Copyright 20062012 Anil Vithala Rao Page 302
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Schematic of Algorithm to Solve Optimal Control Problem
Generate
New Mesh
Compute LGR Points, Weights,
and Dierentiation Matrices
Transcribe and
Solve NLP
Untranscribe NLP
Solution to Discrete
Optimal Control Problem
Solution
Meets Error
Tolerance?
YES NO
Quit
Copyright 20062012 Anil Vithala Rao Page 303
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Generation of Derivatives for NLP Solver
NLP Solvers Need Derivatives
Quasi-Newton NLP Solvers (e.g., SNOPT)
Objective Function Gradient
Constraint Jacobian
Typical Methods for Generating NLP Derivatives
Finite-Dierencing
Analytic Dierentiation
Automatic Dierentiation
Copyright 20062012 Anil Vithala Rao Page 304
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Generating NLP Derivatives for a Pseudospectral Method
Pseudospectral Methods Have Great Deal of Structure
Key Point: NLP Derivatives Can Be Computed Very Eciently
Suppose NLP Given in Following Form
Minimize f(z)
Constraints: h
min
h(z) h
max
Need to Compute
z
f and
z
h
Using Structure, Only Optimal Control Functions Need to Be Dierentiated
Details Provided in Recent Paper Accepted in Journal of Spacecraft and
Rockets
Copyright 20062012 Anil Vithala Rao Page 305
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Benet of Computing Derivative of Optimal Control Functions
Dierentiating NLP Functions Inecient and Memory Intensive
Optimal Control Functions Much Smaller Than NLP Functions
Each Collocation Condition: Only Involves One Value of Right-Hand Side
Optimal Control Functions Only Dierentiated at Collocation Points
Optimal Control Functions Can Be Dierentiated Using Any Technique
Finite-Dierencing
Complex-Step Derivative Approximation
Analytic Dierentiation
Automatic Dierentiation
Complex-Step is Best Choice
Produces Extremely Accurate First Derivative
Perfect for Quasi-Newton NLP Solver
Copyright 20062012 Anil Vithala Rao Page 306
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Complex-Step Derivative Approximation
Basic Idea: Given a Function of a Complex Variable z = x + iy
If f(z) = u(x, y) + iv(x, y) is Analytic, Then f(z) Satises
Cauchy-Riemann Equations
u
x
=
v
y
,
u
y
=
v
x
We Then Obtain Following Result (Where h is Real):
u
x
= lim
h0
v(x + i(y + h)) v(x + iy)
h
Setting y = 0, u(x) = f(x), and v(x) = 0, We Obtain
df
dx
= lim
h0
Im[f(x + ih)]
h
Therefore
df
dx

Im[f(x + ih)]
h
Notice That Approximation Has No Subtraction
Thus, Complex-Step Can Be Extremely Small
Copyright 20062012 Anil Vithala Rao Page 307
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Also, Derivative is Accurate to O(h
2
)
Easy to Implement on a Computer Using Complex Arithmetic
All Analytic Functions Dened for Complex Arguments
Must Avoid Non-Dierentiable Functions abs, max, and min
Copyright 20062012 Anil Vithala Rao Page 308
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Using Complex-Step in Pseudospectral Method
At Endpoints of Interval, Compute Derivative Approximations of
Mayer Cost
Boundary Conditions
At Collocation Points, Compute Derivative Approximations of
Lagrange cost
Right-hand side of dierential equations
Path constraints
Insert Optimal Control Derivatives Into NLP Derivative Functions
Copyright 20062012 Anil Vithala Rao Page 309
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
General Approach to Software Design
Suppose We Are Given Mesh Points (s
1
, . . . , s
K
) on s [1, +1]
Develop Following Subroutines First Given (s
1
, . . . , s
K
)
LGR Points, Weights, and Dierentiation Matrix
NLP Sparsity Pattern Generator
NLP Functions
Objective Function: Discrete Version of Bolza Cost
Constraint Function: Defects, Paths, Boundary Conditions
SNOPT Wrapper, Where SNOPT Calls Objective and Constaints
Repeat Above Steps
Using (s
1
, . . . , s
K
) computed from mesh renement
Until user-specied accuracy tolerance on mesh is met
Copyright 20062012 Anil Vithala Rao Page 310
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Part VIII: Wrap-Up
Copyright 20062012 Anil Vithala Rao Page 311
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Review of Topics Covered
Calculus of Variations
Optimal Control Theory
Nonlinear Optimization
Numerical Integration and Interpolation
Foundations of Pseudospectral Methods
Practical Implementation Using Radau Pseudospectral Method
Copyright 20062012 Anil Vithala Rao Page 312
May Be Redistributed Provided Copies Are Not Made for Prot or Direct Commercial Advantage
Summary
Numerical Methods for Dierential Equations
Single-Step Methods
Multiple-Step Methods
Multiple-Stage Methods
Explicit and Implicit Schemes
Explicit
Easier to Implement
Has Poorer Stability Properties
Implicit
More Work to Implement
Much Better Stability and Accuracy
Copyright 20062012 Anil Vithala Rao Page 313

Вам также может понравиться