Numerical Methods for Differential · PDF fileNumerical Methods for Differential Equations...

Post on 06-Feb-2018

226 views 0 download

Transcript of Numerical Methods for Differential · PDF fileNumerical Methods for Differential Equations...

Numerical Methods for Differential Equations

Chapter 1: Initial value problems in ODEs

Gustaf Soderlind and Carmen Arevalo

Numerical Analysis, Lund University

Textbooks: A First Course in the Numerical Analysis of Differential Equations, by Arieh Iserles

and Introduction to Mathematical Modelling with Differential Equations, by Lennart Edsberg

c© Gustaf Soderlind, Numerical Analysis, Mathematical Sciences, Lund University, 2008-09

Numerical Methods for Differential Equations – p. 1/52

Chapter 1: contents

◮ Course contents

◮ Introduction to initial value problems

◮ The explicit Euler method

◮ Convergence

◮ Order of consistency

◮ The trapezoidal rule

◮ Theta methods

◮ Numerical tests

◮ The linear test equation and numerical stability

◮ Stiff equations

Numerical Methods for Differential Equations – p. 2/52

What is Numerical Analysis?

Categories of mathematical problems

Category Algebra Analysis

linear computable not computable

nonlinear not computable not computable

Algebra: Only finite constructions

Analysis: Limits, derivatives, integrals etc. (transfinite)

Computable: the exact solution can be obtained in afinite number of operations

Numerical Methods for Differential Equations – p. 3/52

What is Numerical Analysis?

Category Algebra Analysis

linear computable not computable

nonlinear not computable not computable

With numerical methods, problems from all four categoriescan be solved:

“Numerical analysis aims to construct and analyzequantitative methods for the automatic computation ofapproximate solutions to mathematical problems.”

Goal: Construction of mathematical software

Numerical Methods for Differential Equations – p. 4/52

0. What will we study in this course?

To solve a differential equation analytically we look for adifferentiable function that satisfies the equation

Large, complex and nonlinear systems cannot be solvedanalytically

Numerical Methods for Differential Equations – p. 5/52

0. What will we study in this course?

To solve a differential equation analytically we look for adifferentiable function that satisfies the equation

Large, complex and nonlinear systems cannot be solvedanalytically

Instead, we compute numerical solutions with standardmethods and software

To solve a differential equation numerically we generate asequence {yk}N

k=0 of pointwise approximations to theanalytical solution: y(tk) ≈ yk

Numerical Methods for Differential Equations – p. 5/52

Some differential equations we will solve

◮ Initial value problems (IVP) first-order equations;higher-order equations; systems of differentialequations

Numerical Methods for Differential Equations – p. 6/52

Some differential equations we will solve

◮ Initial value problems (IVP) first-order equations;higher-order equations; systems of differentialequations

◮ Boundary value problems (BVP) two-point boundaryvalue problems; Sturm-Liouville eigenvalue problems

Numerical Methods for Differential Equations – p. 6/52

Some differential equations we will solve

◮ Initial value problems (IVP) first-order equations;higher-order equations; systems of differentialequations

◮ Boundary value problems (BVP) two-point boundaryvalue problems; Sturm-Liouville eigenvalue problems

◮ Partial differential equations (PDE) the diffusionequation; the advection equation; the wave equation

Numerical Methods for Differential Equations – p. 6/52

Some differential equations we will solve

◮ Initial value problems (IVP) first-order equations;higher-order equations; systems of differentialequations

◮ Boundary value problems (BVP) two-point boundaryvalue problems; Sturm-Liouville eigenvalue problems

◮ Partial differential equations (PDE) the diffusionequation; the advection equation; the wave equation

◮ Applications in all three areas

Numerical Methods for Differential Equations – p. 6/52

Initial value problems: examples

A first-order equation: a simple equation without a knownanalytical solution

dy

dt= y − e−t2 , y(0) = y0

Numerical Methods for Differential Equations – p. 7/52

Initial value problems: examples

A first-order equation: a simple equation without a knownanalytical solution

A second-order equation: motion of a pendulum

θ′′(t) +g

Lsin θ(t) = 0, θ(0) = θ0, θ′(0) = θ′0

where θ(t) is the angle, g is the gravitational constant andL is the pendulum length

Numerical Methods for Differential Equations – p. 7/52

Initial value problems: examples

A first-order equation: a simple equation without a knownanalytical solution

A second-order equation: pendulum equation

A system of equations: the predator–prey model

y′1(t) = k1 y1(t) − k2 y1(t) y2(t)

y′2(t) = k3 y1(t) y2(t) − k4y2(t)

where y1(t) is the population of the prey species and y2(t)

is the population of the predator species at time t

Numerical Methods for Differential Equations – p. 7/52

Boundary value problems: examples

Second-order two-point BVP: the electrostatic potentialu(r) between two concentric metal spheres satisfies

d2u

dr2+

