Finite difference method for heat...

46
Finite difference method for heat equation Praveen. C [email protected] Tata Institute of Fundamental Research Center for Applicable Mathematics Bangalore 560065 http://math.tifrbng.res.in/ ~ praveen January 25, 2013 1 / 46

Transcript of Finite difference method for heat...

Page 1: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Finite difference method for heat equation

Praveen. [email protected]

Tata Institute of Fundamental ResearchCenter for Applicable Mathematics

Bangalore 560065http://math.tifrbng.res.in/~praveen

January 25, 2013

1 / 46

Page 2: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Heat equation: Initial value problem

• Partial differential equation, µ > 0

ut = µuxx, (x, t) ∈ R× R+

u(x, 0) = f(x), x ∈ R

• Exact solution

u(x, t) =1√

4πµt

∫ +∞

−∞e−y

2/4µtf(x− y)dy =: (E(t)f)(x)

• Solution bounded in maximum norm

‖u(t)‖C = ‖E(t)f‖C ≤ ‖f‖C = supx∈R|f(x)|

2 / 46

Page 3: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

• Finite difference mesh in space and time: partition space R by a uniformmesh of size h and time R+ by a uniform mesh of size ∆t

xj = jh, j = . . . ,−2,−1, 0,+1,+2, . . .

tn = n∆t, n = 0, 1, 2, . . .

x

t

j

n

∆x

∆t

• Let the numerical approximation be

Unj ≈ u(xj , tn)

3 / 46

Page 4: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

• Finite difference in spaceFirst derivative:

D+x U

nj =

Unj+1 − Unjh

, D−x Unj =

Unj − Unj−1

h, D0

xUnj =

Unj+1 − Unj−1

2h

Second derivative:

D+xD−x U

nj =

Unj−1 − 2Unj + Unj+1

h2

• Finite difference in time

D+t U

nj =

Un+1j − Unj

∆t

4 / 46

Page 5: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

• Finite difference scheme: forward time and central space (FTCS)

D+t U

nj = µD+

xD−x U

nj , n = 0, 1, 2, . . .

i.e.,Un+1j − Unj

∆t= µ

Unj−1 − 2Unj + Unj+1

h2

• Update equation: Solve for Un+1j

Un+1j = (EhU

n)j = λUnj−1 + (1− 2λ)Unj + λUnj+1

where

λ =µ∆t

h2

• Explicit schemeUn+1 = H(Un)

5 / 46

Page 6: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Maximum principle• If λ ≤ 1/2, then Un+1

j is given by a convex linear combination ofUnj−1, U

nj , U

nj+1. Hence

min(Unj−1, Unj , U

nj+1) ≤ Un+1

j ≤ max(Unj−1, Unj , U

nj+1)

minkUnk ≤ Un+1

j ≤ maxk

Unk , ∀j

• Hence solution at any time level n is bounded by initial data

minkU0k ≤ Unj ≤ max

kU0k , ∀j, ∀n

• Maximum norm‖U‖∞ = sup

j|Uj |

• Maximum stability: If λ ≤ 1/2, then

∥∥Un+1∥∥∞ = ‖EhUn‖∞ ≤ ‖Un‖∞ ≤ . . . ≤

∥∥U0∥∥∞

and hence‖Un‖∞ ≤

∥∥U0∥∥∞ = ‖f‖∞ , ∀n

6 / 46

Page 7: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Maximum principle

• We have‖EhV ‖∞ ≤ ‖V ‖∞ ‖EnhV ‖∞ ≤ ‖V ‖∞

• λ ≤ 1/2 is necessary: Consider initial condition

fj = f(xj) = (−1)jε, 0 < ε� 1

so that ‖f‖∞ = ε

• After one time step

U1j = [λ(−1)j−1 + (1− 2λ)(−1)j + λ(−1)j+1]ε = (1− 4λ)(−1)jε

and after n time steps

Unj = (1− 4λ)n(−1)jε

If λ > 1/2, then

‖Un‖∞ = |1− 4λ|nε→∞ as n→∞

7 / 46

Page 8: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Maximum principle

Remark: The condition λ ≤ 12 implies that the allowed time step ∆t

depends on the space step h as

∆t ≤ h2

