Lecture Slides
Lecture Slides
Per-Olof Persson
[email protected]
Department of Mathematics
University of California, Berkeley
In general,
u : [t0 , t0 + a] → Rn ,
f : Rn × [t0 , t0 + a] → Rn
u0 = Au + g(t)
Definition
A function f (u, t) is said to be Lipschitz continuous in a region S if
there exists a Lipschitz constant λ ≥ 0 such that
∂f (x, t)
λ = max
(x,t)∈S ∂x
Definition
Commonly used vector norms
m m
!1/2
X X 2
kxk1 = |xi | , kxk2 = |xi | , kxk∞ = max |xi |
1≤i≤m
i=1 i=1
Well-Posedness
Definition
The initial-value problem
Theorem
Suppose f (u, t) is continuous in u, t on the cylinder
Theorem Picard-Lindelöf
Subject to both continuity and Lipschitz continuity of f in S, (1)
has a unique solution in [t0 , t0 + α] and is well-posed.
Theorem
If f is C r for some r ≥ 1, the solution u(u0 , t) is also C r as a
function of t and the initial condition u0 .
Basic Schemes for IVPs
Forward Euler
un+1 = un + hf (tn , un )
eLT − 1
kun − u(tn )k ≤ eLT ku0 − u(0)k + Mh
2L
where L is a Lipschitz constant for f and M ≥ ku00 k.
Backward Euler
Definition
An m-step multistep method for solving the initial-value problem
h
un+1 = un + [55f (tn , un ) − 59f (tn−1 , un−1 )
24
+ 37f (tn−2 , un−2 ) − 9f (tn−3 , un−3 )]
h
un+1 = un + [9f (tn+1 , un+1 ) + 19f (tn , un )
24
− 5f (tn−1 , un−1 ) + f (tn−2 , un−2 )]
Runge-Kutta Methods
k1 = f (tn , un )
h h
k2 = f tn + , un + k1
2 2
h h
k3 = f tn + , un + k2
2 2
k4 = f (tn + h, un + hk3 )
h
un+1 = un + (k1 + 2k2 + 2k3 + k4 )
6
Runge-Kutta Methods
Forward/Backward Euler
0 0 1 1
1 1
The explicit midpoint method
0
1 1
2 2
0 1
Four-stage fourth-order method
0
1 1
2 2
1 1
2 0 2
1 0 0 1
1 1 1 1
6 3 3 6
Implicit Runge-Kutta Methods
If smoothly differentiable,
∂f (t, x)
L = max
x,t ∂x
un+1 = un + h · f (tn , un )
with h = T /N and tn = nh
Convergence of Euler’s Method
Definition
A method for the IVP converges if, for Lipschitz continuous f
as h → 0 and u0 → y0 .
Theorem
Euler’s method converges for any IVP with f Lipschitz and y is C 2 .
Convergence of Euler’s Method
un+1 = un + hf (tn , un )
− y(tn+1 ) = y(tn ) + hf (tn , y(tn )) + τn
Bound the truncation errors by τ ≥ kτn k for all n, take norms and
use the triangle inequality:
Apply recursively:
eLT − 1 M h LT
ken k ≤ M h2 n ≤ (e − 1) = O(h)
2LT 2L
Stiff Equations and Linear Stability Theory
Time-step restrictions for Euler’s method
Example
Consider the IVP
with solution
y1 (t) = Ae−3000t + Be−3t
y2 (t) = −Ae−3000t + 2Be−3t
Set A = 0 to get initial conditions (y1 (0), y2 (0)) = (1, 2). Euler’s
method with h = 0.01 then gives y1 (1) ≈ (u1 )100 = −1.5 · 10128 ,
even if the rapid term e−3000t is not present in the solution.
Example
Backward Euler’s method with h = 0.01 gives (u1 )100 = 0.0520,
which is close to the true solution y1 (1) = e−3 = 0.0498.
Stiff Initial Value Problems
Definition 1
A stiff IVP is one for which we have to use implicit methods to get
accurate results at reasonable cost.
Definition 2
A system of ODEs with high “stiffness ratio”
max |λp |
min |λp |
y 0 = λy
un+1 = R(z)un
S = {z ∈ C : |R(z)| ≤ 1}
Example
Euler’s method
Example
Backward Euler method
the RAS is the set of points z such that the roots ζj of the
polynomial
r
X r
X
j
π(ζ; z) = ρ(ζ) − zσ(ζ), ρ(ζ) = αj ζ , σ(ζ) = βj ζ j
j=0 j=0
are less than one in magnitude (or equal to one if not repeated).
More on this later.
Linear Systems of Equations
The same technique can be used on, for example, Euler’s method:
Consider the IVP y 0 = f (t, y) with y(0) = y0 , and the Taylor series
expansion for y(tn+1 ) about y(tn ):
∞
X hi h2 00
y(tn+1 ) = y (i) (tn ) = yn + hy 0 (tn ) + y (tn ) + · · ·
i! 2
i=0
h2 00 hk
y(tn+1 ) ≈ yn + hy 0 (tn ) + y (tn ) + · · · + y (k) (tn )
2 k!
Write y(tn ) and its derivatives in terms of f and its derivatives:
h2
un+1 = un + hf (tn , un ) + ft (tn , un ) + Df (tn , un ) · f (tn , un )
2
h2 00 hk (k)
0
τn = yn+1 − yn + hy (tn ) + y (tn ) + · · · + y (tn )
2 k!
h k+1
= y (k+1) (tn + θn h)
(k + 1)!
h(k+1)
kτn k ≤ M = O(hk+1 ) with ky (k+1) k ≤ M
(k + 1)!
Linear Stability
y 0 = f = λy
y 00 = f 0 = fy y 0 = λ(λy) = λ2 y
..
.
y (k) = λk y
h2 2 hk
un+1 = un + hλun + λ un · · · + λk un = R(hλ)un
2 k!
2 zk
with R(z) = 1 + z + z2 · · · + k! . Note that R(z) → ez as k → ∞,
since for the true solution,
un+1 = un + h · Φ(tn , un , h)
The Taylor series method of order k has LTE τ (h) = O(hk+1 ), and
is therefore convergent of order k.
Runge-Kutta Methods
k1 = f (tn , un ) 0
k2 = f (tn + h, un + hk1 ) 1 1
1 1
h 2 2
un+1 = un + (k1 + k2 )
2
and the implicit trapezoidal rule
k1 = f (tn , un )
k2 = f (tn+1 , un+1 ) 0
1 1
1
h 2
1
2
1
= f (tn + h, (k1 + k2 ))
2 2 2
h
un+1 = un + (k1 + k2 )
2
Runge-Kutta Order Bounds
For p > 4, systems of equations may have lower order than scalar
equations.
Autonomization
y0 = f
y 00 = f 0 = fy y 0 = fy f
y 000 = f 00 = fyy (y 0 )f + fy f 0 = fyy f 2 + fy2 f
Example: General 2-stage ERK
h2 a2 2
f (yn + haf ) = f + fy haf + fyy f + O(h3 )
2
and substitute in the LTE and collect equal powers of h:
h2 h3
τn = hf + fy f + (fyy f 2 + fy2 f ) + O(h4 )
2 6
h3
− hb1 f − hb2 f − h2 b2 afy f − b2 a2 f 2 + O(h4 )
2
1
= h(f − b1 f − b2 f ) + h2 ( fy f − b2 afy f )
2
3 1 1 2 1
+ h ( fyy f + fy f − b2 a2 fyy f 2 ) + O(h4 )
2
6 6 2
Example: General 2-stage ERK
b1 + b2 = 1
1
b2 a =
2
Impossible to eliminate the h3 -term, so τn = O(h3 ) at best. Many
solutions possible:
0 0 0 0 0 0 0 0 0
1/2 1/2 0 1 1 0 3/4 3/4 0
0 1 1/2 1/2 1/3 2/3
But we can choose the scheme that minimizes the h3 -term, by
cancelling two of its terms: 16 = 21 b2 a2 =⇒ b2 a2 = 31 . This leads
to Heun’s method
0 0 0
2 1 3
a = , b1 = , b2 = 2/3 2/3 0
3 4 4
1/4 3/4
Implicit Runge-Kutta (IRK) Methods
Newton’s Method
Newton’s Method
Solve F (x) = 0 iteratively, starting from initial guess x(0) . Taylor
expansion of F (x) about last iterate x(k) with remainder term:
Convergence
If f is C 2 and x(0) is “close enough” to x, the iterations converge
quadratically:
Termination Criteria
Nothing is perfect, but two commonly used criteria for terminating
the iterations and accepting the last iterate are:
k∆x(k+1) k ≤ tol
kF (x(k) )k ≤ tol
Newton’s Method for Backward Euler
with derivative
(0)
Good initial guess: un+1 = un
General Implicit Runge-Kutta Methods (IRKs)
k1 = f (un ) 0 0 0
1 1
1 2 2
k2 = f (un + h(k1 + k2 )/2) 1 1
2 2
un+1 = un + h(k1 + k2 )/2
Do a Taylor expansion of k1 , k2 , and approximate to first order:
k1 = f
k2 = f + fy h(k1 + k2 )/2 + O(h2 ) = f + O(h)
fy f
fyy
The γ Function
For each tree t̂, we define the function γ(t̂) as the product of the
order of t̂ and the orders of all possible trees after successively
removing roots. For example:
Tree
Orders 4 2,1 1
gives γ(t̂) = 4 · 2 · 1 · 1 = 8.
Order Conditions
Find γ(t̂)
Assign indices to the tree vertices
k
The order condition is
s
X 1 i j
b` a`,i a`,j ai,k =
`,i,j=1
γ(t̂)
`
that is, b` multiplied by one ai,j for
each edge between two vertices i, j
Example: 2-stage Explicit Runge-Kutta
i j 2
X 1
3 b` a`,i a`,j = b2 a221 =
3
` `,i,j=1
j
2
X 1
b` a`,i ai,j = 0 =
i 3·2=6 6
`,i,j=1
Impossible to satisfy
`
Gaussian Quadrature and Collocation Methods
Gaussian Quadrature
P0 (x) = 1, P1 (x) = x
1 1
P2 (x) = (3x2 − 1) P3 (x) = (5x3 − 3x)
2 2
Gaussian Quadrature
Theorem
Suppose x1 , . . . , xn are roots of Pn (x) and
n
1
x − xj
Z Y
wi = dx
−1 xi − xj
j6=i
MATLAB Implementation
function [x,c]=gaussquad(n)
%GAUSSQUAD Gaussian quadrature
P=zeros(n+1,n+1);
P([1,2],1)=1;
for k=1:n-1
P(k+2,1:k+2)=((2*k+1)*[P(k+1,1:k+1) 0]- ...
k*[0 0 P(k,1:k)])/(k+1);
end
x=sort(roots(P(n+1,1:n+1)));
A=zeros(n,n);
for i=1:n
A(i,:)=polyval(P(i,1:i),x)’;
end
c=A\[2;zeros(n-1,1)];
The Lagrange Polynomial
Theorem
If x1 , . . . , xn distinct and f given at these numbers, a unique
polynomial P (x) of degree < n exists with
The polynomial is
n
X
P (x) = f (x1 )Ln,1 (x) + . . . + f (xn )Ln,n (x) = f (xk )Ln,k (x)
k=1
where
(x − x1 )(x − x2 ) · · · (x − xk−1 )(x − xk+1 ) · · · (x − xn )
Ln,k (x) =
(xk − x1 )(xk − x2 ) · · · (xk − xk−1 )(xk − xk+1 ) · · · (xk − xn )
Y (x − xi )
=
(xk − xi )
i6=k
Collocation
Scheme:
1 1
2 2
1
Example: Hammer-Hollingsworth
√
1 3
s = 2, Gaussian Quadrature points c1 = 2 − 6 ,
√
1 3
c2 = 2 + 6 , Lagrange polynomials
t − t(2) t − t(1)
L2,1 (t) = , L2,2 (t) =
t(1) − t(2) t(2) − t(1)
Coefficients
Z tn +c1 h
1 1
a1,1 = L2,1 dt = · · · =
h tn 4
Z tn +c2 h
√
1 1 3
a1,2 = L2,1 dt = · · · = +
h tn 4 6
Z tn +c1 h √
1 1 3
a2,1 = L2,2 dt = · · · = −
h tn 4 6
Z tn +c2 h
1 1
a2,2 = L2,2 dt = · · · =
h tn 4
Example: Hammer-Hollingsworth
Coefficients (cont’d)
Z tn +h
1 1
b1 = L2,1 (t) dt =
h tn 2
Z tn +h
1 1
b2 = L2,2 (t) dt =
h tn 2
Scheme: √ √
1 3 1 1 3
2 − √6 4√ 4 − 6
1 3 1 3 1
2 + 6 4 + 6 4
1 1
2 2
Example: Three-stage Gauss Legendre
p
s = 3, Gaussian Quadrature
p points c1 = (1 − 3/5)/2,
c2 = 1/2, c3 = (1 + 3/5)/2, Lagrange polynomials
Scheme: √ √ √
1 15 5 2 15 5 15
2 − 10 36√ 9 − 15 36 − √30
1 5 15 2 5 15
2√ 36 + −
√24 9√ 36 24
1 15 5 15 2 15 5
2 + 10 36 + 30 9 + 15 36
5 4 5
18 9 18
A,L,B-stability of Runge-Kutta Methods
Linear Stability Analysis of RK Methods
By Cramer’s rule,
adj(I − zA)
(I − zA)−1 =
det(I − zA)
with
R ∈ Ps/s
R ∈ Ps
A-stability of RK Methods
Lemma
Let R be an arbitrary rational function that is not a constant.
Then |R(z)| < 1 for all z ∈ C − if and only if all the poles of R
have positive real parts and |R(it)| ≤ 1 for all t ∈ R.
L-Stability
Definition
A one-step method is L-stable if it is A-stable and
limz→∞ |R(z)| = 0
P (z)
For R(z) = Q(z) , L-stability requires deg(P ) < deg(Q).
Examples
1
Backward Euler, R(z) = 1−z → 0 as z → ∞ =⇒ L-stable
Definition
An ODE is contractive if ky(t) − z(t)k ≤ ky(s) − z(s)k for every
pair of solutions y and z when t ≥ s.
Definition
A numerical method is B-stable (or contractive) if every pair of
numerical solutions u and v satisfy kun+1 − vn+1 k ≤ kun − vn k for
all n, when solving an IVP with a dissipative f .
Definition
A RK method is algebraically stable if the matrices
B = diag(b1 , . . . , bs ), M = BA + AT B T − bbT
Examples
Implicit midpoint method, A = 1/2, b = 1, B = 1 is
nonnegative semidefinite,
M = 1 · 1/2 + 1/2 · 1 − 1 · 1 = 1 − 1 = 0 is nonnegative
semidefinite =⇒ Algebraically stable =⇒ B-stable.
Linear Multisteps Methods, Adams Methods
Linear Multistep Methods
Normalize by setting αr = 1
Explicit if βr = 0
Adams Methods
Adams-Bashforth Methods
Let p(t) interpolate fn , fn−1 , . . . , fn−r+1
r = 1: p(t) = fn =⇒ un+1 = un + hfn
r = 2: p(t) = fn tt−tn−1
n −tn−1
t−tn
+ fn−1 tn−1 −tn
t
(t − tn−1 )2 (t − tn )2 n+1
un+1 = un + fn − fn−1
2h 2h tn
3 1
= un + hfn − hfn−1
2 2
Adams-Bashforth Methods
Adams-Moulton Methods
Let p(t) interpolate fn+1 , fn , fn−1 , . . . , fn−r+1
t−tn t−tn+1
r = 1: p(t) = fn+1 tn+1 −tn + fn tn −tn+1
t
(t − tn )2 (t − tn+1 )2 n+1
un+1 = un + fn+1 − fn
2h 2h tn
1 1
= un + hfn+1 + hfn (Trapezoidal)
2 2
(t−tn )(t−tn−1 )
r = 2: p(t) = fn+1 (tn+1 −tn )(tn+1 −tn−1 ) +
fn (t(t−tn+1 )(t−tn−1 )
n −tn+1 )(tn −tn−1 )
(t−tn+1 )(t−tn )
+ fn−1 (tn−1 −tn+1 )(tn−1 −tn )
Z tn+1
un+1 = un + p(t) dt = (Maple) =
tn
5 2 1
= un + hfn+1 + hfn − hfn−1
12 3 12
Adams-Moulton Methods
h
1-step: un+1 = un + [f (tn+1 , un+1 ) + f (tn , un )]
2
h
2-step: un+1 = un + [5f (tn+1 , un+1 ) + 8f (tn , un )
12
− f (tn−1 , un−1 )]
h
3-step: un+1 = un + [9f (tn+1 , un+1 ) + 19f (tn , un )
24
− 5f (tn−1 , un−1 ) + f (tn−2 , un−2 )]
h
4-step: un+1 = un + [251f (tn+1 , un+1 ) + 646f (tn , un )
720
− 264f (tn−1 , un−1 ) + 106f (tn−2 , un−2 )
− 19f (tn−3 , un−3 )]
t − tn t − tn+1
p(t) = un+1 + un
tn+1 − tn tn − tn+1
1 1
p0 (t) = un+1 − un
h h
p0 (tn+1 ) = f (tn+1 , un+1 ) =⇒
un+1 = un + hf (tn+1 , un+1 )
BDF2
(t − tn )(t − tn−1 )
p(t) = un+1
(tn+1 − tn )(tn+1 − tn−1 )
(t − tn+1 )(t − tn−1 )
+ un
(tn − tn+1 )(tn − tn−1 )
(t − tn+1 )(t − tn )
+ un−1
(tn−1 − tn+1 )(tn−1 − tn )
1
p0 (t) = un+1 2 (t − tn + t − tn−1 )
2h
1
− un 2 (t − tn+1 + t − tn−1 )
h
1
+ un+1 2 (t − tn+1 + t − tn )
2h
0 3 2 1
p (tn+1 ) = un+1 − un + un−1 = f (tn+1 , un+1 ) =⇒
2h h 2h
4 1 2
un+1 = un − un−1 + hf (tn+1 , un+1 )
3 3 3
Backward Differentiation Formula (BDF) Methods
Example:
u0 = 0
u1 = h
u2 = 3h
u3 = 7h
..
.
un = (2n − 1)h
Linear Difference Equations
Pr
Consider the homogeneous problem j=0 αj un+j =0
Suppose un = ζn and plug into the scheme:
r
X r
X
n+j
αj ζ = 0 =⇒ αj ζ j = 0
j=0 j=0
c1 + c2 + · · · + cr = u0
c1 ζ1 + c2 ζ2 + · · · + cr ζr = u1
..
.
c1 ζ1r−1 + c2 ζ2r−1 + · · · + cr ζrr−1 = ur−1
Example
For
the polynomial is
ρ(ζ) = ζ 2 − 3ζ + 2 = (ζ − 1)(ζ − 2) =⇒ ζ1 = 1, ζ2 = 2
=⇒ un = c1 + c2 2n
ρ(ζ) = ζ 2 − 2ζ + 1 = (ζ − 1)2 =⇒ ζ1 = ζ2 = 1
=⇒ un = c1 + c2 n = u0 + (u1 − u0 )n
5 1
ρ(ζ) = ζ 3 − 2ζ 2 + ζ − = (ζ − 1)(ζ − 0.5)2
4 4
=⇒ un = c1 + c2 0.5n + c3 n0.5n → c1 as n → ∞
Definition
An r-step Linear Multistep Method (LMM) is zero-stable if the
roots of the polynomial ρ(ζ) satisfy:
1) |ζj | ≤ 1
2) |ζj | < 1 if ζj is repeated
and
r r−1 r ζ1 = 1,
ρ(ζ) = ζ − ζ = (ζ − 1)ζ =⇒
ζ2 = ζ3 = · · · = 0,
=⇒ convergent if consistent
Zero-Stability
4 1 1
ρ(ζ) = ζ 2 − ζ + = (ζ − 1)(ζ − ) =⇒ zero-stable
3 3 3
=⇒ convergent if consistent
Can be shown that the BDF methods are zero-stable when
r≤6
Definition
The region of absolute stability for an LMM is the set of points z
in the complex plane for which the roots ζj of the polynomial
π(ζ; z) = ρ(ζ) − zσ(ζ) satisfy
1) |ζj | ≤ 1
2) |ζj | < 1 if ζj is repeated
where q ≤ s − 1.
The local truncation errors are
This gives
1
hp+1 y (p+1) (tn+s ) ≈ (wn+s − un+s )
c − c̃
Plug into local truncation error to get the Milne Device
c
τ≈ (wn+s − un+s )
c − c̃
Example: TR-AB2
τ ≈ un+1 − ûn+1
Embedded Runge-Kutta Methods
u(x̄ + h) − u(x̄) h
D+ u(x̄) = = u0 (x̄) + u00 (x̄) + O(h2 )
h 2
u(x̄) − u(x̄ − h) 0 h 00
D− u(x̄) = = u (x̄) − u (x̄) + O(h2 )
h 2
u(x̄ + h) − u(x̄ − h) h2
D0 u(x̄) = = u0 (x̄) + u000 (x̄) + O(h4 )
2h 6
u(x̄ − h) − 2u(x̄) + u(x̄ + h)
D2 u(x̄) =
h2
h2
= u00 (x̄) + u0000 (x̄) + O(h4 )
12
Method of Undetermined Coefficients
u(xn )
Ah eh = −τ h
eh = −(Ah )−1 τ h
keh k = k(Ah )−1 τ h k ≤ k(Ah )−1 k · kτ h k
keh k ≤ C · kτ h k → 0 if kτ h k → 0 as h → 0
Stability, Consistency, and Convergence
Definition
A method Ah uh = f h is stable if (Ah )−1 exists and
k(Ah )−1 k ≤ C for h ≤ h0
It is consistent with the DE if kτ h k → 0 as h → 0
It is convergent if keh k → 0 as h → 0
h2 0000 h2 00
kτ h k2 ≈ ku k2 = kf k2 =⇒ keh k2 = O(h2 )
12 12
While this implies convergence in the max-norm, 1/2 order is
lost because of the grid function norm:
1
keh k∞ ≤ √ keh k2 = O(h3/2 )
h
1 h
(−u0 + u1 ) = σ + f (x0 )
h 2
Same matrix structure as in 1), but with “correction term”
h
2 f (x0 )
Neumann Boundary Conditions
3h h
2 −2h 2 u0 σ
1 −2 1 u1 f (x1 )
1
..
..
..
= .
. .
h2
1 −2 1 un f (xn )
0 h2 un+1 β
2.8 ε=1e−1
ε=3e−2
2.6
ε=1e−2
2.4
2.2
1.8
1.6
1.4
1.2
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Boundary Layers
2.8
2.6
h=0.05
2.4 h=0.025
2.2
1.8
1.6
1.4
1.2
1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1