2

r

du

dr= 0, u(R1) = V1, u(R2) = 0

at the distance r from the center; R1 and R2 are the radii ofthe two spheres

Numerical Methods for Differential Equations – p. 8/52

Boundary value problems: examples

Second-order two-point BVP: the electrostatic potentialu(r) between two concentric metal spheres satisfies

d2u

dr2+

2

r

du

dr= 0, u(R1) = V1, u(R2) = 0

at the distance r from the center; R1 and R2 are the radii ofthe two spheres

A Sturm-Liouville eigenproblem: Euler buckling of column

y′′ + λy = 0, y′(0) = 0, y(1) = 0

Find eigenvalues λ and eigenfunctions y

Numerical Methods for Differential Equations – p. 8/52

Partial differential equations: examples

The heat equation

ut(x, t) = uxx(x, t), x ∈ [0, a), t ∈ (0, b)

u(x, 0) = f(x), x ∈ [0, a]

u(0, t) = c1, u(a, t) = c2, t ∈ [0, b]

is a parabolic PDE modelling e.g. the temperature in aninsulated rod with constant temperatures c1 and c2 at itsends, and initial temperature distribution f(x)

Numerical Methods for Differential Equations – p. 9/52

Partial differential equations: examples

The heat equation

The wave equation

utt(x, t) = uxx(x, t), x ∈ (0, a), t ∈ (0, b)

u(0, t) = 0, u(a, t) = 0 for t ∈ [0, b]

u(x, 0) = f(x) for x ∈ [0, a]

ut(x, 0) = g(x) for x ∈ (0, a)

is a hyperbolic PDE e.g. modelling the displacement u of avibrating elastic string fixed at x = 0 and x = a

Numerical Methods for Differential Equations – p. 9/52

Some applications in ODEs

Initial value problems

• mechanics Mq = F (q)

• electrical circuits Cv = −I(v)• chemical reactions c = f(c)

Boundary value problems

• materials u′′ = M(u)/EI

• microphysics − ~

2mψ′′ = E

• eigenmodes u′′ + λu = 0

Numerical Methods for Differential Equations – p. 10/52

1. Initial value problems

Standard formulation

y′ = f(t, y) ; y(0) = y0

Scalar equation: y ∈ R; f scalar;Systems of ODEs: y ∈ R

m; f vector-valued.

Theorem (Cauchy & Peano) A solution to y′ = f(t, y)

exists if f is continuous.

Numerical Methods for Differential Equations – p. 11/52

Existence

Note: Continuity is not sufficient to guarantee uniqueness!

Example:

y = 2√y; y(0) = 0 with solution

y(t) = 0, t ≤ τ and y(t) = (t− τ)2, t > τ

This may happen in real physical models!

Consider the energy of a falling particle of mass m:12my2 +mgy = E := 0

This yields y = −√2g

√−y with y(0) = 0

Numerical Methods for Differential Equations – p. 12/52

Existence and uniqueness

Theorem If f(t, y) is continuous on [0, T ] and satisfies theLipschitz condition

‖f(t, u) − f(t, v)‖ ≤ L[f ] · ‖u− v‖

for all u, v and some Lipschitz constant L[f ] <∞, thereexists a unique solution to the initial value problem

y′ = f(t, y)

on [0, T ] for every initial value y(0) = y0

Numerical Methods for Differential Equations – p. 13/52

Existence and uniqueness . . .

Note Most problems do not satisfy a Lipschitz conditionon all of R

m

Example The problem

y = y2; y(0) = y0 > 0

has solution

y(t) = y0

1−y0t

The solution blows up at t = 1/y0 (“Finite escape time”)

Numerical Methods for Differential Equations – p. 14/52

Existence and uniqueness . . .

Other problems always satisfy Lipschitz conditions on Rm

Example

y = Ay; y(0) = y0

Lipschitz constant:

L[f ] = maxu 6=v‖Au−Av‖‖u−v‖

= maxy 6=0‖Ay‖‖y‖

= ‖A‖

The matrix norm ‖A‖ is a Lipschitz constant for f(y) = Ay

Numerical Methods for Differential Equations – p. 15/52

Standard form: x′ = F (t, x)

Example

y′′ = f(t, y, y′); y(0) = y0; y′(0) = y′0

Standard substitution Introduce new variables

x1 = y

x2 = y′

Then we get a system of first order equations

x′1 = x2

x′2 = f(t, x1, x2)

with x1(0) = y0 and x2(0) = y′0

Numerical Methods for Differential Equations – p. 16/52

2. The Explicit Euler method (1768)

y′ = f(t, y); y(t0) = y0

Replace derivative by finite difference approximation

y′(tn) ≈ y(tn + h) − y(tn)

h

Let {un} denote the numerical approximation to {y(tn)} and

h = tn+1 − tn denote the time-step.

Numerical Methods for Differential Equations – p. 17/52

