0% found this document useful (0 votes)
2 views

02 Direct Methods

The document outlines direct methods for smooth nonlinear optimal control, focusing on continuous-time optimal control problems and their numerical solution techniques. It classifies optimal control methods into indirect and direct methods, detailing approaches like direct single shooting, direct collocation, and direct multiple shooting. The document also provides numerical examples and discusses the challenges and convergence issues associated with these methods.

Uploaded by

gminhhoang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

02 Direct Methods

The document outlines direct methods for smooth nonlinear optimal control, focusing on continuous-time optimal control problems and their numerical solution techniques. It classifies optimal control methods into indirect and direct methods, detailing approaches like direct single shooting, direct collocation, and direct multiple shooting. The document also provides numerical examples and discusses the challenges and convergence issues associated with these methods.

Uploaded by

gminhhoang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 163

2.

Direct methods for smooth nonlinear


optimal control
Armin Nurkanović

Systems Control and Optimization Laboratory, University of Freiburg, Germany


(slides create jointly with Moritz Diehl)

Winter School on Numerical Methods for Optimal Control of Nonsmooth Systems


École des Mines de Paris
February 3-5, 2025, Paris, France
Outline of the lecture

1 Overview of optimal control methods

2 Direct methods

3 Numerical simulation methods

4 Collocation methods

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 1/49
Continuous-time optimal control problems (OCP)

▶ decision variables x(·), u(·) in infinite


Continuous-time optimal control problem
dimensional function space
RT ▶ infinitely many constraints for t ∈ [0, T ]
min 0
L(x(t), u(t)) dt + E(x(T ))
x(·),u(·) ▶ smooth ordinary differential equations
s.t. x(0) = x̄0 (ODE)
ẋ(t) = f (x(t), u(t))
ẋ(t) = f (x(t), u(t))
0 ≥ h(x(t), u(t)), t ∈ [0, T ]
0 ≥ r(x(T )) ▶ dynamic model can be more general e.g.,
nonsmooth
▶ OCP can be convex or nonconvex

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 2/49
Classification of optimal control methods

Continuous-Time Optimal Control

Hamilton-Jacobi- Indirect Methods, Pontryagin: Direct Methods


Bellman Equation: Solve Boundary Transform into
Tabulation in State Space Value Problem Nonlinear Program (NLP)

Figure inspired by Figure 9.2. in Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2024

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 3/49
Classification of optimal control methods

Continuous-Time Optimal Control

Hamilton-Jacobi- Indirect Methods, Pontryagin: Direct Methods


Bellman Equation: Solve Boundary Transform into
Tabulation in State Space Value Problem Nonlinear Program (NLP)

Direct Single Shooting: Direct Collocation: Direct Multiple Shooting:


Only discretized con- Discretized controls and Controls and node start
trols in NLP (sequential) states in NLP (simultaneous) values in NLP (simultaneous)

Figure inspired by Figure 9.2. in Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2024

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 3/49
Classification of optimal control methods

Continuous-Time Optimal Control

Hamilton-Jacobi- Indirect Methods, Pontryagin: Direct Methods


Bellman Equation: Solve Boundary Transform into
Tabulation in State Space Value Problem Nonlinear Program (NLP)

Direct Single Shooting: Direct Collocation: Direct Multiple Shooting:


Only discretized con- Discretized controls and Controls and node start
trols in NLP (sequential) states in NLP (simultaneous) values in NLP (simultaneous)

▶ indirect methods: first optimize, then discretize


▶ direct methods: first discretize, then optimize
Figure inspired by Figure 9.2. in Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2024

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 3/49
Direct single shooting

▶ discretize controls u(t) ∈ Rnu on a fixed grid 0 = t0 < t1 < . . . < tN = T , and regard
x(t) as depended variables
▶ parametrize controls by q = (q0 , . . . , qN −1 ) ∈ RN ·Nu
▶ use numerical integration and obtain state x(t; q) as function of q
0.1

0.05

-0.05

-0.1
u(t)
-0.15 x(t)
-0.2

-0.25
0 0.5 1 1.5 2 2.5 3
t

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 4/49
Direct single shooting

NLP resulting from direct single shooting


Z T
min L(x(t; q), u(t; q)) dt + E(x(T ; q))
q∈RN ·nu 0
s.t. 0 ≥ h(x(ti ; q), u(ti ; q)), i = 1, . . . , N
0 ≥ r(x(T ; q))

▶ This is a standard NLP, can be solved with SQP or interior-point method


▶ Convergence can be difficult for unstable systems

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 5/49
Numerical example with single shooting

Z 3
min x(t)2 + u(t)3 dt
x(·),u(·) 0
s.t. x(0) = x0 (initial value)
ẋ(t) = (1 + x)x + u, t ∈ [0, 3] (ODE)
−1 ≤ x(t) ≤ 1, t ∈ [0, 3] (path constraint)
−1 ≤ u(t) ≤ 1, t ∈ [0, 3] (path constraint)
x(3) = 0. (terminal constraint)

▶ For (1 + x0 )x0 ≥ 1, i.e., x0 ≥ 0.618 uncontrollable growth


▶ Choose N = 15 equidistant control intervals
▶ Initialize with steady state control u(t) = 0
▶ Initial value x0 = 0.05 (for higher value trajectory explodes)
▶ Solve OCP with IPOPT via CasADi

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 6/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
initialization

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
1st iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
2nd iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
3rd iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
4th iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
5th iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
10th iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
15th iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
20th iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Numerical example with single shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
23rd iteration - converged!

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 7/49
Direct multiple shooting

▶ discretize controls u(t) ∈ Rnu on a fixed grid 0 = t0 < t1 < . . . < tN = T


▶ parametrize controls by u = (u0 , . . . , uN −1 ) ∈ RN ·nu
▶ numerically solve ODE ẋ(t) = fc (x(t), un ) on each [tn , tn+1 ] with artificial initial value
x(tn ) = xn
▶ new degrees of freedom: x = (x0 , . . . , xN ) ∈ R(N +1)·nx
0.1

0.05

-0.05

-0.1

-0.15
u(t)
x(t)
-0.2
0 0.5 1 1.5 2 2.5 3
t
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 8/49
Direct multiple shooting

Continuous time OCP


RT
min 0
L(x(t), u(t)) dt + E(x(T ))
x(·),u(·)

s.t. x(0) = x̄0


ẋ(t) = f (x(t), u(t))
0 ≥ h(x(t), u(t)), t ∈ [0, T ]
0 ≥ r(x(T ))

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting

1. Parametrize controls, e.g.


Continuous time OCP
u(t) = un , t ∈ [tn , tn+1 ].
RT
min 0
L(x(t), u(t)) dt + E(x(T ))
x(·),u(·)

s.t. x(0) = x̄0


ẋ(t) = f (x(t), u(t))
0 ≥ h(x(t), u(t)), t ∈ [0, T ]
0 ≥ r(x(T ))

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting

1. Parametrize controls, e.g.


Continuous time OCP
u(t) = un , t ∈ [tn , tn+1 ].
min
RT
L(x(t), u(t)) dt + E(x(T )) 2. Discretize cost and dynamics via numerical
0
x(·),u(·) simulation method
s.t. x(0) = x̄0 Z tn+1
ẋ(t) = f (x(t), u(t)) Ld (xn , un ) = L(x(t), u(t)) dt.
tn
0 ≥ h(x(t), u(t)), t ∈ [0, T ]
0 ≥ r(x(T )) Replace ẋ = f (x, u) by

xn+1 = ψf (xn , un )

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting

1. Parametrize controls, e.g.


Continuous time OCP
u(t) = un , t ∈ [tn , tn+1 ].
min
RT
L(x(t), u(t)) dt + E(x(T )) 2. Discretize cost and dynamics via numerical
0
x(·),u(·) simulation method
s.t. x(0) = x̄0 Z tn+1
ẋ(t) = f (x(t), u(t)) Ld (xn , un ) = L(x(t), u(t)) dt.
tn
0 ≥ h(x(t), u(t)), t ∈ [0, T ]
0 ≥ r(x(T )) Replace ẋ = f (x, u) by

xn+1 = ψf (xn , un )

3. Relax path constraints, e.g., evaluate only


at t = tn

0 ≥ h(xn , un ), n = 0, . . . N − 1.

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct multiple shooting

Continuous time OCP