2µ=⇒ ∆t = O

(h2)

The scheme is said to be conditionally stable.

8 / 46

Page 9: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Truncation error and consistency

• If u(x, t) is exact solution then with unj = u(xj , tn), the local truncationerror

τnj := D+t u

nj − µD+

xD−x u

nj

Using Taylor’s formula, for some xj ∈ (xj−1, xj+1) andtn ∈ In = (tn, tn+1)

τnj =1

2∆tutt(xj , tn)− 1

12µh2uxxxx(xj , tn)

Using the PDE, we get utt = µ2uxxxx and from the exact solution, wehave |uxxxx|C ≤ |fxxxx|C . The truncation error is bounded as

‖τn‖∞ ≤ C∆tmaxt∈In|utt(t)|C + Ch2|uxxxx(tn)|C

≤ Ch2 maxt∈In|uxxxx(t)|C , since λ ≤ 1/2

≤ Ch2|fxxxx|C

9 / 46

Page 10: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Error estimate

Let Un and un be the numerical and exact solutions, and let λ ≤ 1/2. Thenthere is a constant C such that

‖Un − un‖∞ ≤ Ctnh2|fxxxx|C , tn ≥ 0

Proof: Set en = Un − un. Then

D+t e

nj − µD+

xD−x e

nj = −τnj

and henceen+1j = (Ehe

n)j −∆t τnj

Iterating over time

enj = (Enhe0)j −∆t

n−1∑

l=0

(En−1−lh τ l)j

= −∆t

n−1∑

l=0

(En−1−lh τ l)j since e0 = U0 − u0 = 0

10 / 46

Page 11: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Using the stability estimate and truncation error estimate

‖en‖∞ ≤ ∆t

n−1∑

l=0

∥∥En−1−lh τ l

∥∥∞

≤ ∆t

n−1∑

l=0

∥∥τ l∥∥∞ ,

∥∥En−1−lh τ l

∥∥∞ ≤

∥∥τ l∥∥∞ ≤ Ch

2|fxxxx|C

≤ C(n∆t)h2|fxxxx|C= Ctnh

2|fxxxx|C

Remark: The FTCS scheme has first order accuracy in time and secondorder accuracy in space τnj = O

(∆t+ h2

). Since ∆t = O

(h2)

under thestability condition λ ≤ 1/2, the scheme has second order accuracy with respectto the mesh width h. If h is halved, then the error reduces by 1/4. Butnumber of time steps increases by a factor of 4.

11 / 46

Page 12: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Symbol of Eh

• FTCS scheme

Un+1j = λUnj−1 + (1− 2λ)Unj + λUnj+1

• General finite difference scheme

Un+1j =

p

ap(λ)Unj−p

How does scheme modify one Fourier mode: Unj = gne−ijξ

g = amplitude gn+1(ξ) = Eh(ξ)gn(ξ)

ξ is called the wave number.

• Symbol or characteristic polynomial of Eh

Eh(ξ) =∑

p

ape−ipξ, ξ ∈ R

• Useful in stability analysis: Fourier stability

12 / 46

Page 13: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Necessary condition for maximum stability

A necessary condition for stability of the operator Eh with respect to thediscrete maximum norm is that

|Eh(ξ)| ≤ 1, ∀ ξ ∈ R

Proof: Assume that Eh is stable in maximum norm and that |Eh(ξ0)| > 1 forsome ξ0 ∈ R. Then with initial condition fj = eijξ0ε, the numerical solutionafter one time step is

U1j =

p

apei(j−p)ξ0ε =

(∑

p

ape−ipξ0

)eijξ0ε = Eh(ξ0)fj

By iterating in time, we get Unj = [Eh(ξ0)]nfj and

‖Un‖∞ = |Eh(ξ0)|nε→∞ as n→∞

Since ‖f‖∞ = ε, this contradicts the stability of the scheme and hence thetheorem is proved.

13 / 46

Page 14: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

FTCS scheme

Un+1j = λUnj−1 + (1− 2λ)Unj + λUnj+1

Symbol

Eh(ξ) = λe−iξ + (1− 2λ)e0 + λeiξ = 1− 2λ+ 2λ cos(ξ)