2. The Explicit Euler method (1768)

y′ = f(t, y); y(t0) = y0

Replace derivative by finite difference approximation

y′(tn) ≈ y(tn + h) − y(tn)

h

Let {un} denote the numerical approximation to {y(tn)} and

h = tn+1 − tn denote the time-step. Compute un from

un+1 − un

h= f(tn, un), u0 = y0

Numerical Methods for Differential Equations – p. 17/52

2. The Explicit Euler method (1768)

y′ = f(t, y); y(t0) = y0

Replace derivative by finite difference approximation

y′(tn) ≈ y(tn + h) − y(tn)

h

Let {un} denote the numerical approximation to {y(tn)} and

h = tn+1 − tn denote the time-step. Compute un from

un+1 − un

h= f(tn, un), u0 = y0

The Explicit Euler method Given u0, t0 and h, compute

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

tn+1 = tn + h

Numerical Methods for Differential Equations – p. 17/52

Explicit Euler: Taylor series expansion

y′(t) = f(t, y), y(t0) = y0

Use Taylor series expansion

y(t + h) = y(t) + hy′(t) +h2

2!y′′(ζ)

= y(t) + hf(t, y(t)) + O(h2) ⇒y(t + h) ≈ y(t) + hf(t, y(t))

Numerical Methods for Differential Equations – p. 18/52

Explicit Euler: Taylor series expansion

y′(t) = f(t, y), y(t0) = y0

Use Taylor series expansion

y(t + h) = y(t) + hy′(t) +h2

2!y′′(ζ)

= y(t) + hf(t, y(t)) + O(h2) ⇒y(t + h) ≈ y(t) + hf(t, y(t))

Construct the numerical method (drop higher order terms)

un+1 = un + hf(tn, un); u0 = y0

tn+1 = tn + h

Numerical Methods for Differential Equations – p. 18/52

Explicit Euler: Taylor series expansion

y′(t) = f(t, y), y(t0) = y0

Use Taylor series expansion

y(t + h) = y(t) + hy′(t) +h2

2!y′′(ζ)

= y(t) + hf(t, y(t)) + O(h2) ⇒y(t + h) ≈ y(t) + hf(t, y(t))

Construct the numerical method (drop higher order terms)

un+1 = un + hf(tn, un); u0 = y0

tn+1 = tn + h

Explicit Euler!

Numerical Methods for Differential Equations – p. 18/52

Explicit Euler: graphic interpretation

“Take a step of size h in the direction of the tangent”

0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.7

0.75

0.8

0.85

0.9

0.95

1

1.05

1.1

1.15

1.2

t

y

Each step introduces an error and ends up on a differentsolution trajectory (dashed curves)

Numerical Methods for Differential Equations – p. 19/52

Explicit Euler: an example

Compute numerical solution to y′ = −y cos t; y(0) = 1; t ∈ [0, 2π]

Solution Choose a stepsize h = 2π/N ; N = 24 ⇒ h = π/12

Recursion un+1 = un + h (−un cos tn); u0 = 1

tn+1 = tn + h; t0 = 0

0 1 2 3 4 5 6 70.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

0 1 2 3 4 5 6 70.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

The numerical solution is a sequence of points (tn, un)

Numerical Methods for Differential Equations – p. 20/52

3. Convergence

Analytical and numerical solutions for h = π/8 and π/128

0 5 10 15 20 250

0.5

1

1.5

2

2.5

3

N=64

0 5 10 15 20 250

0.5

1

1.5

2

2.5

3

N=64*16

As h → 0 the numerical solution approaches the exact solution

Numerical Methods for Differential Equations – p. 21/52

3. Convergence

Analytical and numerical solutions for h = π/8 and π/128

0 5 10 15 20 250

0.5

1

1.5

2

2.5

3

N=64

0 5 10 15 20 250

0.5

1

1.5

2

2.5

3

N=64*16

As h → 0 the numerical solution approaches the exact solution

A method is convergent if, for every ODE with a Lipschitz

function f and every fixed T , with T = N · h, it holds that

limN→∞

‖yN,h − y(T )‖ = 0

Numerical Methods for Differential Equations – p. 21/52

Local and global errors

1.3 1.35 1.4 1.45 1.5 1.55 1.6 1.65 1.7 1.75 1.80.95

1

1.05

1.1

1.15

t

yyn+1•

yn•yn+1

y(t)y(tn)• •

y(tn+1)

Global error en = yn − y(tn) and en+1 = yn+1 − y(tn+1)

Local error ln+1 = yn+1 − y(tn+1)

Numerical Methods for Differential Equations – p. 22/52

The local error of the explicit Euler method

Insert exact data

yn+1 = y(tn) + hf(tn, y(tn))

Local error definition ln+1 = yn+1 − y(tn+1) implies residual

y(tn+1) = y(tn) + hf(tn, y(tn))− ln+1