Discrete time OCP (an NLP)
RT
min 0
L(x(t), u(t)) dt + E(x(T )) PN −1
x(·),u(·)
min k=0 Ld (xk , uk ) + E(xN )
x,u
s.t. x(0) = x̄0
ẋ(t) = f (x(t), u(t)) s.t. x0 = x̄0
0 ≥ h(x(t), u(t)), t ∈ [0, T ] xn+1 = ψf (xn , un )
0 ≥ r(x(T )) 0 ≥ h(xn , un ), n = 0, . . . , N −1
0 ≥ r(xN )

Variables x = (x0 , . . . , xN ), and


u = (u0 , . . . , uN −1 ).

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 9/49
Direct optimal control methods solve Nonlinear Programs (NLP)

Discrete time OCP (an NLP)


PN −1
min k=0 Ld (xk , uk ) + E(xN )
x,u

s.t. x0 = x̄0
xn+1 = ψf (xn , un )
0 ≥ h(xn , un ), n = 0, . . . , N −1
0 ≥ r(xN )

Variables w = (x, u)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 10/49
Direct optimal control methods solve Nonlinear Programs (NLP)

Discrete time OCP (an NLP) Nonlinear Program (NLP)


PN −1
min k=0 Ld (xk , uk ) + E(xN )
x,u min F (w)
w∈Rnx
s.t. x0 = x̄0
s.t. G(w) = 0
xn+1 = ψf (xn , un )
H(w) ≥ 0
0 ≥ h(xn , un ), n = 0, . . . , N −1
0 ≥ r(xN )
Obtain larger but sparse
NLP
Variables w = (x, u)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 10/49
Numerical example with multiple shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
initialization

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
1st iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
2nd iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
3rd iteration

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Numerical example with multiple shooting: iterations

1 1

0.5 0.5
u(t)

x(t)
0 0

-0.5 -0.5

-1 -1

0 1 2 3 0 1 2 3
t t
5th iteration - converged!

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 11/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers
+ few degrees of freedom even for large - more optimization variables, but fixed
ODE/DAE systems dimension

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers
+ few degrees of freedom even for large - more optimization variables, but fixed
ODE/DAE systems dimension
+ need only initial guess for controls u + can pass initial guess for controls u

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers
+ few degrees of freedom even for large - more optimization variables, but fixed
ODE/DAE systems dimension
+ need only initial guess for controls u + can pass initial guess for controls u
- cannot use knowledge of x in initialization + can use knowledge of x in initialization

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers
+ few degrees of freedom even for large - more optimization variables, but fixed
ODE/DAE systems dimension
+ need only initial guess for controls u + can pass initial guess for controls u
- cannot use knowledge of x in initialization + can use knowledge of x in initialization
- ODE solution can depend very non-linearly + usually less nonlinear = faster
on u convergence)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers
+ few degrees of freedom even for large - more optimization variables, but fixed
ODE/DAE systems dimension
+ need only initial guess for controls u + can pass initial guess for controls u
- cannot use knowledge of x in initialization + can use knowledge of x in initialization
- ODE solution can depend very non-linearly + usually less nonlinear = faster
on u convergence)
- unstable systems difficult to treat + unstable systems easier to treat

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers
+ few degrees of freedom even for large - more optimization variables, but fixed
ODE/DAE systems dimension
+ need only initial guess for controls u + can pass initial guess for controls u
- cannot use knowledge of x in initialization + can use knowledge of x in initialization
- ODE solution can depend very non-linearly + usually less nonlinear = faster
on u convergence)
- unstable systems difficult to treat + unstable systems easier to treat
- difficult to parallelize + easy to parallelize

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Single vs multiple shooting: pros and cons

Single shooting: sequential optimization and Multiple shooting: simultaneous optimization


simulation: and simulation:
+ use state-of-the-art ODE/DAE solvers + use state-of-the-art ODE/DAE solvers
+ few degrees of freedom even for large - more optimization variables, but fixed
ODE/DAE systems dimension
+ need only initial guess for controls u + can pass initial guess for controls u
- cannot use knowledge of x in initialization + can use knowledge of x in initialization
- ODE solution can depend very non-linearly + usually less nonlinear = faster
on u convergence)
- unstable systems difficult to treat + unstable systems easier to treat
- difficult to parallelize + easy to parallelize
- often used in prototype engineering + used in many great software packages:
implementations MUSCOD-II, ACADO, acados

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 12/49
Work flow in smooth direct optimal control
First discretize, then optimize.

Single shooting
SQP

Integrator
OCP Multiple shooting NLP

Direct IPM
transcription

Problem formulation Time discretization Optimization


OCP = Optimal Control Problem SQP = Sequential Quadratic Programming
NLP = Nonlinear Program IPM = Interior-Point Method
Figure inspired by Lecture 1, Numerical Methods for Optimal Control: Introduction, 2022, by Mario Zanon and Sébastien Gros.
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 13/49
Outline of the lecture

1 Overview of optimal control methods

2 Direct methods

3 Numerical simulation methods

4 Collocation methods

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 14/49
Ordinary differential equations and controlled dynamical system

Let:
▶ t ∈ R be the time
▶ x(t) ∈ Rnx the differential states
▶ u(t) ∈ Rnu a given control function
▶ denote by ẋ(t) = dx(t)
dt

Ordinary differential equations

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 15/49
Ordinary differential equations and controlled dynamical system

Let:
▶ t ∈ R be the time
▶ x(t) ∈ Rnx the differential states
▶ u(t) ∈ Rnu a given control function
▶ denote by ẋ(t) = dx(t)
dt

Ordinary differential equations


▶ Let F : R × Rnx × Rnx × Rnu → Rnx be a function such that the Jacobian ∂F
∂ ẋ (·) is
invertible. The system of equations:

F (t, ẋ(t), x(t), u(t)) = 0,

is called an Ordinary Differential Equation (ODE).

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 15/49
Ordinary differential equations and controlled dynamical system

Let:
▶ t ∈ R be the time
▶ x(t) ∈ Rnx the differential states
▶ u(t) ∈ Rnu a given control function
▶ denote by ẋ(t) = dx(t)
dt

Ordinary differential equations


▶ Let F : R × Rnx × Rnx × Rnu → Rnx be a function such that the Jacobian ∂F
∂ ẋ (·) is
invertible. The system of equations:

F (t, ẋ(t), x(t), u(t)) = 0,

is called an Ordinary Differential Equation (ODE).


▶ Given a function f : R × Rnx × Rnu → Rnx then a system of equations:

ẋ(t) = f (t, x(t), u(t)) (1)

is called an explicit ODE.


02. Direct methods for smooth nonlinear optimal control A. Nurkanović 15/49
Sufficient conditions for existence and uniqueness

Theorem (Picard-Lindelöf / Cauchy–Lipschitz )

An initial value problem in ODE

ẋ(t) = f (t, x(t), u(t)), t ∈ [0, T ],


x(0) = x0
▶ with given initial state x0 , and controls u(t),
▶ f (t, x(t), u(t)) = fˆ(t, x(t)) is continuous in t and Lipschitz continuous in x

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 16/49
Sufficient conditions for existence and uniqueness

Theorem (Picard-Lindelöf / Cauchy–Lipschitz )

An initial value problem in ODE

ẋ(t) = f (t, x(t), u(t)), t ∈ [0, T ],


x(0) = x0
▶ with given initial state x0 , and controls u(t),
▶ f (t, x(t), u(t)) = fˆ(t, x(t)) is continuous in t and Lipschitz continuous in x
has a unique solution x(t), t ∈ [0, T ].

▶ f is Lipschitz if ∥f (x) − f (y)∥ ≤ L∥x − y∥


▶ smooth ODEs modeling physics usually Lipschitz

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 16/49
Sufficient conditions for existence and uniqueness

Theorem (Picard-Lindelöf / Cauchy–Lipschitz )

An initial value problem in ODE

ẋ(t) = f (t, x(t), u(t)), t ∈ [0, T ],


x(0) = x0
▶ with given initial state x0 , and controls u(t),
▶ f (t, x(t), u(t)) = fˆ(t, x(t)) is continuous in t and Lipschitz continuous in x
has a unique solution x(t), t ∈ [0, T ].

▶ f is Lipschitz if ∥f (x) − f (y)∥ ≤ L∥x − y∥