Since cos(ξ) ∈ [−1,+1], the maximum value is attained for cos(ξ) = −1

maxξ|Eh(ξ)| = |1− 4λ| ≤ 1 =⇒ λ ≤ 1

2

which is the condition previously derived for maximum stability.

14 / 46

Page 15: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Discrete Fourier transform

• For any grid function V = {Vj} ∈ R∞ define discrete l2 norm

‖V ‖2,h =

h

j=+∞∑

j=−∞|Vj |2

1/2

• Space of bounded grid functions

l2,h = {V ∈ R∞ : ‖V ‖2,h <∞}

• Discrete Fourier transform

V (ξ) = h

+∞∑

j=−∞Vje−ijξ

• Inverse transform

Vj =1

2πh

∫ +π

−πV (ξ)eijξdξ

15 / 46

Page 16: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Discrete Fourier transform

• Parseval relation

‖V ‖22,h =1

2πh

∫ +π

−π|V (ξ)|2dξ =

1

∫ +π/h

−π/h|V (ξh)|2dξ

Definition: Stability in l2,h

The discrete solution operator Eh is said to be stable in the norm ‖·‖2,h if

‖EhV ‖2,h ≤ ‖V ‖2,h , V ∈ l2,h

16 / 46

Page 17: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Von Neumann stability condition

A necessary and sufficient condition for Eh to be stable in l2,h is given by

|Eh(ξ)| ≤ 1, ξ ∈ R

Proof: For any V ∈ l2,h,

EhV (ξ) = h

∞∑

j=−∞(EhV )je

−ijξ

= h∑

j

p

apVj−pe−ijξ

=∑

p

ape−ipξh

j

Vj−pe−i(j−p)ξ

= Eh(ξ)V (ξ)

and iterating in time

EnhV (ξ) = [Eh(ξ)]nV (ξ)

17 / 46

Page 18: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Using Parseval relation, stability of Eh in l2,h is equivalent to

∫ +π

−π|EnhV (ξ)|2dξ =

∫ +π

−π|Eh(ξ)|2n|V (ξ)|2dξ ≤

∫ +π

−π|V (ξ)|2dξ

which holds if and only if

|Eh(ξ)|n ≤ 1, n ≥ 0, ξ ∈ R

Remark: If the problem is in the time interval (0, T ), then a less restrictivenotion of stability is given by the condition

‖EnhV ‖ ≤ CT ‖V ‖ , 0 ≤ n ≤ T/∆t

If the finite difference scheme satisfies

‖EhV ‖ ≤ (1 +K∆t) ‖V ‖ , K ≥ 0

then this implies

‖EnhV ‖ ≤ (1 +K∆t)n ‖V ‖ ≤ eKn∆t ‖V ‖ ≤ eKT ‖V ‖

18 / 46

Page 19: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Fourier transform in spaceDefine numerical scheme at all x ∈ R, not just at the mesh points

Un+1(x) = (EhUn)(x) =

p

ap(λ)Un(x− xp)

Advantage: All the Un lie in same function space, L2(R) or C(R),independently of h. Define usual L2 norm

‖v‖ =

+∞∫

−∞

|v(x)|2dx

1/2

Fourier transform

v(ξ) =

+∞∫

−∞

v(x)e−ixξdx

Parseval relation

‖v‖2 =1

2π‖v‖2

Then

Ehv(ξ) =∑

p

ap v(· − ph)(ξ) =

(∑

p

ape−iphξ

)v(ξ) = Eh(hξ)v(ξ)

19 / 46

Page 20: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

For the numerical scheme, we thus find

‖Un‖ =1√2π

∥∥∥[Eh(hξ)]nU0∥∥∥ ≤ 1√

2πsupξ∈R|Eh(hξ)|n

∥∥∥U0∥∥∥ = sup

ξ∈R|Eh(hξ)|n

∥∥U0∥∥

Stability in L2 norm holds if

supξ∈R|Eh(hξ)| ≤ 1

Accuracy of order r

The finite difference scheme Eh is accurate of order r if

Eh(ξ) = e−λξ2

+O(|ξ|r+2

), ξ → 0

Example: FTCS scheme

Eh(ξ) = 1− 2λ+ 2λ cos(ξ)

= 1− λξ2 +1