Taylor series y(tn+1) = y(tn) + hy′(tn) + h2

2y′′(tn) + . . . ⇒

Local error for explicit Euler ln+1 ≈ − h2

2y′′(tn)

(along exact solution, solid curve)

Numerical Methods for Differential Equations – p. 23/52

Error propagation

Explicit Euler (numerical solution)

yn+1 = yn + hf(tn, yn)

Subtract Taylor series expansion of exact solution

y(tn+1) = y(tn) + hf(tn, y(tn)) +h2

2y′′(tn) + . . .

Global error recursion

en+1 = en + hf(tn, y(tn) + en) − hf(tn, y(tn)) + ln+1

Numerical Methods for Differential Equations – p. 24/52

Error propagation . . .

en+1 = en + hf(tn, y(tn) + en) − hf(tn, y(tn)) + ln+1

Take norms and use Lipschitz condition:

‖en+1‖ ≤ ‖en‖ + hL[f ] · ‖en‖ + ‖ln+1‖

Lemma If {an}, a0 = 0, is a sequence of non-negativenumbers satisfying

an+1 ≤ (1 + hµ)an + ch2 for µ > 0, then

an ≤ c

µh [(1 + hµ)n − 1], n = 0, 1, . . .

Numerical Methods for Differential Equations – p. 25/52

Convergence of Euler’s method: Theorem

Theorem The explicit Euler method is convergent

Numerical Methods for Differential Equations – p. 26/52

Convergence of Euler’s method: Theorem

Theorem The explicit Euler method is convergent

Proof Suppose f sufficiently differentiable. Given h and afixed T = Nh, let en,h = yn,h − y(tn)

Numerical Methods for Differential Equations – p. 26/52

Convergence of Euler’s method: Theorem

Theorem The explicit Euler method is convergent

Proof Suppose f sufficiently differentiable. Given h and afixed T = Nh, let en,h = yn,h − y(tn)

Apply the lemma to global error recursion, to get

‖en,h‖ ≤ c

L[f ]h [(1 + hL[f ])n − 1], n = 0, 1, . . .

withc = max

n‖ln‖/h2 ≈ max

t‖y′′‖/2

Numerical Methods for Differential Equations – p. 26/52

Convergence of Euler’s method . . .

As (1 + hL[f ])n < enhL[f ] ≤ eTL[f ], we have for n ≤ N ,

‖en,h‖ ≤ c

L[f ]h (eTL[f ] − 1)

So‖en,h‖ ≤ C(T ) · h

implies convergence because

limh→0

‖en,h‖ = 0

Note 1) The global error can be made arbitrarily small!2) The error is way too large for practical purposes!3) Better bounds can be obtained

Numerical Methods for Differential Equations – p. 27/52

Theoretical error “bound”

Example

y′ = −100y, y(0) = 1.

Then L[f ] = 100 and the exact solution is y(t) = e−100t with

y′′(t) = 1002e−100t, so c = 1002/2, with bound

‖en,h‖ ≤ 1002

2 · 100 h (e100T − 1)

Numerical Methods for Differential Equations – p. 28/52

Theoretical error “bound”

Example

y′ = −100y, y(0) = 1.

Then L[f ] = 100 and the exact solution is y(t) = e−100t with

y′′(t) = 1002e−100t, so c = 1002/2, with bound

‖en,h‖ ≤ 1002

2 · 100 h (e100T − 1)

Error estimate at T = 1 is ‖en,h‖ ≤ 50h e100 ≈ 1.4 · 1045h !

Numerical Methods for Differential Equations – p. 28/52

Theoretical error “bound”

Example

y′ = −100y, y(0) = 1.

Then L[f ] = 100 and the exact solution is y(t) = e−100t with

y′′(t) = 1002e−100t, so c = 1002/2, with bound

‖en,h‖ ≤ 1002

2 · 100 h (e100T − 1)

Error estimate at T = 1 is ‖en,h‖ ≤ 50h e100 ≈ 1.4 · 1045h !

But yn = (1 − 100h)n, so for h < 1/50, at T = 1 ,

Actual error is ‖en,h‖ = |(1− 100/N)N − e−100| ≤ 3.7 · 10−44h !

Numerical Methods for Differential Equations – p. 28/52

Computational test y = λ(y − sin t) + cos t

λ = −0.2 , with initial condition y(π/4) = 1/√

2

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

h = π/10 h = π/20

Note Local error O(h2), global error O(h)!

Numerical Methods for Differential Equations – p. 29/52

4. Order of consistency

Given a method in the form yn+1 = Φn(f, h, y0, y1, . . . , yn)

Insert exact data y(t0), y(t1), . . . , y(tn)

Definition The order of consistency is p if

y(tn+1) − Φn(f, h, y(t0), y(t1), . . . , y(tn)) = O(hp+1), ∀n

as h→ 0, for every analytic f