▶ smooth ODEs modeling physics usually Lipschitz
▶ if f is only continuous, existence but not uniqueness can be guaranteed, e.g.
p 2
ẋ(t) = |x(t)|, x(0) = 0, solutions: x(t) = 0 and x(t) = t4

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 16/49
Sufficient conditions for existence and uniqueness

Theorem (Picard-Lindelöf / Cauchy–Lipschitz )

An initial value problem in ODE

ẋ(t) = f (t, x(t), u(t)), t ∈ [0, T ],


x(0) = x0
▶ with given initial state x0 , and controls u(t),
▶ f (t, x(t), u(t)) = fˆ(t, x(t)) is continuous in t and Lipschitz continuous in x
has a unique solution x(t), t ∈ [0, T ].

▶ f is Lipschitz if ∥f (x) − f (y)∥ ≤ L∥x − y∥


▶ smooth ODEs modeling physics usually Lipschitz
▶ if f is only continuous, existence but not uniqueness can be guaranteed, e.g.
p 2
ẋ(t) = |x(t)|, x(0) = 0, solutions: x(t) = 0 and x(t) = t4
▶ Conditions are only sufficient, ODEs with a non-Lipschitz r.h.s. can have unique solutions
A collection of results in: Agarwal, Ratan Prakash, Ravi P. Agarwal, and V. Lakshmikantham. Uniqueness and
nonuniqueness criteria for ordinary differential equations. Vol. 6. World Scientific, 1993.
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 16/49
Basic definitions of numerical simulation

▶ IVPs have only in special cases a closed form solution


▶ Instead, compute numerically a solution approximation x̃(t) that approximately satisfies:

˙
x̃(t) ≈ f (t, x̃(t), u(t)), t ∈ [0, T ]
x̃(0) = x(0) = x0

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 17/49
Basic definitions of numerical simulation

▶ IVPs have only in special cases a closed form solution


▶ Instead, compute numerically a solution approximation x̃(t) that approximately satisfies:

˙
x̃(t) ≈ f (t, x̃(t), u(t)), t ∈ [0, T ]
x̃(0) = x(0) = x0

▶ Recursively generate solution approximation xn := x̃(tn ) ≈ x(tn ) at N discrete time


points 0 = t0 < t1 < . . . < tN = T
▶ Integration interval [0, T ] split into subintervals [tn , tn+1 ] where h = tn+1 − tn
▶ h - integration step size can be constant, different for every interval, or adaptive

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 17/49
Single step numerical simulation as discrete time system

Single step abstract integration method

xn+1 = ϕf (xn , zn , un ),
0 = ϕint (xn , zn , un ), n = 0, . . . , N − 1.

▶ ϕf - state transition - compute next integration step


▶ ϕint - internal computations, e.g., stages of a Runge-Kutta method (next section)
▶ zn collects all interval variables of the integration method

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 18/49
Single step numerical simulation as discrete time system

Single step abstract integration method

xn+1 = ϕf (xn , zn , un ),
0 = ϕint (xn , zn , un ), n = 0, . . . , N − 1.

▶ ϕf - state transition - compute next integration step


▶ ϕint - internal computations, e.g., stages of a Runge-Kutta method (next section)
▶ zn collects all interval variables of the integration method

Example (Explicit Euler):

xn+1 = xn + hf (xn , un ),

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 18/49
Single step numerical simulation as discrete time system

Single step abstract integration method

xn+1 = ϕf (xn , zn , un ),
0 = ϕint (xn , zn , un ), n = 0, . . . , N − 1.

▶ ϕf - state transition - compute next integration step


▶ ϕint - internal computations, e.g., stages of a Runge-Kutta method (next section)
▶ zn collects all interval variables of the integration method

Example (Explicit Euler):

xn+1 = xn + hzn ,
0 = f (xn , un ) − zn .

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 18/49
Integration error

Local and global error


20
Exact solution
▶ Local integration error at tn+1 : 18
Numerical simulation
16 Locally exact solution
e(tn+1 ) = ∥x(tn+1 ) − ϕf (x(tn ), zn , u0 )∥. 14

12

x(t)
10

2
e(t1 )
0
0 0.2 0.4 0.6 0.8 1 1.2
t

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error

Local and global error


20
Exact solution
▶ Local integration error at tn+1 : 18
Numerical simulation
16 Locally exact solution
e(tn+1 ) = ∥x(tn+1 ) − ϕf (x(tn ), zn , u0 )∥. 14

12

x(t)
10

2 e(t2 )
0
0 0.2 0.4 0.6 0.8 1 1.2
t

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error

Local and global error


20
Exact solution
▶ Local integration error at tn+1 : 18
Numerical simulation
16 Locally exact solution
e(tn+1 ) = ∥x(tn+1 ) − ϕf (x(tn ), zn , u0 )∥. 14

12

x(t)
10

4
e(t3 )
2

0
0 0.2 0.4 0.6 0.8 1 1.2
t

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error

Local and global error


20
Exact solution
▶ Local integration error at tn+1 : 18
Numerical simulation
16 Locally exact solution
e(tn+1 ) = ∥x(tn+1 ) − ϕf (x(tn ), zn , u0 )∥. 14

12

x(t)
10

6 e(t4 )
4

0
0 0.2 0.4 0.6 0.8 1 1.2
t

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Integration error

Local and global error


20
Exact solution
▶ Local integration error at tn+1 : 18
Numerical simulation
16 Locally exact solution
E(T )
e(tn+1 ) = ∥x(tn+1 ) − ϕf (x(tn ), zn , u0 )∥. 14

12
▶ Global integration error at t = T :

x(t)
10 e(t5 )
8
E(T ) = ∥x(T ) − xN ∥.
6

▶ Global error - accumulation of local 0


0 0.2 0.4 0.6 0.8 1 1.2

errors t

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 19/49
Convergence and integrator order

Integrator convergence and accuracy


10 -2

▶ Convergence
10 -4

lim E(T ) = 0 10 -6
h→0

E(T )
▶ Integrator has order p if 10 -8

10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order

Integrator convergence and accuracy


10 -2

▶ Convergence
10 -4

lim E(T ) = 0 10 -6
h→0

E(T )
▶ Integrator has order p if 10 -8

10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order

Integrator convergence and accuracy


10 -2

▶ Convergence
10 -4

lim E(T ) = 0 10 -6
h→0

E(T )
▶ Integrator has order p if 10 -8

10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order

Integrator convergence and accuracy


10 -2

▶ Convergence
10 -4

lim E(T ) = 0 10 -6
h→0

E(T )
▶ Integrator has order p if 10 -8

10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order

Integrator convergence and accuracy


10 -2

▶ Convergence
10 -4

lim E(T ) = 0 10 -6
h→0

E(T )
▶ Integrator has order p if 10 -8

10 -10
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 Explicit Euler O(h)
10 -12 RK2 O(h2 )
RK4 O(h4 )
▶ Higher order p: 10 -14
10 -2 10 -1
▶ less, but more expensive steps for h
same accuracy
▶ in total fewer r.h.s. evaluations for
same accuracy

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Convergence and integrator order

10 -2
Integrator convergence and accuracy
10 -4
▶ Convergence
10 -6
lim E(T ) = 0

E(T )
h→0 10 -8

▶ Integrator has order p if


10 -10

Explicit Euler O(h)


lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0 10
-12
RK2 O(h2 )
h→0
RK4 O(h4 )
-14
10
1 2
10 10
▶ Higher order p: N
▶ less, but more expensive steps for
Alternatively one can plot the error over
same accuracy N ∝ h1 instead of h
▶ in total fewer r.h.s. evaluations for
same accuracy

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 20/49
Stability and convergence

1.5

Integrator convergence and accuracy Explicit Euler


Implicit Euler
▶ Convergence 10 5
O(h)

1
lim E(T ) = 0
h→0

E(T )
x(t)
0
10

▶ Integrator has order p if


0.5

lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0 10


-5
h→0

▶ Stability: damping of errors, does it


0
work for h ≫ 0? 0 0.5 1 1.5 10
-2
10
-1

t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
small x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Stability and convergence

h = 0:1
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10 5
O(h)

1
lim E(T ) = 0
h→0

E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5

▶ Stability: damping of errors, does it


work for h ≫ 0? 0
0 0.5 1 1.5 2 10 -2 10 -1
t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very
small ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
x(0) = 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Stability and convergence