12λξ4 +O

(ξ6)

= e−λξ2

+

(1

12λ− 1

2λ2

)ξ4 +O

(ξ6)

FTCS is accurate of order 2;For the choice λ = 1

6 it isaccurate of order 4.

20 / 46

Page 21: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Convergence in L2

Assume that the scheme Eh with λ = ∆th2 = constant and is accurate of order r

and stable in L2. Then

‖Un − un‖ ≤ Ctnhr|f |r+2, tn ≥ 0

Proof: Since Eh(ξ) is bounded in R, we have from accuracy property

|Eh(ξ)− e−λξ2 | ≤ C|ξ|r+2, ξ ∈ R

By stability and an − bn = (a− b)(an−1 + an−2b+ . . .+ bn) it follows that

|[Eh(ξ)]n − e−nλξ2 | ≤

∣∣∣∣∣∣(Eh(ξ)− e−λξ

2

)

n−1∑

j=0

[Eh(ξ)]n−1−je−jλξ2

∣∣∣∣∣∣≤ Cn|ξ|r+2

Take Fourier transform of heat equation in x variable

du

dt(ξ, t) = −ξ2u(ξ, t), t > 0, u(ξ, 0) = f(ξ)

21 / 46

Page 22: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

so that

u(ξ, t) = e−ξ2tf(ξ)

Fourier transform of error in numerical solution is

(Un − un)(ξ) = ([Eh(hξ)]n − e−n∆tξ2)f(ξ)

From Parseval relation

‖Un − un‖2 =1

∥∥∥Un − un∥∥∥

2

=1

∥∥∥([Eh(hξ)]n − e−n∆tξ2)f(ξ)∥∥∥

2

But

|[Eh(hξ)]n − e−n∆tξ2 | ≤ Cnhr+2|ξ|r+2

and using the fact that

df

dx= −iξf(ξ),

drf

dx= (−iξ)rf(ξ), λ =

∆t

h2= const

22 / 46

Page 23: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

we get

‖Un − un‖ ≤ 1√2πCnhr+2

∥∥∥ξr+2f(ξ)∥∥∥

≤ C(n∆t)hr∥∥∥f (r+2)

∥∥∥ , h2 = O (∆t)

= Ctnhr|f |r+2

23 / 46

Page 24: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Multi-level scheme• Higher order accuracy in time

D0tU

nj = µD+

xD−x U

nj

orUn+1j − Un−1

j

2∆t= µ

Unj−1 − 2Unj + Unj+1

h2

Formally second order in t and x, but unstable

• Dufort-Frankel scheme: stable for any λ

Un+1j − Un−1

j

2∆t= µ

Unj−1 − 2

(Un+1

j +Un−1j

2

)+ Unj+1

h2

Note: You need to get U1 by some other scheme.Second order accurate (need ∆t/h→ 0, ok if ∆t/h2 =constant)

τnh = O(∆t2

)+O

(h2)

+∆t2

h2utt(xj , tn) +O

(∆t4

h2

)

24 / 46

Page 25: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Initial-boundary value problem

ut = µuxx, (x, t) ∈ (0, 1)× R+

u(x, 0) = f(x)

u(0, t) = 0

u(1, t) = 0

25 / 46

Page 26: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Forward Euler scheme

Consider a uniform grid of M + 1 points, indexed from 0 to M .

D+t U

nj = µD+

xD−x U

nj , j = 1, . . . ,M − 1

orUn+1j − Unj

∆t=Unj−1 − 2Unj + Unj+1

h2

or

Un+1j = λUnj−1 + (1− 2λ)Unj + λUnj+1, j = 1, . . . ,M − 1

Un+10 = Un+1

M = 0

Maximum norm

‖U‖∞,h = max0≤j≤M

|Uj |

26 / 46

Page 27: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Forward Euler scheme

Maximum stability

The forward Euler scheme for the IBVP is stable in maximum norm iffλ ≤ 1/2.

λ ≤ 1/2 is necessary: Consider initial condition

U0j = fj = (−1)j sin(πjh), j = 0, 1, . . . ,M

so that ‖f‖∞,h = 1. Then

Unj = [1− 2λ− 2λ cos(πh)]nfj , j = 0, 1, . . . ,M