Theorem The local error is then O(hp+1)

Numerical Methods for Differential Equations – p. 30/52

4. Order of consistency

Given a method in the form yn+1 = Φn(f, h, y0, y1, . . . , yn)

Insert exact data y(t0), y(t1), . . . , y(tn)

Definition The order of consistency is p if

y(tn+1) − Φn(f, h, y(t0), y(t1), . . . , y(tn)) = O(hp+1), ∀n

as h→ 0, for every analytic f

Theorem The local error is then O(hp+1)

Alternative The order of consistency is p if the formula isexact for all polynomials y = P (t) of degree p or less

Numerical Methods for Differential Equations – p. 30/52

Order of consistency of Euler’s method

Example Explicit Euler Φn(f, h, y0, . . . , yn) = yn + h f(tn, yn)

Numerical Methods for Differential Equations – p. 31/52

Order of consistency of Euler’s method

Example Explicit Euler Φn(f, h, y0, . . . , yn) = yn + h f(tn, yn)

Expanding in Taylor series,

y(tn+1) − [y(tn) + h f(tn, y(tn))] = O(h2)

so the method’s consistency order is one

Numerical Methods for Differential Equations – p. 31/52

Order of consistency of Euler’s method

Example Explicit Euler Φn(f, h, y0, . . . , yn) = yn + h f(tn, yn)

Expanding in Taylor series,

y(tn+1) − [y(tn) + h f(tn, y(tn))] = O(h2)

so the method’s consistency order is one

◮ Alternatively, suppose y(t) = 1 with f = y′ = 0. Then

1 = y(tn+1) = y(tn) + hf(tn, y(tn)) = 1 + h · 0 = 1 ⇒ exact!

Numerical Methods for Differential Equations – p. 31/52

Order of consistency of Euler’s method

Example Explicit Euler Φn(f, h, y0, . . . , yn) = yn + h f(tn, yn)

Expanding in Taylor series,

y(tn+1) − [y(tn) + h f(tn, y(tn))] = O(h2)

so the method’s consistency order is one

◮ Alternatively, suppose y(t) = 1 with f = y′ = 0. Then

1 = y(tn+1) = y(tn) + hf(tn, y(tn)) = 1 + h · 0 = 1 ⇒ exact!

◮ Next take 1st degree polynomial y(t) = t with f = y′ = 1, then

h = y(tn+1) = y(tn) + hf(tn, y(tn)) = 0 + h · 1 = h ⇒ exact!

Numerical Methods for Differential Equations – p. 31/52

Order of consistency of Euler’s method

Example Explicit Euler Φn(f, h, y0, . . . , yn) = yn + h f(tn, yn)

Expanding in Taylor series,

y(tn+1) − [y(tn) + h f(tn, y(tn))] = O(h2)

so the method’s consistency order is one

◮ Alternatively, suppose y(t) = 1 with f = y′ = 0. Then

1 = y(tn+1) = y(tn) + hf(tn, y(tn)) = 1 + h · 0 = 1 ⇒ exact!

◮ Next take 1st degree polynomial y(t) = t with f = y′ = 1, then

h = y(tn+1) = y(tn) + hf(tn, y(tn)) = 0 + h · 1 = h ⇒ exact!

◮ For a 2nd degree polynomial, y(t) = t2 with f = y′ = 2t. Then

h2 = y(tn+1) = y(tn)+hf(tn, y(tn)) = 0+h ·0 = 0 6= h2 ⇒ p = 1 !

Numerical Methods for Differential Equations – p. 31/52

5. The trapezoidal rule

Explicit Euler linearizes y at tn with a slope of y′(tn)

Numerical Methods for Differential Equations – p. 32/52

5. The trapezoidal rule

Explicit Euler linearizes y at tn with a slope of y′(tn)

Instead, linearize with a slope equal to the average of y′(tn)

and y′(tn+1)

y(t) ≈ y(tn) + (t− tn)1

2[f(tn, y(tn)) + f(tn+1, y(tn+1))]

Numerical Methods for Differential Equations – p. 32/52

5. The trapezoidal rule

Explicit Euler linearizes y at tn with a slope of y′(tn)

Instead, linearize with a slope equal to the average of y′(tn)

and y′(tn+1)

y(t) ≈ y(tn) + (t− tn)1

2[f(tn, y(tn)) + f(tn+1, y(tn+1))]

The numerical method is the trapezoidal rule

tn+1 = tn + h

yn+1 = yn +h

2[f(tn, yn) + f(tn+1, yn+1)]

Numerical Methods for Differential Equations – p. 32/52

5. The trapezoidal rule

Explicit Euler linearizes y at tn with a slope of y′(tn)

Instead, linearize with a slope equal to the average of y′(tn)

and y′(tn+1)

y(t) ≈ y(tn) + (t− tn)1

2[f(tn, y(tn)) + f(tn+1, y(tn+1))]