h = 0:05
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10 5
O(h)

1
lim E(T ) = 0
h→0

E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5

▶ Stability: damping of errors, does it


work for h ≫ 0? 0
0 0.5 1 1.5 2 10 -2 10 -1
t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very
small ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
x(0) = 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Stability and convergence

h = 0:0125
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10 5
O(h)

1
lim E(T ) = 0
h→0

E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5

▶ Stability: damping of errors, does it


work for h ≫ 0? 0
0 0.5 1 1.5 2 10 -2 10 -1
t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very
small ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
x(0) = 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Stability and convergence

h = 0:00625
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10
5 O(h)

1
lim E(T ) = 0
h→0

E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5

▶ Stability: damping of errors, does it


work for h ≫ 0? 0
0 0.5 1 1.5 -2 -1
10 10
t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
small
x(0) = 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Stability and convergence

h = 0:003125
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10
5 O(h)

1
lim E(T ) = 0
h→0

E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5

▶ Stability: damping of errors, does it


work for h ≫ 0? 0
0 0.5 1 1.5 -2 -1
10 10
t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
small
x(0) = 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Stability and convergence

h = 0:0015625
1.5
Integrator convergence and accuracy Explicit Euler
Implicit Euler
▶ Convergence 10
5 O(h)

1
lim E(T ) = 0
h→0

E(T )
x(t)
10 0
▶ Integrator has order p if
0.5
lim e(ti ) ≤ Chp+1 = O(hp+1 ), C > 0
h→0 10 -5

▶ Stability: damping of errors, does it


work for h ≫ 0? 0
0 0.5 1 1.5 -2 -1
10 10
t h
▶ If integrator is unstable, it does not
converge and has p = 0, unless h very ẋ(t) = −300(x(t) − cos(t)), t ∈ [0, 2]
small
x(0) = 1
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 21/49
Classes of numerical simulation methods

General Linear Methods

Multi Step Single Step

Linear Multi-Step Runge-Kutta


Methods Methods

Explicit Implicit Explicit Implicit

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 22/49
Runge-Kutta method definition
Unknowns are derivatives at stage points

Definition (Runge-Kutta method in differential form)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h. The system of equations:
ns
X
kn,i = f (tn,i , xn + h ai,j kn,j , un ), i = 1, . . . , ns
j=1
ns
X
xn+1 = xn + h bi kn,i
i=1

is called a ns -stage Runge-Kutta (RK) method in the differential form.

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points

Definition (Runge-Kutta method in differential form)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h. The system of equations:
ns
X
kn,i = f (tn,i , xn + h ai,j kn,j , un ), i = 1, . . . , ns
j=1
ns
X
xn+1 = xn + h bi kn,i
i=1

is called a ns -stage Runge-Kutta (RK) method in the differential form.


x0 x1 x2 x3
t
t0 t1 t2 t3

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points

Definition (Runge-Kutta method in differential form)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h. The system of equations:
ns
X
kn,i = f (tn,i , xn + h ai,j kn,j , un ), i = 1, . . . , ns
j=1
ns
X
xn+1 = xn + h bi kn,i
i=1

is called a ns -stage Runge-Kutta (RK) method in the differential form.


x0 x1 x2 x3
t
t0 t0,1 t0,2 . . . t0,ns t1 t2 t3

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points

Definition (Runge-Kutta method in differential form)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h. The system of equations:
ns
X
kn,i = f (tn,i , xn + h ai,j kn,j , un ), i = 1, . . . , ns
j=1
ns
X
xn+1 = xn + h bi kn,i
i=1

is called a ns -stage Runge-Kutta (RK) method in the differential form.

x0 x1 k1,1 k1,2 . . . k1,ns x2 x3


t
t0 t0,1 t0,2 . . . t0,ns t1 t2 t3

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method definition
Unknowns are derivatives at stage points

Definition (Runge-Kutta method in differential form)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h. The system of equations:
ns
X
kn,i = f (tn,i , xn + h ai,j kn,j , un ), i = 1, . . . , ns
j=1
ns
X
xn+1 = xn + h bi kn,i
i=1

is called a ns -stage Runge-Kutta (RK) method in the differential form.

Time grid Butcher tableau Data Variables


h, tn , tn,i ai,j , bi , ci xn , un , f (·) xn+1 , kn,i
i = 1, . . . , ns i, j = 1, . . . , ns i = 1, . . . , ns

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 23/49
Runge-Kutta method examples

Explicit Runge-Kutta 4

kn,1 = f (tn , xn )
h kn,1
kn,2 = f (tn + , xn + h )
2 2
h kn,2
kn,3 = f (tn + , xn + h )
2 2
kn,5 = f (tn + h, xn + hkn,3 )
1 2 2 1
xn+1 = xn + h( kn,1 + kn,2 + kn,3 + kn,4 )
6 6 6 6

▶ All kn,i can be found by explicit function


evaluations.

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 24/49
Runge-Kutta method examples

Explicit Runge-Kutta 4

Implicit Euler Method


kn,1 = f (tn , xn )
h kn,1
kn,2 = f (tn + , xn + h )
2 2 kn,1 = f (tn , xn + hkn,1 )
h kn,2
kn,3 = f (tn + , xn + h ) xn+1 = xn + hkn,1
2 2
kn,5 = f (tn + h, xn + hkn,3 )
1 2 2 1 ▶ All kn,1 is found implicitly by
xn+1 = xn + h( kn,1 + kn,2 + kn,3 + kn,4 )
6 6 6 6 solving
kn,1 − f (tn , xn + hkn,1 ) = 0.
▶ All kn,i can be found by explicit function
evaluations.

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 24/49
Explicit vs implicit Runge-Kutta methods
The Butcher tableau

Explicit Runge-Kutta method

0
c2 a2,1
.. .. .. ..
. . . .
cns ans ,1 ans ,2 ... ans ,ns −1
b1 b2 ... bns −1 bns

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 25/49
Explicit vs implicit Runge-Kutta methods
The Butcher tableau

Explicit Runge-Kutta method

0
c2 a2,1
.. .. .. ..
. . . .
cns ans ,1 ans ,2 ... ans ,ns −1
b1 b2 ... bns −1 bns

▶ ai,j ̸= 0 only for j < i


▶ Explicit function evaluations to
compute stage values and next step
▶ Computationally cheap
▶ Order: p = ns if ns ≤ 4 and p < ns
otherwise
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 25/49
Explicit vs implicit Runge-Kutta methods
The Butcher tableau

Explicit Runge-Kutta method Implicit Runge-Kutta method

0 c1 a1,1 a1,2 ... a1,ns −1 a1,ns


c2 a2,1 c2 a2,1 a2,2 ... a2,ns −1 a2,ns
.. .. .. .. .. .. .. .. .. ..
. . . . . . . . . .
cns ans ,1 ans ,2 ... ans ,ns −1 c ns ans ,1 ans ,2 ... ans ,ns −1 ans ,ns
b1 b2 ... bns −1 bns b1 b2 ... bns −1 bns

▶ ai,j ̸= 0 only for j < i


▶ Explicit function evaluations to
compute stage values and next step
▶ Computationally cheap
▶ Order: p = ns if ns ≤ 4 and p < ns
otherwise
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 25/49
Explicit vs implicit Runge-Kutta methods
The Butcher tableau

Explicit Runge-Kutta method Implicit Runge-Kutta method

0 c1 a1,1 a1,2 ... a1,ns −1 a1,ns


c2 a2,1 c2 a2,1 a2,2 ... a2,ns −1 a2,ns
.. .. .. .. .. .. .. .. .. ..
. . . . . . . . . .
cns ans ,1 ans ,2 ... ans ,ns −1 c ns ans ,1 ans ,2 ... ans ,ns −1 ans ,ns
b1 b2 ... bns −1 bns b1 b2 ... bns −1 bns

▶ ai,j ̸= 0 only for j < i ▶ Requires solving nonlinear rootfinding