If λ > 1/2, then for sufficiently small h

|1− 2λ− 2λ cos(πh)| ≥ γ > 1

which implies

‖Un‖∞,h ≥ γn ‖f‖∞,h = γn →∞, h→ 0

27 / 46

Page 28: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Forward Euler scheme

Local truncation error: (for any fixed λ)

|τnj | ≤ Ch2 maxt∈In|uxxxx(t)|C , In = (tn, tn+1)

Error estimate

If λ ≤ 1/2, then the FTCS scheme for IBVP has error estimate given by

‖Un − un‖∞,h ≤ Ctnh2 maxt≤tn|uxxxx(t)|C

28 / 46

Page 29: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Numerical example: FTCS (forward Euler)

PDEut = µuxx x ∈ (0, 1)

Initial conditionu(x, 0) = f(x) = sin(πx)

Exact solutionu(x, t) = e−µπ

2t sin(πx)

Try withλ = 0.5, 0.6

Matlab code: heat 1d fe.m

29 / 46

Page 30: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Backward EulerExplicit scheme (Forward Euler/FTCS)

D+t U

nj = µD+

xD−x U

nj

Implicit scheme (Backward Euler/BTCS)

D+t U

nj = µD+

xD−x U

n+1j

orUn+1j − Unj

∆t= µ

Un+1j−1 − 2Un+1

j + Un+1j+1

h2

−λUn+1j−1 + (1 + 2λ)Un+1

j − λUn+1j+1 = Unj , j = 1, . . . ,M − 1

Un+10 = Un+1

M = 0

In matrix notationBUn+1 = Un

where U = [U1, U2, . . . , UM−1]> and30 / 46

Page 31: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Backward Euler

140 9 Finite Di!erence Methods for Parabolic Problems

We remark that in this case, in order for u to be su!ciently regular toguarantee that the right hand side of (9.7) is bounded by Ch2|v|C4 , we need torequire certain compatibility conditions for v with the boundary conditions,namely v(x) = v!!(x) = v(iv)(x) = 0 for x = 0, 1.

We note that a method of the form

Un+1j =

!

p

apUnj"p, for j = 1, . . . , M ! 1,

is not suitable here if ap "= 0 for some |p| > 1, since then for some interiormesh-point of ! the equation uses mesh-points outside this interval. In sucha case the equation has to be modified near the endpoints, which significantlycomplicates the analysis.

The stability requirement k # 12h2 used for the forward Euler method is

quite restrictive in practice, and it would be desirable to relax it to be ableto use h and k of the same order of magnitude. For this purpose one maydefine an implicit method, instead of the explicit method considered above,by the backward Euler scheme

(9.21)

"tUn+1j = "x"xUn+1

j , for j = 1, . . . , M ! 1, n $ 0,

Un+10 = Un+1

M = 0, for n $ 0,

U0j = Vj = v(xj), for j = 0, . . . , M.

For Un given this may be put in the form