The numerical method is the trapezoidal rule

tn+1 = tn + h

yn+1 = yn +h

2[f(tn, yn) + f(tn+1, yn+1)]

The method is implicit . Nonlinear equation solving required

Numerical Methods for Differential Equations – p. 32/52

Trapezoidal rule: Order and convergence

Order of consistency (sketch):

y(tn+1) − {y(tn) +h

2[f(tn, y(tn)) + f(tn+1, y(tn+1))]}

= y(tn) + h y′(tn) +h2

2y′′(tn) + O(h3)

−{y(tn) +h

2(y′(tn) + [y′(tn) + h y′′(tn) + O(h2)])}

= O(h3)

Numerical Methods for Differential Equations – p. 33/52

Trapezoidal rule: Order and convergence

Order of consistency (sketch):

y(tn+1) − {y(tn) +h

2[f(tn, y(tn)) + f(tn+1, y(tn+1))]}

= y(tn) + h y′(tn) +h2

2y′′(tn) + O(h3)

−{y(tn) +h

2(y′(tn) + [y′(tn) + h y′′(tn) + O(h2)])}

= O(h3)

The method is of order two

Numerical Methods for Differential Equations – p. 33/52

Trapezoidal rule: Order and convergence

Order of consistency (sketch):

y(tn+1) − {y(tn) +h

2[f(tn, y(tn)) + f(tn+1, y(tn+1))]}

= y(tn) + h y′(tn) +h2

2y′′(tn) + O(h3)

−{y(tn) +h

2(y′(tn) + [y′(tn) + h y′′(tn) + O(h2)])}

= O(h3)

The method is of order two

Theorem The trapezoidal rule is convergent(No proof given here)

Numerical Methods for Differential Equations – p. 33/52

Trapezoidal rule: the dramatic effect of 2nd order

Compute numerical solution to y′ = −y cos t; y(0) = 1; t ∈ [0, 8π].

Choose h = π/12. Note that f is linear in y. The recursion is

un+1 =1 − h

2 cos tn

1 + h2 cos tn+1

un ; u0 = 1

0 5 10 15 20 250

0.5

1

1.5

2

2.5

3

N=96 Trapezoidal rule

0 5 10 15 20 250

0.5

1

1.5

2

2.5

3

N=96 Explicit Euler

Solutions with Trapezoidal rule and Explicit Euler

Numerical Methods for Differential Equations – p. 34/52

The implicit midpoint rule

We can also approximate the derivative y′(t) by taking the

average of tn and tn+1 as well as yn and yn+1:

y′(t) ≈ f(tn + tn+1

2,yn + yn+1

2), t ∈ [tn, tn+1]

Numerical Methods for Differential Equations – p. 35/52

The implicit midpoint rule

We can also approximate the derivative y′(t) by taking the

average of tn and tn+1 as well as yn and yn+1:

y′(t) ≈ f(tn + tn+1

2,yn + yn+1

2), t ∈ [tn, tn+1]

The resulting method is the 2nd order implicit midpoint method

tn+1 = tn + h

yn+1 = yn + h f(tn + tn+1

2,yn + yn+1

2)

Numerical Methods for Differential Equations – p. 35/52

6. Theta methods

We construct methods that linearize y at tn with a slope equal to

a convex combination of y′(tn) and y′(tn+1):

yn+1 = yn + h [θf(tn, yn) + (1 − θ)f(tn+1, yn+1)], θ ∈ [0, 1]

◮ Explicit Euler: θ = 1

◮ Trapezoidal rule (implicit): θ = 1/2

◮ Implicit Euler: θ = 0 ⇒ yn+1 = yn + h f(tn+1, yn+1)

Numerical Methods for Differential Equations – p. 36/52

Theta methods: Order and convergence

Use Taylor expansion to get

y(tn+1) − y(tn) − h [θf(tn, y(tn)) + (1 − θ)f(tn+1, y(tn+1))]

= (θ − 1

2)h2y′′(tn) +

1

2(θ − 2

3)h3y′′′(tn) + O(h4)

Numerical Methods for Differential Equations – p. 37/52

Theta methods: Order and convergence

Use Taylor expansion to get

y(tn+1) − y(tn) − h [θf(tn, y(tn)) + (1 − θ)f(tn+1, y(tn+1))]

= (θ − 1

2)h2y′′(tn) +

1

2(θ − 2

3)h3y′′′(tn) + O(h4)

If θ = 1/2 the method is of order 2; otherwise it is of order 1

Numerical Methods for Differential Equations – p. 37/52

Theta methods: Order and convergence

Use Taylor expansion to get

y(tn+1) − y(tn) − h [θf(tn, y(tn)) + (1 − θ)f(tn+1, y(tn+1))]

= (θ − 1

2)h2y′′(tn) +

1

2(θ − 2

3)h3y′′′(tn) + O(h4)

If θ = 1/2 the method is of order 2; otherwise it is of order 1