▶ Explicit function evaluations to problem with Newton’s method
compute stage values and next step ▶ Expensive but good for stiff systems
▶ Computationally cheap ▶ Order: p = 2ns , p = 2ns − 1, ...
▶ Order: p = ns if ns ≤ 4 and p < ns ▶ Famous representative: collocation
otherwise methods - treated next!
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 25/49
c2 a21
Figure 8.3: Polynomial approximation x e 1 (t) and true trajectory
c3 a31 a32
Butcher tableau, six examples
x1 (t) of the first state and its derivative, computed
the first integration step of the GL4 collocation method
..
.
.at
.. ..
.
applied to the stiff ODE from Example 8.4. Note that cs the as1 · · · as,s 1
8.2 Numerical Simulation 505
accuracy of the polynomial at the end of the intervalbis 1 b2 ··· bs
significantly higher than in the interior. The result of this
first GL4 step can also be Theseen Butcher on thetableau of three
right side of Fig-popular RK methods is stated below
explicit Euler

10 0 ure 8.4.
Heun

Euler Heun RK4


exact explicit Euler Heun RK4
RK4
2
3
10 1
x1
0
E(2⇡ ) 10 6
1 0
time derivatives is visualized, for a collocation
9 0 method0with s = 2 col- 1/2 1/2
10
location points (GL4) applied to
1 the ODE from Example
Implicit Runge-Kutta 1 8.4.1 Note(IRK)
that methods
1/2 0 1/2
12
x 2 1
in this example, ẋ
10
e (⌧; k1 , k2 , . . .0, ks ) is a polynomial of order one, i.e., an
1 0 0 1
1 1/2 1/2
affine10function, and10 its10integral,0 x e (⌧;⇡ /2
x, k1 ,⇡k2 , .3⇡. /2
. , ks ),
2⇡ is a polynomial
1/6 2/6 2/6 1/6
1 2 3 4 5 6
10 10 10
function evaluations t
of order two.
(a) Accuracy vs. function evaluations. (b) Simulation results for M = 32.
The Butcher tableau of three popular
Notecollocation
that the bmethods is
i coefficients on the bottom always add to one. An
Figure 8.2: Performance of different integration interesting
IRK as
methods. fact
the isnatural s-stage explicit
that angeneralization Runge-Kutta
from method can never
ERK methods:
Implicit Midpoint Gauss-Legendre
Euler rule (GL2) of order
0 4 (GL4)
It is important to note that on the right-hand side of each row, only c1 a11 ··· a1s
p c2 a21 p c2 a21 ··· a2s
those ki values
1 1are used 1/2that1/2
are already
1/2 computed.
3/6 c3This 1/4 property1/4 3/6
holds for every explicit integration method, and p makes ap31
it possible
a32to .. .. ..
1 1 1/2+ 3/6 1/4+ .. .. 3/6 .1/4
.
) . . .
explicitly evaluate the first s equations one after the other . 1/2 to
. obtain .
1/2 cs as1 ··· ass
all values k1 , . . . , ks for the summation in the last line.
cs One as1 usually
as2 · · ·
summarizes the coefficients of a Runge-Kutta method in what is known
b1 ··· bs
b1 b2 · · · bs
as a Butcher tableau (after John C. Butcher, born 1933) given by

c1
c2 aoptimal
02. Direct methods for smooth nonlinear 21 control A. Nurkanović 26/49
Differential-Algebraic Equations (DAE) - semi-explicit form

Extend the ODE by algebraic equations g and algebraic states z:

ẋ(t) = f (t, x(t), u(t), z(t))


0 = g(t, x(t), z(t), u(t))

▶ differential states: x(t) ∈ Rnx


▶ algebraic states: z(t) ∈ Rnz
▶ control input: u(t) ∈ Rnu

▶ Source problems: conservation laws, fast dynamics: ϵż(t) = g(x(t), z(t), u(t))), ϵ → 0.
▶ The usual case is index one, i.e. the Jacobian ∂g ∂z is invertible. If this is not the case,
dd
replace g(x, z, u) = 0 by dtd g = 0, until it is (higher index).

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 27/49
Runge-Kutta methods for differential algebraic equations
Unknowns are derivatives of states ki,j and algebraic states zi,j at stage points

Definition (RK method for index 1 DAEs)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h.
Pns
kn,i = f (tn,i , xn + h j=1 ai,j kn,j , zn,i , un ), i = 1, . . . , ns
Pns
0 = g(tn,i , xn + h j=1 ai,j kn,j , zn,i , un ), i = 1, . . . , ns
Pns
xn+1 = xn + h i=1 bi kn,i ,
0 = g(tn+1 , xn+1 , zn+1 , un ).

is called a ns -stage Runge-Kutta (RK) method for DAEs of index 1. Here zn,i , i = 1, . . . , ns
are the stage values for the algebraic variables and zn+1 is the approximation of z(tn+1 ).

x0 x1 k1,1 k1,2 . . . k1,ns x2 x3


t
t0 t0,1 t0,2 . . . t0,ns t1 z1,1 z1,2 . . . z1,ns t2 t3

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 28/49
Runge-Kutta methods for differential algebraic equations
Unknowns are derivatives of states ki,j and algebraic states zi,j at stage points

Definition (RK method for index 1 DAEs)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h.
Pns
kn,i = f (tn,i , xn + h j=1 ai,j kn,j , zn,i , un ), i = 1, . . . , ns
Pns
0 = g(tn,i , xn + h j=1 ai,j kn,j , zn,i , un ), i = 1, . . . , ns
Pns
xn+1 = xn + h i=1 bi kn,i ,
0 = g(tn+1 , xn+1 , zn+1 , un ).

is called a ns -stage Runge-Kutta (RK) method for DAEs of index 1. Here zn,i , i = 1, . . . , ns
are the stage values for the algebraic variables and zn+1 is the approximation of z(tn+1 ).

Time grid Butcher tableau Data Variables


h, tn , tn,i ai,j , bi , ci xn , un , f (·) xn+1 , kn,i , zn+1 , zn,i
i = 1, . . . , ns i, j = 1, . . . , ns i = 1, . . . , ns

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 28/49
Outline of the lecture

1 Overview of optimal control methods

2 Direct methods

3 Numerical simulation methods

4 Collocation methods

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 29/49
Collocation

Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation

Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation

Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation

Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns
▶ The polynomial qn (t) ≈ x(t) satisfies the ODE on the collocation points:

Collocation equations

qn (tn ) = xn
q̇n (tn + ci h) = f (tn + ci h, qn (tn + ci h), un ), i = 1, . . . , ns

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation

Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns
▶ The polynomial qn (t) ≈ x(t) satisfies the ODE on the collocation points:

Collocation equations

qn (tn ) = xn
q̇n (tn + ci h) = f (tn + ci h, qn (tn + ci h), un ), i = 1, . . . , ns

▶ Polynomial of degree ns : ns + 1 coefficient and ns + 1 equations

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation

Main ideas:
▶ Approximate x(t) on t ∈ [tn , tn+1 ] with a polynomial qn (t) of degree ns
▶ Pick ns distinct numbers: 0 ≤ c1 < c2 < . . . < cns ≤ 1
▶ Define collocation points tn,i = tn + ci h , i = 1, . . . , ns
▶ The polynomial qn (t) ≈ x(t) satisfies the ODE on the collocation points:

Collocation equations

qn (tn ) = xn
q̇n (tn + ci h) = f (tn + ci h, qn (tn + ci h), un ), i = 1, . . . , ns

▶ Polynomial of degree ns : ns + 1 coefficient and ns + 1 equations


▶ Next value - simple evaluation: xn+1 = qn (tn+1 )

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 30/49
Collocation - how to implement it?

How to parameterize qn (t)?


Two common (equivalent) choices

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?

How to parameterize qn (t)?


Two common (equivalent) choices
1. Find q̇n (t) interpolating polynomial through state derivatives kn,1 , . . . , kn,ns at
collocation points tn,i , i = 1, . . . , ns (this lecture).

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?

How to parameterize qn (t)?


Two common (equivalent) choices
1. Find q̇n (t) interpolating polynomial through state derivatives kn,1 , . . . , kn,ns at
collocation points tn,i , i = 1, . . . , ns (this lecture).
2. Find interpolating polynomial qn (t) through xn (at tn ) and state values xn,1 , . . . , xn,ns
at collocation points tn,i , i = 1, . . . , ns (in Appendix).

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?

How to parameterize qn (t)?


Two common (equivalent) choices
1. Find q̇n (t) interpolating polynomial through state derivatives kn,1 , . . . , kn,ns at
collocation points tn,i , i = 1, . . . , ns (this lecture).
2. Find interpolating polynomial qn (t) through xn (at tn ) and state values xn,1 , . . . , xn,ns
at collocation points tn,i , i = 1, . . . , ns (in Appendix).