(1 + 2#)Un+1j ! #(Un+1

j"1 + Un+1j+1 ) = Un

j , j = 1, . . . , M ! 1,

Un+10 = Un+1

M = 0,

which is a linear system of equations for the determination of Un+1. In matrixnotation it may be written as

(9.22) BUn+1 = Un,

where Un+1 and Un are now thought of as vectors with M ! 1 componentscorresponding to the interior mesh-points and B is the diagonally dominant,symmetric, tridiagonal matrix

B =

"#######$

1 + 2# !# 0 . . . 0

!# 1 + 2# !#. . .

...

0. . .

. . .. . . 0

.... . . !# 1 + 2# !#

0 . . . 0 !# 1 + 2#

%&&&&&&&'

.

Clearly the system (9.22) may easily be solved for Un+1.

Maximum stability

The backward Euler scheme is stable in maximum norm for any value of λ.The scheme is unconditionally stable.

Proof: At time level n+ 1, let the maximum be achieved at grid point j = j0.Then

Un+1j0

=1

1 + 2λ

[λUn+1

j0−1 + λUn+1j0+1 + Unj0

]

31 / 46

Page 32: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Backward Euler

and

∥∥Un+1∥∥∞,h = |Un+1

j0|

≤ 1

1 + 2λ

[λ|Un+1

j0−1|+ λ|Un+1j0+1|+ |Unj0 |

]

≤ 2λ

1 + 2λ

∥∥Un+1∥∥∞,h +

1

1 + 2λ‖Un‖∞,h

which implies that∥∥Un+1

∥∥∞,h ≤ ‖Un‖∞,h.

Remark: If we write

BUn+1 = U as Un+1 = B−1Un =: E∆Un

then maximum norm stability implies that

‖E∆U‖∞,h ≤ ‖U‖∞,h =⇒ ‖E∆‖∞,h ≤ 1

32 / 46

Page 33: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Backward Euler

Error estimateThe backward Euler scheme has the error estimate

‖Un − un‖∞,h ≤ Ctn(∆t+ h2) maxt≤tn|uxxxx(t)|C

Proof: Define the error en = Un − un.

Un+1j − Unj

∆t= µ

Un+1j−1 − 2Un+1

j + Un+1j+1

h2

un+1j − unj

∆t= µ

un+1j−1 − 2un+1

j + un+1j+1

h2+ τnj

The local truncation error can be bounded as

‖τn‖∞,h ≤ C(∆t+ h2) maxt∈In−1

|u(t)|C4 , In−1 = (tn−1, tn)

33 / 46

Page 34: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Backward Euler

Then the error satisfies

en+1j − enj

∆t= µ

en+1j−1 − 2en+1

j + en+1j+1

h2− τnj

In terms of matrix B and discrete evolution operator E∆

Ben+1 = en −∆t τn =⇒ en+1 = E∆en −∆tE∆τ

n

Iterating over time

en = En∆e0 −∆t

n−1∑

l=0

En−l∆ τ l, n ≥ 1

= −∆t

n−1∑

l=0

En−l∆ τ l since e0 = 0

34 / 46

Page 35: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Backward Euler

Therefore

‖en‖∞,h ≤ ∆t

n−1∑

l=0

∥∥En−l∆ τ l∥∥∞,h

≤ ∆t

n−1∑

l=0

∥∥τ l∥∥∞,h , from stability of E∆

≤ (n∆t) max0≤l≤n−1

∥∥τ l∥∥∞,h

≤ tnC(∆t+ h2) maxt≤tn|u(t)|C4

Remark: The Backward Euler scheme is first order accurate in time andsecond order accurate in space.

35 / 46

Page 36: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Crank-Nicholson

D+t U

nj = µD+

xD−x

(Unj + Un+1

j

2

)

−λ2Un+1j−1 + (1 + λ)Un+1

j − λ

2Un+1j+1 =

λ

2Unj−1 + (1− λ)Unj +

λ

2Unj+1

Un+10 = Un+1

M = 0

In matrix notation

BUn+1 = AUn

where

36 / 46

Page 37: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Crank-Nicholson

142 9 Finite Di!erence Methods for Parabolic Problems

and hence

zn = !k

n!1!

l=0

En!lk ! l.

The estimate (9.7) is now replaced by

"!n"",h # C(h2 + k) maxt#In!1

|u(·, t)|C4 .

Using (9.24) we then obtain

"zn"",h # kn!1!

l=0

"! l"",h # C tn(h2 + k)maxt$tn

|u(·, t)|C4 ,

which concludes the proof. $%The above convergence result for the backward Euler method is satisfac-

tory in that it requires no restriction on the mesh-ratio " = k/h2. On theother hand, since it is only first order accurate in time, the error in the timediscretization will dominate unless k is chosen much smaller than h. It wouldthus be desirable to find a stable method which is second order accuratealso with respect to time. Such a method is provided by the Crank-Nicolsonscheme, which was introduced for a system of ordinary di!erential equationsin Sect. 7.2. This uses symmetry around the point (xj , tn+1/2) and is definedby

(9.25)

#tUn+1j = 1

2#x#x

"Un

j + Un+1j

#, for j = 1, . . . ,M ! 1, n & 0,

Un+10 = Un+1

M = 0, for n & 0,

U0j = Vj := v(jh), for j = 0, . . . ,M.

The first equation may also be written

(I ! 12k#x#x)Un+1

j = (I + 12k#x#x)Un

j ,

or

(1 + ")Un+1j ! 1

2"(Un+1j!1 + Un+1

j+1 ) = (1 ! ")Unj + 1

2"(Unj!1 + Un

j+1),

and, in matrix form, with Un again denoting the (M ! 1)-vector associatedwith Un,

BUn+1 = AUn,

where now both A and B are symmetric tridiagonal matrices, with B diago-nally dominant:

B =

$%%%%%%%&

1 + " ! 12" 0 . . . 0

! 12" 1 + " ! 1

2". . .

...

0. . .

. . .. . . 0

.... . . !1

2" 1 + " ! 12"

0 . . . 0 ! 12" 1 + "

'((((((()

,

9.2 The Mixed Initial-Boundary Value Problem 143

and

A =

!"""""""#

1 ! ! 12! 0 . . . 0

12! 1 ! ! 1

2!. . .

...

0. . .

. . .. . . 0

.... . . 1

2! 1 ! ! 12!

0 . . . 0 12! 1 ! !

$%%%%%%%&

.

With obvious notation we also have

BkhUn+1 = AkhUn,

orUn+1 = B!1

kh AkhUn = EkUn,

where, similarly to the above,

"B!1kh V "",h # "V "",h.

The same approach to stability as for the backward Euler method gives,for ! # 1, since the coe!cients on the right are then non-negative,

(1 + !)"Un+1"",h # !"Un+1"",h + "Un"",h,

or"Un+1"",h # "Un"",h,

which shows stability. However, if ! > 1, which is the interesting case if wewant to be able to take h and k of the same order, one obtains instead

(1 + !)"Un+1"",h # !"Un+1"",h + (2! ! 1)"Un"",h,

which does not yield maximum-norm stability, since 2! ! 1 > 1. For ! # 1we have immediately as before a O(k2 + h2) = O(h2) convergence estimate.

In order to be able to deal with ! > 1, we now instead turn to an analysisin an l2 type norm. We introduce thus for vectors V = (V0, . . . , VM )T theinner product

(V,W )h = hM'

j=0

VjWj ,

and the corresponding norm

"V "2,h = (V, V )1/2h =

(h

M'

j=0

V 2j

)1/2

.

We denote by l02,h the space l0h equipped with this inner product and norm,and note that this space is spanned by the M !1 vectors "p, p = 1, . . . ,M !1,with components

Un+1 = B−1AUn =: E∆Un

Maximum stability

The Crank-Nicholson scheme is stable in maximum norm for λ ≤ 1

Proof: Similar to backward Euler scheme

Remark: Backward Euler scheme was unconditionally stable in maximumnorm.

37 / 46

Page 38: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Implicit scheme for IBVP: Crank-Nicholson

Remark: If λ > 1, then

∥∥Un+1∥∥∞,h ≤ (2λ− 1) ‖Un‖∞,h

But since 2λ− 1 > 1, this does not yield stability in maximum norm.

Error estimateFor λ ≤ 1, the Crank-Nicholson scheme has the error estimate

‖Un − un‖∞,h = O(∆t2 + h2

)

Remark: The condition λ ≤ 1 is too restrictive. This can be relaxed if weuse a weaker norm for stability.

38 / 46

Page 39: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Fourier stabilityVector V = (V0, V1, . . . , VM ) ∈ RM+1

Inner product

(V,W )h := h

M∑

j=0

VjWj

and corresponding norm‖V ‖2,h =

√(V, V )h

Space of vectors

l02,h = {V ∈ RM+1 : ‖V ‖2,h <∞, V0 = VM = 0}

Orthonormal basis vectors for l02,h: φp ∈ RM+1, p = 1, . . . ,M − 1

φp,j =√

2 sin(πpjh), j = 0, 1, . . . ,M (φp, φq)h = δpq

φp are eigenfunctions of finite difference operator −D+xD−x

−D+xD−x φp,j =

2

h2[1− cos(πph)]φp,j , j = 1, 2, . . . ,M − 1

39 / 46

Page 40: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Fourier stability

Let f ∈ l02,h be initial data. Then

f =

M−1∑

p=1

fpφp, fp = (f, φp)h

Parseval relation‖f‖2,h = ‖f‖2

Forward Euler method (FTCS): Consider one time step

U1j = fj + µ∆tD+

xD−x fj

=

M−1∑

p=1

fp[1− 2λ(1− cos(πph))]φp,j , j = 1, 2, . . . ,M − 1

andU1

0 = U1M = 0

40 / 46

Page 41: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Fourier stability

or more generally

Unj =

M−1∑

p=1

fp[Eh(πph)]nφp,j , j = 0, 1, . . . ,M

where Eh(ξ) is the symbol of the operator Eh

Eh(ξ) = 1− 2λ[1− cos(ξ)]

By orthogonality of {φp} and Parseval’s relation

‖Un‖2,h =

(M−1∑

p=1

f2p [Eh(πph)]2n

)1/2

≤ maxp|Eh(πph)|n ‖f‖2,h

Check that |Eh(ξ)| ≤ 1 for ξ ∈ [0, π] iff λ ≤ 1/2. In that case, we have stability

‖Un‖2,h ≤ ‖f‖2,h , iff λ ≤ 1/2

41 / 46

Page 42: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Fourier stability

This condition is identical to the condition for maximum norm stability ofFTCS scheme.

Backward Euler method

Eh(ξ) =1

1 + 2λ[1− cos(ξ)]

and 0 ≤ Eh(ξ) ≤ 1 for all ξ ∈ [0, π] and any λ > 0. Hence we haveunconditional stability.

Crank-Nicholson method

Eh(ξ) =1− λ[1− cos(ξ)]

1 + λ[1− cos(ξ)]

and |Eh(ξ)| ≤ 1 for ξ ∈ [0, π] and for any λ > 0. Thus the CN scheme isunconditionally stable in l02,h.

42 / 46

Page 43: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Fourier stability

Convergence of CN scheme in l02,h

Let Un and un be numerical and exact solutions. Then for any λ > 0

‖Un − un‖2,h ≤ Ctn(h2 + ∆t2) maxt≤tn|u(t)|C6

Proof: The local truncation error

τnj = D+t u

nj − µD+

xD−x

(unj + un+1

j

2

)

=[D+t u

nj − ut(xj , tn+ 1

2)]− µD+

xD−x

[unj + un+1

j

2− un+ 1

2j

]

−µ[D+xD−x u

n+ 12

j − uxx(xj , tn+ 12)]

and using Taylor formula we get

‖τn‖2,h ≤ C(∆t2 + h2) maxt∈In|u(t)|C6

43 / 46

Page 44: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

IBVP: Fourier stability

The error e = Un − un satisfies the difference equation

en+1 = E∆en −∆t B−1τn

or

en = −∆t

n−1∑

l=0

En−1−l∆ B−1τ l

The result follows from the stability of E∆ and the boundedness of B−1, i.e.,

‖E∆V ‖2,h ≤ ‖V ‖2,h and∥∥B−1V

∥∥2,h≤ ‖V ‖2,h

44 / 46

Page 45: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

θ-scheme

D+t U

n = µD+xD−x [(1− θ)Un + θUn+1]

θ = 0 Forward Euler Explicit O(∆t+ h2

)

θ = 1 Backward Euler Implicit O(∆t+ h2

)

θ = 1/2 Crank-Nicholson Implicit O(∆t2 + h2

)

Symbol of the scheme

Eh(ξ) =1− 2(1− θ)λ(1− cos ξ)

1 + 2θλ(1− cos ξ)

For 0 ≤ θ ≤ 1, we have Eh(ξ) ≤ 1 for all ξ. Stability requires that

minξEh(ξ) =

1− 4(1− θ)λ1 + 4θλ

≥ −1 =⇒ (1− 2θ)λ ≤ 1

2

θ < 1/2: stable in l02,h only if λ < 12(1−2θ)

θ ≥ 1/2: unconditionally stable in l02,h

45 / 46

Page 46: Finite difference method for heat equationmath.tifrbng.res.in/~praveen/notes/cm2013/heat_1d.pdfFinite di erence method for heat equation Praveen. C praveen@math.tifrbng.res.in Tata

Numerical example

Initial and boundary condition same as in (29)Matlab codes:

• Backward euler scheme: heat 1d be.m

• Crank-Nicholson scheme: heat 1d cn.m

46 / 46