Theorem (without proof) The θ methods are convergent

Numerical Methods for Differential Equations – p. 37/52

Implicit methods

Implicit Euler yn+1 = yn + h f(tn+1, yn+1)

We need to solve a nonlinear equation to compute yn+1

The extra cost is motivated if we can take larger steps

There are some problems where implicit methods can takeenormous time steps without losing accuracy!

We will return to how to solve nonlinear equations

Numerical Methods for Differential Equations – p. 38/52

7. Tests: Explicit Euler y = λ(y − sin t) + cos t

λ = −0.2 , with initial condition y(π/4) = 1/√

2

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

h = π/10 h = π/20

Local error O(h2), global error O(h)!

Numerical Methods for Differential Equations – p. 39/52

Tests: Implicit Euler y = λ(y − sin t) + cos t

λ = −0.2 , with initial condition y(π/4) = 1/√

2

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

h = π/10 h = π/20

Local error O(h2), global error O(h)!

Numerical Methods for Differential Equations – p. 40/52

Tests: Implicit Euler y = λ(y − sin t) + cos t

λ = −10 , with initial condition y(π/4) = 1/√

2

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

h = π/10 h = π/20

Local error = O(h2), global error = O(h), but difficult to see!

Numerical Methods for Differential Equations – p. 41/52

Tests: Explicit Euler y = λ(y − sin t) + cos t

λ = −10 , with initial condition y(π/4) = 1/√

2

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

h = π/20

Numerical Methods for Differential Equations – p. 42/52

Tests: Explicit Euler y = λ(y − sin t) + cos t

λ = −10 , with initial condition y(π/4) = 1/√

2

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

h = π/10 h = π/20

NUMERICAL INSTABILITY! Stability for h small

Numerical Methods for Differential Equations – p. 42/52

8. The linear test equation

Defintion The linear test equation is

y′ = λy; y(0) = 1, t ≥ 0, where λ ∈ C

Numerical Methods for Differential Equations – p. 43/52

8. The linear test equation

Defintion The linear test equation is

y′ = λy; y(0) = 1, t ≥ 0, where λ ∈ C

As y(t) = eλt, we have

|y(t)| ≤ K ⇔ Re(λ) ≤ 0

Mathematical stability Bounded solutions if Re(λ) ≤ 0

Numerical Methods for Differential Equations – p. 43/52

8. The linear test equation

Defintion The linear test equation is

y′ = λy; y(0) = 1, t ≥ 0, where λ ∈ C

As y(t) = eλt, we have

|y(t)| ≤ K ⇔ Re(λ) ≤ 0

Mathematical stability Bounded solutions if Re(λ) ≤ 0

When does a numerical method have the same property?

Does Re(λ) ≤ 0 imply numerical stability ?

Numerical Methods for Differential Equations – p. 43/52

Numerical stability: The stability region

Definition The stability region D of a method is the set of all

hλ ∈ C such that |yn| ≤ K when the method is applied to the test

equation

4

Numerical Methods for Differential Equations – p. 44/52

Numerical stability: The stability region

Definition The stability region D of a method is the set of all

hλ ∈ C such that |yn| ≤ K when the method is applied to the test

equation

Example For Euler’s method, yn+1 = (1 + hλ)yn, so yn remains

bounded if and only if |1 + hλ| ≤ 1

4

Numerical Methods for Differential Equations – p. 44/52

Numerical stability: The stability region

Definition The stability region D of a method is the set of all

hλ ∈ C such that |yn| ≤ K when the method is applied to the test

equation

Example For Euler’s method, yn+1 = (1 + hλ)yn, so yn remains

bounded if and only if |1 + hλ| ≤ 1

−4 −3 −2 −1 0 1 2 3 4−4

−3

−2

−1

0

1

2

3

4

DEuler = {z ∈ C : |1 + z| ≤ 1}

Numerical Methods for Differential Equations – p. 44/52

A-stability

Definition A method is called A-stable if its stability region

contains C−, i.e. C− ≡ {z ∈ C : Re(z) ≤ 0} ⊂ D.

Numerical Methods for Differential Equations – p. 45/52

A-stability

Definition A method is called A-stable if its stability region

contains C−, i.e. C− ≡ {z ∈ C : Re(z) ≤ 0} ⊂ D.

For the trapezoidal rule

DTR =

{

z ∈ C :

1 + 12z

1 − 12z

≤ 1

}

≡ C−

so if Re(z) ≤ 0 then yn remains bounded for any h > 0

Numerical Methods for Differential Equations – p. 45/52

A-stability

Definition A method is called A-stable if its stability region

contains C−, i.e. C− ≡ {z ∈ C : Re(z) ≤ 0} ⊂ D.

For the trapezoidal rule

DTR =

{

z ∈ C :

1 + 12z

1 − 12z

≤ 1

}

≡ C−