▶ qn (t) is recovered via:


Z t
qn (t) = xn + q̇n (τ ; kn,1 , . . . , kn,ns )dτ.
tn

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
Collocation - how to implement it?

How to parameterize qn (t)?


Two common (equivalent) choices
1. Find q̇n (t) interpolating polynomial through state derivatives kn,1 , . . . , kn,ns at
collocation points tn,i , i = 1, . . . , ns (this lecture).
2. Find interpolating polynomial qn (t) through xn (at tn ) and state values xn,1 , . . . , xn,ns
at collocation points tn,i , i = 1, . . . , ns (in Appendix).

▶ qn (t) is recovered via:


Z t
qn (t) = xn + q̇n (τ ; kn,1 , . . . , kn,ns )dτ.
tn
▶ with:
t − t  t − t  t − t 
n n n
q̇n (t) = ℓ1 kn,1 + ℓ2 kn,2 + · · · + ℓns kn,ns
h h h
ns t − t 
n
X
= ℓi f (tn + ci , qn (tn + ci h), u0 )
i=1
h | {z }
=kn,i

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 31/49
The Lagrange polynomials ℓi (τ )

Lagrange polynomial basis


2.5
ns
Y τ − cj
ℓi (τ ) = . 2
ci − cj
j=1,i̸=j 1.5

0.5

`i (= )
0

-0.5 c1 c2 c3 c4 c5
-1

-1.5

-2

-2.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
=

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )

Lagrange polynomial basis


ns 2.5
Y τ − cj
ℓi (τ ) = . 2
ci − cj
j=1,i̸=j 1.5
`1 (t)
1
Properties:
0.5

`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1

-1.5

-2

-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )

Lagrange polynomial basis


ns 2.5
Y τ − cj
ℓi (τ ) = . 2
ci − cj
j=1,i̸=j 1.5
`1 (t) `2 (t)
1
Properties:
0.5

`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1

-1.5

-2

-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )

Lagrange polynomial basis


ns 2.5
Y τ − cj
ℓi (τ ) = . 2
ci − cj
j=1,i̸=j 1.5
`1 (t) `2 (t) `3 (t)
1
Properties:
0.5

`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1

-1.5

-2

-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )

Lagrange polynomial basis


ns 2.5
Y τ − cj
ℓi (τ ) = . 2
ci − cj
j=1,i̸=j 1.5
`1 (t) `2 (t) `3 (t) `4 (t)
1
Properties:
0.5

`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1

-1.5

-2

-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )

Lagrange polynomial basis


ns 2.5
Y τ − cj
ℓi (τ ) = . 2
ci − cj
j=1,i̸=j 1.5
`1 (t) `2 (t) `3 (t) `4 (t) `5 (t)
1
Properties:
0.5

`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1

-1.5

-2

-2.5
-0.2 0 0.2 0.4 0.6 0.8 1 1.2
=

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
The Lagrange polynomials ℓi (τ )

Lagrange polynomial basis


ns 2.5
Y τ − cj
ℓi (τ ) = . 2
ci − cj
j=1,i̸=j 1.5
`1 (t) `2 (t) `3 (t) `4 (t) `5 (t)
1
Properties:
0.5

`i (= )
(
0
1 if j = i
ℓi (cj ) = -0.5 c1 c2 c3 c4 c5
0 ̸ i
if j =
-1

-1.5
ns
X -2
ℓi (t) = 1 -2.5
i=1 -0.2 0 0.2 0.4 0.6 0.8 1 1.2
=

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 32/49
Collocation - how to implement it - continued

▶ Evaluate qn (t) at collocation points


Z tn +ci h
qn (tn + ci h) = xn + q̇n (τ ; kn,1 , . . . , kn,ns )dτ
tn

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued

▶ Evaluate qn (t) at collocation points


Z tn +ci h
qn (tn + ci h) = xn + q̇n (τ ; kn,1 , . . . , kn,ns )dτ
tn
Z tn +ci h Xns τ − t 
n
= xn + ℓj kn,j dτ
tn j=1
h

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued

▶ Evaluate qn (t) at collocation points


Z tn +ci h
qn (tn + ci h) = xn + q̇n (τ ; kn,1 , . . . , kn,ns )dτ
tn
Z tn +ci h Xns τ − t 
n
= xn + ℓj kn,j dτ
tn j=1
h
ns
X Z ci
= xn + h kn,j ℓj (σ)dσ
j=1 |0 {z }
:=ai,j

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued

▶ Evaluate qn (t) at collocation points


Z tn +ci h
qn (tn + ci h) = xn + q̇n (τ ; kn,1 , . . . , kn,ns )dτ
tn
Z tn +ci h Xns τ − t 
n
= xn + ℓj kn,j dτ
tn j=1
h
ns
X Z ci
= xn + h kn,j ℓj (σ)dσ
j=1 |0 {z }
:=ai,j
ns
X
= xn + h kn,j ai,j
j=1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
Collocation - how to implement it - continued

▶ Evaluate qn (t) at collocation points


Z tn +ci h
qn (tn + ci h) = xn + q̇n (τ ; kn,1 , . . . , kn,ns )dτ
tn
Z tn +ci h Xns τ − t 
n
= xn + ℓj kn,j dτ
tn j=1
h
ns
X Z ci
= xn + h kn,j ℓj (σ)dσ
j=1 |0 {z }
:=ai,j
ns
X
= xn + h kn,j ai,j
j=1

Similarly qn (t) evaluated at tn+1 = tn + h:


ns
X Z 1 Xns
qn (tn + h) = xn + h kn,i ℓi (σ)dσ = xn + h kn,i bi
i=1 |0 {z } i=1
:=bi
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 33/49
All collocation methods are implicit Runge-Kuta method

Collocation equations

qn (tn ) = xn (initial value)


q̇n (tn + ci h) = f (tn + ci , qn (tn + ci h), un ), i = 1, . . . , ns (stage eqs.)
xn+1 = qn (tn+1 ) (next value)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
All collocation methods are implicit Runge-Kuta method

Collocation equations

qn (tn ) = xn (initial value)


kn,i = f (tn + ci h, qn (tn + ci h), un ), i = 1, . . . , ns (stage eqs.)
xn+1 = qn (tn+1 ) (next value)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
All collocation methods are implicit Runge-Kuta method

Collocation equations

qn (tn ) = xn (initial value)


ns
X
kn,i = f (tn + ci h, xn + h kj ai,j , un ), i = 1, . . . , ns (stage eqs.)
j=1

xn+1 = qn (tn+1 ) (next value)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
All collocation methods are implicit Runge-Kuta method

Collocation equations

qn (tn ) = xn (initial value)


ns
X
kn,i = f (tn + ci h, xn + h kj ai,j , un ), i = 1, . . . , ns (stage eqs.)
j=1
ns
X
xn+1 = xn + h ki bi (next value)
i=1

▶ We arrived at the implicit RK equations in differential form


▶ Unknowns: xn+1 ∈ Rnx and zn = (kn,1 , . . . , kn,ns ) ∈ Rns nx
▶ (ns + 1)nx equations and (ns + 1)nx variables - solve via Newton’s methods

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 34/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

0
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1


Visualization inspired by Leo Simpson’s talk at the European control conference 2023
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

0
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1


Visualization inspired by Leo Simpson’s talk at the European control conference 2023
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

0
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1


Visualization inspired by Leo Simpson’s talk at the European control conference 2023
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 3
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

GL4
0
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1


Visualization inspired by Leo Simpson’s talk at the European control conference 2023
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 3
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2

10!10
0

GL6
-0.2
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1


Visualization inspired by Leo Simpson’s talk at the European control conference 2023
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 4, N = 3
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

GL8
0
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 5, N = 3
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

GL10
0
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 3
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

GL4
0
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 5
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

GL4
0
0h 1h 2h 3h 4h 5h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 10
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

GL4
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 15
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10

GL4
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 11h 12h 13h 14h 15h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 20
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10

0.1
GL4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 50
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10

0.1
GL4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 2, N = 100
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10

0.1
GL4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 3
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2

10!10
0
GL4
GL6
-0.2
0h 1h 2h 3h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 5
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10
GL4
GL6
0
0h 1h 2h 3h 4h 5h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 10
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10
GL4
GL6
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 15
1

100
0.8

0.6

E(T )
10!5
x(t)

0.4

0.2 10!10
GL4
GL6
0
0h 1h 2h 3h 4h 5h 6h 7h 8h 9h 10h 11h 12h 13h 14h 15h 10!2 10!1

t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 20
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10
GL4
0.1
GL6
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 50
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10
GL4
0.1
GL6
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 100
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10
GL4
0.1
GL6
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Gauss Legendre, ns = 3, N = 100
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10 GL2


GL4
0.1
GL6
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Collocation - visualization

▶ Choice of points c1 , . . . , cns determines properties of method.


▶ Gauss-Legendre p = 2ns , Radau-IIA p = 2ns − 1 good for stiff systems, Lobatto family
p = 2ns − 2.
Radau-IIA, ns = 3, N = 100
1

0.9
100
0.8

0.7

0.6

E(T )
10!5
x(t)

0.5

0.4

0.3

0.2 10!10 Radau-IIA1


Radau-IIA3
0.1
Radau-IIA5
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 10!2 10!1
t h

ẋ(t) = −0.5x(t)2 − x(t) + sin(10t), x(0) = 1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 35/49
Direct collocation in optimal control

Variables xn+1 ∈ Rnx and zn = (kn,1 , . . . , kn,ns ) ∈ Rns nx

Collocation equations

ns
X
xn+1 = xn + h kn,i bi (next value)
i=1
ns
X
kn,1 = f (tn + c1 h, xn + h kn,j a1,j , un ) (stage Eq. 1)
j=1
..
.
ns
X
kn,ns = f (tn + cns h, xn + h kn,j ans ,j , un ), (stage Eq. ns )
j=1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Direct collocation in optimal control

Variables xn+1 ∈ Rnx and zn = (kn,1 , . . . , kn,ns ) ∈ Rns nx

Collocation equations

ns
X
xn+1 = xn + h kn,i bi (next value)
i=1
ns
X
0 = kn,1 − f (tn + c1 h, xn + h kn,j a1,j , un ) (stage Eq. 1)
j=1
..
.
ns
X
0 = kn,ns − f (tn + cns h, xn + h kn,j ans ,j , un ), (stage Eq. ns )
j=1

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Direct collocation in optimal control

Variables xn+1 ∈ Rnx and zn = (kn,1 , . . . , kn,ns ) ∈ Rns nx

Collocation equations

ns
X
xn+1 = xn + h kn,i bi =: ϕf (xn , zn , un ) (next value)
i=1
Pns
kn,1 − f (tn + c1 h, xn + h j=1
 
kn,j a1,j , un )
..
0=  =: ϕint (xn , zn , un ) (stage Eqs.)
 
. Pns
kn,ns − f (tn + cns h, xn + h j=1 kn,j ans ,j , un )

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Direct collocation in optimal control

Variables xn+1 ∈ Rnx and zn = (kn,1 , . . . , kn,ns ) ∈ Rns nx

Collocation equations

xn+1 = ϕf (xn , zn , un ) (next value)


0 = ϕint (xn , zn , un ) (stage Eqs.)

▶ Use to discretize optimal control problem

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 36/49
Continious time OCP into Nonlinear Programs (NLP)

Continuous time OCP


RT
min 0
Lc (x(t), u(t)) dt + E(x(T ))
x(·),u(·)

s.t. x(0) = x̄0


ẋ(t) = f (x(t), u(t))
0 ≥ h(x(t), u(t)), t ∈ [0, T ]
0 ≥ r(x(T ))

▶ Direct methods: first discretize,


then optimize

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)

1. Parametrize controls, e.g.


Continuous time OCP
u(t) = un , t ∈ [tn , tn+1 ].
RT
min 0
Lc (x(t), u(t)) dt + E(x(T ))
x(·),u(·)

s.t. x(0) = x̄0


ẋ(t) = f (x(t), u(t))
0 ≥ h(x(t), u(t)), t ∈ [0, T ]
0 ≥ r(x(T ))

▶ Direct methods: first discretize,


then optimize

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)

1. Parametrize controls, e.g.


Continuous time OCP
u(t) = un , t ∈ [tn , tn+1 ].
min
RT
Lc (x(t), u(t)) dt + E(x(T )) 2. Discretize cost and dynamics via collocation
x(·),u(·) 0
Z tn+1
s.t. x(0) = x̄0 Ld (xn , un ) = Lc (x(t), u(t)) dt.
tn
ẋ(t) = f (x(t), u(t))
0 ≥ h(x(t), u(t)), t ∈ [0, T ] Replace ẋ = f (x, u) by
0 ≥ r(x(T ))
xn+1 = ϕf (xn , zn , un ),
▶ Direct methods: first discretize, 0 = ϕint (xn , zn , un ).
then optimize

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)

1. Parametrize controls, e.g.


Continuous time OCP
u(t) = un , t ∈ [tn , tn+1 ].
min
RT
Lc (x(t), u(t)) dt + E(x(T )) 2. Discretize cost and dynamics via collocation
x(·),u(·) 0
Z tn+1
s.t. x(0) = x̄0 Ld (xn , un ) = Lc (x(t), u(t)) dt.
tn
ẋ(t) = f (x(t), u(t))
0 ≥ h(x(t), u(t)), t ∈ [0, T ] Replace ẋ = f (x, u) by
0 ≥ r(x(T ))
xn+1 = ϕf (xn , zn , un ),
▶ Direct methods: first discretize, 0 = ϕint (xn , zn , un ).
then optimize
3. Relax path constraints, e.g., evaluate only
at t = tn

0 ≥ h(xn , un ), n = 0, . . . N − 1.

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Continious time OCP into Nonlinear Programs (NLP)

Continuous time OCP


RT Discrete time OCP (an NLP)
min 0
Lc (x(t), u(t)) dt + E(x(T ))
x(·),u(·) PN −1
min k=0 Ld (xk , uk ) + E(xN )
s.t. x(0) = x̄0 x,z,u

ẋ(t) = f (x(t), u(t)) s.t. x0 = x̄0


0 ≥ h(x(t), u(t)), t ∈ [0, T ] xn+1 = ϕf (xn , zn , un )
0 ≥ r(x(T )) 0 = ϕint (xn , zn , un )
0 ≥ h(xn , un ), n = 0, . . . , N −1
▶ Direct methods: first discretize, 0 ≥ r(xN )
then optimize
Variables x = (x0 , . . . , xN ), z = (z0 , . . . , zN )
and u = (u0 , . . . , uN −1 ).

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 37/49
Direct optimal control methods solve Nonlinear Programs (NLP)

Discrete time OCP (an NLP)


PN −1
min k=0 Ld (xk , uk ) + E(xN )
x,z,u

s.t. x0 = x̄0
xn+1 = ϕf (xn , zn , un )
0 = ϕint (xn , zn , un )
0 ≥ h(xn , un ), n = 0, . . . , N −1
0 ≥ r(xN )

Variables w = (x, z, u)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 38/49
Direct optimal control methods solve Nonlinear Programs (NLP)

Discrete time OCP (an NLP) Nonlinear Program (NLP)


PN −1
min k=0 Ld (xk , uk ) + E(xN )
x,z,u min F (w)
w∈Rnx
s.t. x0 = x̄0
s.t. G(w) = 0
xn+1 = ϕf (xn , zn , un )
H(w) ≥ 0
0 = ϕint (xn , zn , un )
0 ≥ h(xn , un ), n = 0, . . . , N −1
Obtain large and sparse
0 ≥ r(xN ) NLP

Variables w = (x, z, u)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 38/49
Direct optimal control methods solve Nonlinear Programs (NLP)

r2ww L(w; 6; 7)
0
Nonlinear Program (NLP)
20
rw G(w)
0 40

60 min F (w)
w∈Rnx
80
50
0 50 100
s.t. G(w) = 0
100
nz = 196
120
H(w) ≥ 0
0 50 100
nz = 611

Variables w = (x, z, u) Obtain large and sparse


NLP

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 38/49
Work flow in smooth direct optimal control
First discretize, then optimize.

Single shooting
SQP

Integrator
OCP Multiple shooting NLP

Direct IPM
transcription

Problem formulation Time discretization Optimization


OCP = Optimal Control Problem SQP = Sequential Quadratic Programming
NLP = Nonlinear Program IPM = Interior-Point Method
Figure inspired by Lecture 1, Numerical Methods for Optimal Control: Introduction, 2022, by Mario Zanon and Sébastien Gros.
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 39/49
Direct collocation vs direct multiple shooting

Direct collocation NLP Multiple shooting NLP


PN −1 PN −1
min k=0 Ld (xk , uk ) + E(xN ) min k=0 Ld (xk , uk ) + E(xN )
x,z,u x,u
s.t. x0 = x̄0 s.t. x0 = x̄0
xn+1 = ϕf (xn , zn , un ) xn+1 = ψf (xn , un )
0 = ϕint (xn , zn , un )
0 ≥ h(xn , un ), n = 0, . . . , N −1 0 ≥ h(xn , un ), n = 0, . . . , N −1
0 ≥ r(xN ) 0 ≥ r(xN )

▶ Variables w = (x, z, u) ▶ Variables w = (x, u)


▶ Only fixed number of integration steps ▶ Can use adaptive integrators
▶ Internal computations of integrator done ▶ Internal computations of integrator
by optimizer hidden from optimizer
▶ More variables, but sparser ▶ Less variables
02. Direct methods for smooth nonlinear optimal control A. Nurkanović 40/49
Summary

▶ Numerical simulation methods used to solve ODEs approximately.


▶ Integration accuracy order and stability play key roles.
▶ All collocation methods are IRK methods, the converse is not true.
▶ Choice of discretization method has huge influence on efficacy and reliability of NLP
solution.
▶ Best choice is problem dependent and often requires lot of care.
▶ Many good software packages exist: CasADi, pyomo.DAE, acados, MUSCOD-II, ACADO,
ForcesPRO, IPOPT, ... (the list is far from complete)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 41/49
Reading recommendations

Direct optimal control:


▶ James B. Rawlings, David Q. Mayne, and Moritz Diehl. Model predictive control: theory,
computation, and design. Vol. 2. Madison, WI: Nob Hill Publishing, 2017. - Chapter 8.
Online: https://sites.engineering.ucsb.edu/~jbraw/mpc/
▶ Biegler, Lorenz T. Nonlinear programming: concepts, algorithms, and applications to
chemical processes. Society for Industrial and Applied Mathematics, 2010.
▶ Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2014.
Online: https://www.syscop.de/files/2024ws/NOC/book-NOCSE.pdf

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 42/49
Free online video lectures

Numerical optimal control video lectures by Moritz Diehl (highly recommended!):


▶ Videos:
https://www.syscop.de/teaching/ss2020/numerical-optimal-control-online
▶ Lecture notes: https://www.syscop.de/files/2024ws/NOC/book-NOCSE.pdf

Lecture notes/slides by Mario Zanon Sébastien Gros


▶ https://mariozanon.wordpress.com/teaching/
numerical-methods-for-optimal-control/

Optimal control software:


▶ CasADi - general purpose modeling and optimization - https://web.casadi.org/get
▶ acados - fast embedded model predictive control -
https://github.com/acados/acados
▶ https://www.syscop.de/research/software

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 43/49
References used for this lecture

▶ Moritz Diehl, Sébastien Gros. ”Numerical optimal control (Draft),” Lecture notes, 2019.
▶ James B. Rawlings, David Q. Mayne, and Moritz Diehl. Model predictive control: theory,
computation, and design. Vol. 2. Madison, WI: Nob Hill Publishing, 2017.
▶ Gerhard Wanner, Ernst Hairer. ”Solving ordinary differential equations II.” Vol. 375. New
York: Springer Berlin Heidelberg, 1996.

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 44/49
Direct collocation via state values

To discretize an optimal control problem with direct collocation we replace the continuous-time
dynamics

ẋ(t) = f (x(t), u(t)),

by the discrete-time collocation equations.


▶ split the control horizon [0, T ] into N control intervals with a uniform time discretization
T
grid tn = nh, n = 0, . . . , N , h = N
▶ state values are xn = x(tn )
▶ control discretization: u(t) = un , t ∈ [tn , tn+1 ], n = 1, . . . , N .
▶ on every control interval the state trajectory is approximated by polynomials qn (t),
n = 1, . . . , N .
Next, on each control interval [tn , tn+1 ], we compute the coefficients of these polynomials to
ensure that the ODE is exactly satisfied at the collocation points tn,i = tn + hci , i = 1, . . . , ns ,
where, ns is the number of stages.

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 45/49
Direct collocation via state values

▶ choice of 0 = c0 < c1 < . . . < cns ≤ 1 determines the accuracy and stability properties of
the resulting method
▶ popular choices for ci are the Radau IIA or Gauss-Legendre points.
▶ Previously treated: interpolating polynomial q̇n (t) through the state derivatives
kn,1 , . . . , kn,ns .
▶ Here, finding the interpolating polynomial qn (t) through the initial value xn and state
values xn,1 , . . . , xn,ns at the stage points.
▶ We use of the Lagrangian polynomial basis. Using these time points, we define a basis for
our polynomials:
ns
Y τ − cj
ℓi (τ ) = , i = 0, . . . , ns . (2)
ci − cj
j=0, i̸=j

▶ Remark: in contrast to using state derivatives kn,i , the counter starts from i = 0, as we
include the point c0 = 0, since we interpolate through xn .

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 46/49
Direct collocation via state values

We approximate the state trajectory on [tn , tn+1 ] by a linear combination of the basis functions:
ns
t − tn
X  
qn (t) = ℓj xn,j . (3)
j=0
h

By differentiation, we obtain an approximation of the time derivative at each collocation point:


ns ns
1 X 1 X
q̇n (tn,i ) = ℓ̇j (ci ) xn,j := Cj,i xn,j , i = 0, . . . , ns . (4)
h j=0 h j=0

The collocation equations must satisfy the ODE at every collocation point tn,i :

q̇n (tn,i ) = f (qn (tn,i ), un ), i = 1, . . . ns

That is:
ns
1 X
Cj,i xn,j = f (xn,i , un ), i = 1, . . . ns . (5)
h j=0

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 47/49
Collocation: next step and cost integral approximation

The expression for the state at the end of an interval reads as:
ns
X ns
X
xn+1 = ℓi (1) xn,i := Di xn,i (6)
i=0 i=0

Moreover, using the obtained approximation qn (t) we can integrate the stage cost
Z T
L(x(t), u(t))dt,
0

over every control interval and obtain a formula for quadratures:


ns
tn+1 X ns Z 1 ns
t − tn
Z   X X
ℓj L(xn,j , un ) dt = h ℓj (t) dt L(xn,j , un ) := h Bj L(xn,j , un ).
tn j=0
h j=0 0 j=0
(7)

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 48/49
Runge-Kutta method definition
Unknowns are states at stage points, cannot treat case of c1 = 0

Definition (Runge-Kutta method in integral form)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h. The system of equations:
ns
X
xn,i = xn + h ai,j f (tn,i , xn,j , un ), i = 1, . . . , ns
j=1
Xns
xn+1 = xn + h bi f (tn,i , xn,i , un ),
i=1

is called a ns -stage Runge-Kutta (RK) method in integral form.

Time grid Butcher tableau Data Variables


h, tn , tn,i ai,j , bi , ci xn , un , f (·) xn+1 , xn,i
i = 1, . . . , ns i, j = 1, . . . , ns i = 1, . . . , ns

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 49/49
Runge-Kutta method definition
Unknowns are states at stage points, cannot treat case of c1 = 0

Definition (Runge-Kutta method in integral form)


Let ns be the number of stages. Given the matrix A ∈ Rns ×ns with the entries ai,j for
i, j = 1, . . . , ns , and the vectors b, c ∈ Rns . Let tn,i = tn + ci h. The system of equations:
ns
X
xn,i = xn + h ai,j f (tn,i , xn,j , un ), i = 1, . . . , ns
j=1
Xns
xn+1 = xn + h bi f (tn,i , xn,i , un ),
i=1

is called a ns -stage Runge-Kutta (RK) method in integral form.


x0 x1 x1,1 x1,2 . . . x1,ns x2 x3
t
t0 t0,1 t0,2 . . . t0,ns t1 t2 t3

02. Direct methods for smooth nonlinear optimal control A. Nurkanović 49/49

You might also like