so if Re(z) ≤ 0 then yn remains bounded for any h > 0

The explicit Euler method is not A-stable but the implicit Euler

method and the trapezoidal rule are A-stable

Usually: “If the original problem is stable, then an A-stable

method will replicate that behavior numerically”

Numerical Methods for Differential Equations – p. 45/52

Relevance of the linear test equation

When we have a system of equations

y′ = Ay

and A has a full set of eigenvectors with eigenvalues

Λ = diag(λ1, λ2, . . . , λN ), then

◮ A can be diagonalized, T−1AT = Λ

◮ Putting y = Tx transforms the system to x′ = Λx (scalar

systems)

◮ . . . equal to x′k = λkxk for k = 1, . . . , d

◮ The exact solution y(t) = etAy0 is stable if and only if

Re(λk) ≤ 0 for all k = 1, . . . , d

Numerical Methods for Differential Equations – p. 46/52

Relevance of the linear test equation . . .

Applying a method to y′ = Ay gives (say)

yn+1 = (I + hA)yn

Numerical Methods for Differential Equations – p. 47/52

Relevance of the linear test equation . . .

Applying a method to y′ = Ay gives (say)

yn+1 = (I + hA)yn

Noting that T−1(I + hA)T = I + hΛ, putting yn = Txn produces

xn+1 = (I + hΛ)xn

Numerical Methods for Differential Equations – p. 47/52

Relevance of the linear test equation . . .

Applying a method to y′ = Ay gives (say)

yn+1 = (I + hA)yn

Noting that T−1(I + hA)T = I + hΛ, putting yn = Txn produces

xn+1 = (I + hΛ)xn

The same as applying the method to the diagonalized system

x′ = Λx

Numerical Methods for Differential Equations – p. 47/52

Relevance of the linear test equation . . .

Applying a method to y′ = Ay gives (say)

yn+1 = (I + hA)yn

Noting that T−1(I + hA)T = I + hΛ, putting yn = Txn produces

xn+1 = (I + hΛ)xn

The same as applying the method to the diagonalized system

x′ = Λx

Diagonalization and discretization commute! Stability condition

from linear test equation applies to all diagonalizable systems!

Numerical Methods for Differential Equations – p. 47/52

9. Stiff ODEs

Example Solve y = λ(y − sin t) + cos t with λ = −50

Solution

Particular: yP (t) = sin t

Homogeneous: yH(t) = eλt

General: y(t) = eλ(t−t0)(y(t0) − sin t0) + sin t

Study the flow of this equation and numerical solutions

Numerical Methods for Differential Equations – p. 48/52

Flow (solution trajectories)

0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.40.4

0.5

0.6

0.7

0.8

0.9

1

1.1

1.2

t

y

Numerical Methods for Differential Equations – p. 49/52

Stiffness. . .

With Explicit Euler the solution approaches sin t as t→ ∞,

as the exact solution does, only if 0 < h <1

25

Numerical Methods for Differential Equations – p. 50/52

Stiffness. . .

With Explicit Euler the solution approaches sin t as t→ ∞,

as the exact solution does, only if 0 < h <1

25

This means h must be kept small, not to keep errors small,but to have a stable numerical solution

Numerical Methods for Differential Equations – p. 50/52

Stiffness. . .

With Explicit Euler the solution approaches sin t as t→ ∞,

as the exact solution does, only if 0 < h <1

25

This means h must be kept small, not to keep errors small,but to have a stable numerical solution

The trapezoidal rule solution tends to sin t as t→ ∞, as theexact solution does, for every h > 0

This means h must be kept small only to keep errors small

Numerical Methods for Differential Equations – p. 50/52

Stiffness. . .

With Explicit Euler the solution approaches sin t as t→ ∞,

as the exact solution does, only if 0 < h <1

25

This means h must be kept small, not to keep errors small,but to have a stable numerical solution

The trapezoidal rule solution tends to sin t as t→ ∞, as theexact solution does, for every h > 0

This means h must be kept small only to keep errors small

For A-stable methods, there is no stability restriction on hThe step size is only restricted by accuracy

Numerical Methods for Differential Equations – p. 50/52

Stiffness. . .

Stiff differential equations are characterized byhomogeneous solutions being strongly damped

Example y = λ(y − sin t) + cos t with λ≪ −1

Stability regions of explicit methods are bounded, andhλ ∈ D puts a strong stability restriction on h

Example Explicit Euler applied to the problem aboverequires h ≤ −2/λ≪ 1

Numerical Methods for Differential Equations – p. 51/52

Stiffness. . .

Implicit methods with unbounded stability regions put norestrictions on h, and the stepsize is only restricted byaccuracy requirement!

Example The implicit Euler applied to the problem aboverequires only that

ln ≈ h2y′′

2≈ h2

2sin tn

is sufficiently small, independently of λ

Numerical Methods for Differential Equations – p. 52/52