Vous êtes sur la page 1sur 40

3.

20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
3.
Finite dierences, Taylors theorem, nite dierence
methods in space, method of lines, time stepping
20401
Tony Shardlow
1 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Scientic computing

Scientic computing involves constructing numerical


solution techniques for mathematical models and using
computers to analyse and solve models that arise in
science and engineering.

Without computing, we could not nd or even approximate


solutions to most mathematical models and PDEs.

Numerical analysis is the mathematical theory


underpinning the techniques used in computational
science. It aims to show existing algorithms are ecient
and accurate and develop better algorithms.

We introduce one numerical solution technique for PDEs,


known as nite dierences.
2 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Finite dierence approximation
The idea of the nite dierence method is to approximate
u(x) by u
j
at x = x
j
where x
j
is a discrete set of points.
We choose x
j
on a uniform grid.
Denition 1 (uniform grid)
A uniform grid on [0, 1] is dened by
x
j
= jh, j = 0, . . . , n, h = 1/n.
h is known as the grid spacing.

0 = x
0
x
1
x
2
x
3
x
n
= 1
h =
1
n
h h
3 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Approximating derivatives on a grid
Denition 2 (centered dierencing)
To approximate derivatives u

(x
j
) at a grid point x = x
j
, write
u

(x
j
)
1
h
u(x
j
) ,
where u(x) = u(x + h/2) u(x h/2).
x
j
h/2
x
j x
j
+h/2
u(x
j
h/2)
u(x
j
+h/2)
4 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Error
We measure the error in approximation using Taylors theorem.
Theorem 3 (Taylors theorem)
Assume that u(x) is smooth (derivatives of any order exist).
For some (x, x + h).
u(x + h) =u(x) + hu

(x) +
1
2
h
2
u

(x)+
+
1
(n 1)!
h
n1
u
(n1)
(x) +
1
n!
h
n
u
(n)
().
We use the order notation O(h
n
) and write X(h) = O(h
n
) if
there exists a constant K such that [X(h)[ < Kh
n
. Then,
u(x + h) =u(x) + hu

(x) +
1
2
h
2
u

(x)+
+
1
(n 1)!
h
n1
u
(n1)
(x) +O(h
n
).
5 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Lemma 4
The error in approximating u

(x
j
) by u(x
j
)/h is
e
j
= u

(x
j
)
1
h
u(x
j
) = O(h
2
).
Proof.
By Taylors theorem,
u(x + h/2) =u(x) +
h
2
u

(x) +
h
2
8
u

(x) +O(h
3
)
u(x h/2) =u(x)
h
2
u

(x) +
h
2
8
u

(x) +O(h
3
)
so
u(x
j
)
h
=
(u(x
j
+ h/2) u(x
j
h/2))
h
=
hu

(x
j
) +O(h
3
)
h
= u

(x
j
) +O(h
2
).
6 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Approximate u

(x
j
)
Denition 5 (second centered dierence)
To approximate the second derivative, write
u

(x
j
)
1
h
2

2
u(x
j
)
where

2
u(x
j
) =[u(x
j
)]
=u
_
x
j
+
h
2
_
u
_
x
j

h
2
_
= u(x
j
+ h) u(x
j
) (u(x
j
) u(x
j
h))
= u(x
j
+ h) 2u(x
j
) + u(x
j
h) .
7 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Model reaction diusion problem
For a constant r 0, nd u(x) such that
u

+ r u = f for 0 < x < 1


u(0) = , u(1) = ,
_
where , R are given. This is a two point Boundary Value
Problem (BVP).
We derive a nite dierence method by replacing the
derivatives by nite dierences.
8 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Finite dierences for model reaction diusion PDE
At the grid points x
j
= jh where h = 1/n, the PDE is
u

(x
j
) + ru(x
j
) = f (x
j
), j = 1, 2, . . . , n 1 ,
and u(x
0
) = 0 and u(x
n
) = 0 from the BCs.
Let f
j
= f (x
j
) and make approximations
u(x
j
) u
j
, u

(x
j
)
2
u
j
/h
2
.
This gives the equations

1
h
2

2
u
j
+ ru
j
= f
j
, j = 1, 2, . . . , n 1 ,
with boundary conditions u
0
= u
n
= 0.
9 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Finite dierences for model reaction diusion problem
Denition 6 (nite dierence method)
The nite dierence method is to nd u
j
u(x
j
) such that

1
h
2

2
u
j
+ ru
j
= f
j
, j = 1, 2, . . . , n 1, ()
and u
0
= u
n
= 0.
As

2
u
j
= u
j 1
2u
j
+ u
j +1
,
() becomes

1
h
2
(u
j 1
2u
j
+ u
j +1
) + r u
j
= f
j
, j = 1, 2, . . . , n 1.
10 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear system of eqns
Rearrange

1
h
2
(u
j 1
2u
j
+ u
j +1
) + r u
j
= f
j
, j = 1, 2, . . . , n 1,
to get

1
h
2
u
j 1
+ (
2
h
2
+ r )u
j

1
h
2
u
j +1
= f
j
and u
0
= 0 and u
n
= 0. Write as a system of linear equations:
_
_
_
_
_
_
_
_
(
2
h
2
+ r )
1
h
2
0

1
h
2
.
.
.
.
.
.

1
h
2
(
2
h
2
+ r )
1
h
2
.
.
.
.
.
.

1
h
2
0
1
h
2
(
2
h
2
+ r )
_
_
_
_
_
_
_
_
. .
A
_
_
_
_
_
_
_
_
u
1
.
.
.
u
j
.
.
.
u
n1
_
_
_
_
_
_
_
_
. .
u
=
_
_
_
_
_
_
_
_
f
1
.
.
.
f
j
.
.
.
f
n1
_
_
_
_
_
_
_
_
. .
f
11 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear algebra
By using nite dierences, we may approximate the solution to
the reaction-diusion model by solving a linear system of
equations
Au = f,
where f = [f
1
, . . . , f
n1
]
T
and A is the given matrix and
u = [u
1
, . . . , u
n1
]
T
.
A and f are known and methods from linear algebra (e.g.,
Gaussian Elimination) are available to determine u
j
and hence
the approximation to u(x
j
).
In many applications, A is tridiagonal and sparse and this can
be used to speed up the solution of the linear system.
Methods for such systems are studied in the module Numerical
Linear Algebra.
12 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Example soln A
u

= 1 for 0 < x < 1, (A)


u(0) = 0, u(1) = 0.
The solution is u(x) =
1
2
(x x
2
) .
0 0.5 1
0
1/8
x
u
Problem A
0 0.5 1
0
1/(w^2)
Problem B
u
x
13 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Finite dierence example (r = 0, f (x) = 1)
Take n = 6, so that h = 1/6. The linear system is
_

_
72 36 0 0 0
36 72 36 0 0
0 36 72 36 0
0 0 36 72 36
0 0 0 36 72
_

_
_

_
u
1
u
2
u
3
u
4
u
5
_

_
=
_

_
1
1
1
1
1
_

_
.
Solve the system of equations (e.g., with MATLAB):
u
1
= u
5
= 5/72,
u
2
= u
4
= 1/9 = 8/72,
u
3
= 1/8 = 9/72.
Note that u
j
= u(x
j
) =
1
2
(x
j
x
2
j
). That is, the nite
dierence solution is exact in this example (because the nite
dierence approximation are exact for quadratic u(x)).
14 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Example soln B
u

+ w
2
u = 1 for 0 < x < 1 (B)
u(0) = 0, u(1) = 0.
The solution is u(x) =
1
w
2

(exp(wx) + exp(w(1 x)))
w
2
(1 + exp(w))
.
0 0.5 1
0
1/8
x
u
Problem A
0 0.5 1
0
1/(w^2)
Problem B
u
x
15 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Example
u

+ 16u = 1 for 0 < x < 1


u(0) = 0, u(1) = 0.
_
(RD)
Take n = 5, i.e. h = 1/5. Thus,

0 = x
0
x
1
x
2
x
3
x
4
x
5
= 1
h =
1
5
h h
Since 1/h
2
= 25, the linear system is
_

_
66 25 0 0
25 66 25 0
0 25 66 25
0 0 25 66
_

_
_

_
u
1
u
2
u
3
u
4
_

_
=
_

_
1
1
1
1
_

_
.
16 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Example solution

0 = x
0
x
1
x
2
x
3
x
4
x
5
= 1
h =
1
5
u
1
u
2
u
3
u
4
_

_
66 25 0 0
25 66 25 0
0 25 66 25
0 0 25 66
_

_
_

_
u
1
u
2
u
3
u
4
_

_
=
_

_
1
1
1
1
_

_
.
The nite dierence solution is
u
1
= u
4
= 0.03171..
u
2
= u
3
= 0.04372..
Note that u
j
,= u(x
j
) since
u(x
1
) = u(x
4
) = 0.03242..
u(x
2
) = u(x
3
) = 0.04454..
17 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Compare numerical and exact soln
Comparing u(x
j
) (x) with u
j
( o) ...
0.2 0.4 0.6 0.8
0.02
0.025
0.03
0.035
0.04
0.045
0.05
e
1
e
2
e
3
e
4
u(x)
global error components
18 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Numerical analysis
We have derived a numerical method for the PDE. The method
produces errors and we want to ensure the errors are small.
Denition 7 (global error )
The global error is dened by
e
j
= u(x
j
) u
j
, j = 0, 1, 2, . . . , n.
This is the error that matters to the applied scientist: it
measures how close the computed soln u
j
is to true soln u(x
j
).
Denition 8 (convergent)
The nite dierence method is said to be convergent if and
only if
max
0j n
[e
j
[ 0 as n .
19 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Truncation error
Denition 9 (local truncation error )
The local truncation error T
j
at the grid point x
j
is the
remainder when u(x
j
) is substituted in place of u
j
in

1
h
2

2
u
j
+ r u
j
= f
j
j = 1, 2, . . . , n 1,
i.e.,
T
j
=
1
h
2

2
u(x
j
) + ru(x
j
) f
j
j = 1, 2, . . . , n 1.
From the PDE,
0 = u

(x
j
) + ru(x
j
) f
j
j = 1, 2, . . . , n 1
so subtracting equations gives
T
j
= u

(x
j
)
1
h
2

2
u(x
j
).
20 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Denition 10 (kth order consistent)
A nite dierence scheme is said to be kth order consistent for
k > 0 if the local error satises
T
j
= O(h
k
), j = 1, 2, . . . , n 1.
Theorem 11 (consistency of centered dierencing)
The centered dierence approximation to the model reaction
diusion equation is 2nd order consistent. In particular, the
local truncation error satises
T
j
= O(h
2
), j = 1, 2, . . . , n 1.
21 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Proof.
By Taylors theorem,
u(x h)=u(x) hu

(x) +
h
2
2
u

(x)
h
3
6
u

(x) +O(h
4
)
u(x + h)=u(x) + hu

(x) +
h
2
2
u

(x) +
h
3
6
u

(x) +O(h
4
)
and
T
j
= u

(x
j
)
1
h
2
(u(x
j
h) 2u(x
j
) + u(x
j
+ h)).
Add the expansions for u(x h) and u(x + h), to nd
u(x
j
h) + u(x
j
+ h) = 2u(x
j
) + h
2
u

(x
j
) +O(h
4
).
Rearranging gives
T
j
= O(h
2
).
22 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Global error
We relate the global error e
j
at the grid point x
j
to the local
truncation error T
j
.
T
j
=
1
h
2

2
u(x
j
) + ru(x
j
) f
j
, j = 1, 2, . . . , n 1,
0 =
1
h
2

2
u
j
+ r u
j
f
j
, j = 1, 2, . . . , n 1.
Subtracting these equations and letting e
j
= u(x
j
) u
j
gives
T
j
=
1
h
2

2
e
j
+ r e
j
, j = 1, 2, . . . , n 1.
This linear system of eqns gives the global e
j
in terms of the
truncation error T
j
.
23 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Stability theorem for nite dierences
Theorem 12 (Stability theorem)
Consider u
j

n
j =0
such that
au
j 1
+ bu
j
cu
j +1
0, j = 1, 2, . . . , n 1.
Let a, b, c denote real coecients with
a 0
c 0
b a + c > 0
_
_
_
(S)
then
u
j
max0, u
0
, u
n
for all j = 0, 1, 2, . . . , n.
24 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Proof.
Suppose for a contradiction, there exists u
k
0 for
k = 1, . . . , n 1 such that
u
k1
u
k
u
k+1
u
k
= maxu
0
, u
1
, u
2
, . . . , u
n
minu
k1
, u
k+1
< u
k
.
As au
j 1
+ bu
j
cu
j +1
0,
bu
k
au
k1
+ cu
k+1
< au
k
+ cu
k
as a, c 0 and defn of u
k
= (a + c)u
k
bu
k
using a + c b.
As b > 0, this is a contradiction.
25 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Proof ctd.
We conclude that either

there is a maximum, which is negative (u


k
0) or

there is a maximum at the boundary u


k
maxu
0
, u
n
.
.
This is often called the discrete maximum principle.
26 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Stability+consisitency convergence

For PDEs, the maximum principle gave us continuous


dependence on data.

For numerical methods, the discrete maximum principle


gives us continuous dependence of the global error on the
truncation error.

This type of result for numerical methods is usually


referred to as stability and
Stability+consistency convergence
Recall, consistency means local truncation error T
j
is
O(h
k
), some k > 1.
convergence means global error u(x
j
) u
j
is small.
27 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Theorem 13 (Stability+constistency=convergence)
Suppose that
consistent: the nite dierence method is kth order consistent.
stable: the method has the form
au
j 1
+ bu
j
cu
j +1
= f
j
with a, c 0 and b a + c > 0.
Then, the numerical approximation converges to the exact
solution,
e
j
= [u
j
u(x
j
)[ = O(h
k
) as h 0.
Proof not given (See written notes online).
28 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Stability of nite dierence approx
Recall the nite dierence approximation

1
h
2
u
j 1
+ (
2
h
2
+ r )u
j

1
h
2
u
j +1
= f
j
, j = 1, 2, . . . , n 1.
To show that the approximation is stable,
we apply the Stability Theorem and look at condition (S).
a 0
1
h
2
0
c 0
1
h
2
0
b a + c
2
h
2
+ r
2
h
2
The centred approximation method is stable as r 0.
29 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation

The proof is similar to the proof of stability for the


diusion problem.

We conclude that the global error for the centered


dierence approximation of the diusion problem satises
global error = [u
j
u(x
j
)[ = O(h
2
).
30 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Convection diusion problem
The problem
u

+ ru = f
is known as a reaction diusion equation, as the term u

models diusion and the term u models reaction.


We now look at a convection diusion equation, replacing u
with u

.
Convection-diusion
u

+ wu

= f for 0 < x < 1


u(0) = , u(1) =
_
for some f (x), a scalar w R, and boundary values , R.
The scalar w is known as the wind.
It controls the strength and direction of the convection.
31 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Problem A
u

+ wu

= 0 for 0 < x < 1 (A)


u(0) = 1, u(1) = 0.
The solution is
u(x) =
exp(w) exp(wx)
exp(w) 1
0 0.5
0
1
x


u


Problem A
w=0
w=5
w=20
0 0.5 1
0
1/8
Problem B
w=20
w=5
w=0
32 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Problem B
u

+ wu

= 1 for 0 < x < 1 (B)


u(0) = 0, u(1) = 0.
The solution is
u(x) =
x
w

1 exp(wx)
w(exp(w) 1)
0 0.5
0
1
x


u


Problem A
w=0
w=5
w=20
0 0.5 1
0
1/8
Problem B
w=20
w=5
w=0
33 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Centered nite dierences
There are two derivatives to approximate.
u

(x
j
)
u

(x
j
)

2
u(x
j
)
h
2
=
u(x
j
+ h) 2u(x
j
) + u(x
j
h)
h
2
.
u

(x
j
)
We cannot use u(x
j
) = u(x
j
+ h/2) u(x
j
h/2) as we can
only take values on the grid.
We use the averaged centered dierence:
u

(x
j
)

u(x
j
)
h
=
1
2h
_
u(x
j
+
h
2
) +u(x
j

h
2
)
_
=
1
2h
(u(x
j
+ h) u(x
j
h)) .
34 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Numerical approximation
The exact solution at the grid points u(x
j
) satises
u

(x
j
) + wu

(x
j
) = f
j
j = 1, 2, . . . , n 1.
and u(x
0
) = and u(x
n
) = .
Centered nite dierence method
Find u
j
such that u
0
= and u
n
= and

1
h
2

2
u
j
+
w
h

u
j
= f
j
, j = 1, 2, . . . , n 1.
That is,

1
h
2
(u
j +1
2u
j
+ u
j 1
) +
w
2h
(u
j +1
u
j 1
) = f
j
.
35 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear system of equations
For j = 1, . . . , n 1,

1
h
2
(u
j +1
2u
j
+ u
j 1
) +
w
2h
(u
j +1
u
j 1
) = f
j
_

1
h
2

w
2h
_
. .
a
u
j 1
+
_
2
h
2
_
. .
b
u
j
+
_

1
h
2
+
w
2h
_
. .
c
u
j +1
= f
j
Apply the boundary conditions to simplify the equation for
j = 0 and j = n.
The BC u
0
= gives
a + bu
1
cu
2
= f
0
bu
1
cu
2
= f
0
+a,
and u
n
= gives
au
n2
+ bu
n1
= f
n1
+c.
36 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear system of equations
Collect all the equations as a linear system.
_

_
b c 0
a
.
.
.
.
.
.
a b c
.
.
.
.
.
.
c
0 a b
_

_
_

_
u
1
.
.
.
u
j
.
.
.
u
n1
_

_
=
_

_
f
1
+ a
.
.
.
f
j
.
.
.
f
n1
+ c
_

_
.
Top row comes from left hand boundary condition and the
bottom rows comes from the right boundary condition.
Also note the boundary condition aects the right hand side
vector in top/bottom entry.
In contrast to reaction diusion equation, the matrix is
non-symmetric as a ,= c.
37 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Numerical analysis

Is the approximation consistent? If u is smooth,


T
j
Ch
2
, j = 1, 2, . . . , n 1.
In other words, T
j
= O(h
2
). Proof by Taylors theorem.

Is the approximation stable?


We next verify the stability condition (S).
38 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Apply stability theorem
Recall the tridiagonal matrix entries
_

1
h
2

w
2h
_
. .
a
u
j 1
+
_
2
h
2
_
. .
b
u
j
+
_

1
h
2
+
w
2h
_
. .
c
u
j +1
= f
j
To show that the approximation is stable, we check that the
tridiagonal coecients satisfy (S).
a 0
1
h
2
+
w
2h
0 (?)
c 0
1
h
2

w
2h
0
b a + c
2
h
2

2
h
2
()
39 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Condition for stability
Assume that w > 0. Then,
a 0
1
h
2
+
w
2h
0 ()
c 0
1
h
2

w
2h
0 (?)
_

_
The centred approximation method is stable when
1
h
2

w
2h
0

wh
2
1 h
2
w
.
40 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Stability
Assume that w < 0. Then,
a 0
1
h
2
+
w
2h
0 (?)
c 0
1
h
2

w
2h
0 ()
_

_
Thus, the centred approximation method is stable whenever
1
h
2
+
w
2h
0
wh
2
1 h
2
w
.
We deduce that a sucient condition for stability is that
[w[h
2
1.
The ratio
|w|h
2
is called the mesh Peclet number.
Computationally, if
wh
2
> 1, the centred dierence solution
shows oscillations of period h, which indicates an instability.
41 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Solution of convection diusion model with w = 100;
Centered dierencing with h = 1/n and n = 20
0 0.2 0.4 0.6 0.8 1
0
0.5
1
1.5
x
u
Note the oscillation: the exact solution has no oscillation
42 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Alternative method: upwind nite dierence
Upwind dierencing with h = 1/n and n = 20.
0 0.2 0.4 0.6 0.8 1
0
0.5
1
1.5
x
u
There is no oscillation. Even though the truncation error is
bigger, the solution is better.
43 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Alternative method: Upwind nite dierence method
One sided nite dierence approximation:
x
j
h
x
j x
j
+h
u(x
j
h)
u(x
j
)
u(x
j
+h)

+
u(x
j
)

u(x
j
)
1
h

u(x
j
) u

(x
j
),
1
h

+
u(x
j
) u

(x
j
),
where

u(x
j
) =u(x
j
) u(x
j
h)

+
u(x
j
) =u(x
j
+ h) u(x
j
).
44 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Upwind method

For u

, use the centered dierence: u

(x
j
)
1
h
2

2
u(x
j
)

2
u(x
j
) =[u(x
j
)]
=u(x
j
+ h) 2u(x
j
) + u(x
j
h).

For u

, if w > 0, approximate u

(x
j
)
1
h

u(x
j
) where

u(x
j
) = u(x
j
) u(x
j
h).
or, if w < 0, approximate u

(x
j
)
1
h

+
u(x
j
) where

+
u(x
j
) = u(x
j
+ h) u(x
j
).
Called the upwind dierence approximation to u

(x).
45 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear system of eqns
When w > 0, we obtain

1
h
2
(u
j +1
2u
j
+ u
j 1
) +
w
h
(u
j
u
j 1
) = f
j
_

1
h
2

w
h
_
. .
a
u
j 1
+
_
2
h
2
+
w
h
_
. .
b
u
j
+
_

1
h
2
_
. .
c
u
j +1
= f
j
.
Apply the BCs u(0) = and u(1) = , to derive
_

_
b c 0
a
.
.
.
.
.
.
a b c
.
.
.
.
.
.
c
0 a b
_

_
_

_
u
1
.
.
.
u
j
.
.
.
u
n1
_

_
=
_

_
f
1
+ a
.
.
.
f
j
.
.
.
f
n1
+ c
_

_
.
46 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Consistency and Stability for upwind
We can show the upwind method is convergent and stable for
any choice of grid spacing h > 0 (see Problem Sheet). To do
this,

Show the upwind method is 1st order consistent using


Taylors theorem.

Show the method is stable by verifying (S).

Apply the result,


consistent + stable convergent
Hence the global error
[u(x
j
) u
j
[ = O(h).
For applications, it is important that the stability condition for
the upwind approximation holds independent of choice of grid
size h. This makes the method more robust in many
applications, which are convection dominated.
47 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Model parabolic PDE
We now look at nite dierences for time dependent problems,
by developing the method of lines for the following model
problem.
Model problem
Consider the heat equation for t > 0 and x (0, 1),
u
t
=u
xx
u(0, t) =u(1, t) = 0,
with initial condition u(x, 0) = u
0
(x).
48 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Heat equation
Consider the Fourier series
u(x, t) =

j =1
u
j
(t) sin(j x).
Notice that u(0, t) = u(1, t) and boundary conditions are
satised.
Substitute into the heat equation u
t
= u
xx
. Then
u
t
(x, t) =

j =1
u

j
(t) sin(j x)
u
xx
(x, t) =

j =1
u
j
(t) (j
2

2
) sin(j x).
49 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Decoupling the heat equation
After substitution into the heat equation,

j =1
u
j
(t)(j
2

2
) sin(j x) =

j =1
u

j
(t) sin(j x)
and equating coecients of sin(j x),
ODEs for Fourier coecients u
j
(t)
u

j
= j
2

2
u
j
, j = 1, 2, . . . .
From u(x, 0) =

j =1
u
j
(0) sin(j x) = u
0
(x), the initial data
u
j
(0) = 2
_
1
0
u
0
(x) sin j x dx.
50 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Method of lines
Replace the innite system of ODEs
u

j
= j
2

2
u
j
, j = 1, 2, . . . ,
with a nite system
u

j
= j
2

2
u
j
, j = 1, 2, . . . , J
where J is size of system and solve to determine u
j
(t),
j = 1, . . . , J.
Method of lines approximation is
v(x, t) =
J

j =1
u
j
(t) sin(j x).
For large J, u(x, t) v(x, t).
Finite dierence methods are often used to solve the ODEs for
u
j
(t). We study nite dierence methods for ODEs.
51 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Finite dierence method for ODE
Consider the following initial value problem.
dX
dt
= f (X), X(0) = X
0
.
For k > 0 (the time step), we approximate
dX
dt
=
X(t + k) X(t)
k
+O(k).
Example: X(t) = e
t
dX
dt
=
de
t
dt
= e
t
=
e
t+k
e
t
k
+O(k).
As a numerical example, put t = 1 and k = 0.1, then X

(t) =
e
t
= e = 2.7183 and
e
t+k
e
t
k
=
e
1.1
e
1
0.1
= 2.8588.
52 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Explicit Euler method
Put t = nk and substitute
X(t + k) X(t)
k
=
dX(t)
dt
+O(k)
into the ODE.
X((n + 1)k) X(nk)
k
= f (X(nk)) +O(k).
Drop the O(k) term and approximate X(nk) by X
n
, to nd
Explicit Euler method
Given X
0
and time step k, compute X
n
X(nk) by
X
n+1
= X
n
+ kf (X
n
).
It is possible to show that [X(T) X
n
[ = O(k) for nk = T,
under assumptions on f . We do not prove this.
53 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Example: explicit Euler method
Consider the ODE
dX
dt
= X, X(0) = X
0
with X
0
= 2 and = 3. In this case, exact solution is
X(t) = e
3t
2 .
We nd explicit Euler approximation for time step k = 0.1,
X
n+1
= X
n
+ kf (X
n
), X
0
= 2.
X
1
= 2 + 0.1(3 2) = 1.4 ,
X
2
= 1.4 + 0.1(3 1.4) = 0.98.
The exact solution X
1
X(0.1) = 2e
0.3
= 1.4816,
X
2
1.0976 = X(0.2).
Can get more accurate approximation by taking k smaller.
54 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Implicit Euler method
Approximating dX/dt by (X(t) X(t k))/k and repeating
gives
X(nk) X((n 1)k)
k
= f (X(nk)) +O(k)
Drop the O(k) term and approximate X(nk) by X
n
, to nd
Implicit Euler method
Given X
0
and time step k, compute X
n
X(nk) by
X
n
= X
n1
+ kf (X
n
)
also written X
n+1
= X
n
+ kf (X
n+1
). A nonlinear system of
equations must be solved to determine X
n
.
Again possible to show that [X(T) X
n
[ = O(k) for nk = T,
under assumptions on f .
55 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear test ODE
Linear test equation
dX
dt
= X

= X, X(0) = X
0
.
The solution is easily found to be
X(t) = e
t
X
0
.
Note that X(t) 0 as t if 1 < 0 (1 means real part).
Region of absolute stability
For what values of , do the numerical approximations X
n
0
as n . It usually depends on the time step k.
We dene the region of absolute stability to be the set of k C
such that numerical approximation X
n
0 as n .
56 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Stability condition for Explicit Euler

For the case f (X) = X, the explicit Euler method is


X
n+1
= X
n
+ kX
n

Rearrange,
X
n+1
= (1 +k)X
n
.
and the solution X
n
= (1 +k)
n
X
0
.

Hence as n
X
n
0 [1 +k[ < 1 .
We have show that the region of absolute stability is the
set of k C that belongs to the
circle of radius 1 in complex plane with centre at 1.
57 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Time step restriction for explicit Euler

Recall that for the ODE


X(t) 0 as t
if 1 < 0.

The numerical method decays for all initial data if and


only if [1 +k[ < 1. That is, there is a restriction on the
time step.

For the method of lines method, = j


2

2
where
j = 1, 2, . . . , J.

Hence, the time step restriction is [1 j


2

2
k[ < 1. In
other words, 1 < 1 j
2

2
k < 1 for j = 1, . . . , J and we
must have
time step k < 2/J
2

2
.
For large J, the time step condition is very restrictive and
the explicit Euler method is inecient in many cases.
58 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Implicit Euler
Put f (X) = X into the implicit Euler method.
Implicit Euler method
X
n
X
n1
k
= X
n
It becomes
X
n
=
1
(1 k)
X
n1
.
and the soln X
n
= (1 k)
n
X
0
.
Hence
X
n
0 [1 k[ > 1 .
That is, the region of absolute stability is the set of k C
outside the circle of radius 1 in complex plane with centre at 1 .
59 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
No stability restriction for implicit Euler

For implicit Euler, the region of absolute stability is


[1 k[ > 1 and this holds for all with 1 < 0.

When the ODE is stable (1 < 0), the implicit Euler is


stable too and [X
n
[ 0 as n .

There is no timestep restriction for the implicit Euler


method.
This is important for the heat equation, where is large.

Compare to the explicit Euler method, the implicit Euler is


a better method for the time discretisation of the heat
equation.
60 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Explicit vs Implicit
To understand the names implicit and explicit, apply the
methods to
dX
dt
= f (X), X(0) = X
0
for f (X) a nonlinear function. The explicit Euler method is
X
n+1
= X
n
+ kf (X
n
)
and X
n+1
is determined explicitly from X
n
and evaluation of f .
The implicit Euler method is
X
n
= X
n1
+ kf (X
n
)
so that X
n
is determined implicitly by a solution of a nonlinear
equation involving f .
61 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Method of lines by nite dierences
Consider the following PDE for 0 < x < 1
u
t
= u
xx
, u(0, t) = u(1, t), t > 0
with initial condition u(x, 0) = u
0
(x). We may also develop a
method of lines by approximating u
xx
by nite dierences.
Approximate u(x, t) at the grid points x
j
= jh by
u(t) =
_
_
_
u
1
(t)
.
.
.
u
n1
(t)
_
_
_

_
_
_
u(t, x
1
)
.
.
.
u(t, x
n1
)
_
_
_
.
Approximate the time derivative u
t
(x, t) at grid points by
du
dt
.
Approximate the spatial derivative u
xx
(x, t) at grid points by
Au, where A is the centered nite dierence matrix.
62 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Method of lines: nite dierences in space
Then, we have a system of ODEs
du
dt
= Au, A =
1
h
2
_
_
_
_
_
_
2 1
1 2
.
.
.
.
.
.
.
.
.
1
1 2
_
_
_
_
_
_
with initial condition u(0) = [u
0
(x
1
), . . . , u
0
(x
n1
)]
T
.
We may approximate this numerically using the Euler methods.

This system of ODEs is coupled, in contrast to the


method of lines based on Fourier series, where the ODEs
were decoupled so that each component could be solved
separately.
The method is more expensive to use, but applies to a
wider range of problems.
63 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Examination
The material from here on is not covered on the exam.
64 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Discretisation of (x, t) space : u
m
j
u(x
j
, t
m
)
Grid spacing in x direction is h.
Grid spacing in t direction is k.
6 6





s s s s s s
c
c
c
c
c
c
c
c
c
c
0 = x
0
x
j x
n
= 1
j 1 j j +1
h
h =
1
n
-
k
m
t
m
m+1
6
?
u
m
j
65 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Explicit approximation
u
t
(x
j
, t
m
) = u
xx
(x
j
, t
m
)
Approximate
u
xx
(x
j
, t
m
)
1
h
2

2
x
u(x
j
, t
m
)
=
1
h
2
_
u(x
j
h, t
m
) 2u(x
j
, t
m
) + u(x
j
+ h, t
m
)
_
u
t
(x
j
, t
m
)
1
k

+t
u(x
j
, t
m
)
=
1
k
_
u(x
j
, t
m
+ k) u(x
j
, t
m
)
_
.
66 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Finite dierence methodexplicit
u
t
(x
j
, t
m
) = u
xx
(x
j
, t
m
)
j = 1, 2, . . . , n 1
m = 0, 1, 2, . . .
.
Substitute dierence approximations to derive the nite
dierence method
1
k

+t
u
m
j
=
1
h
2

2
x
u
m
j
or
1
k
_
u
m+1
j
u
m
j
_
=
1
h
2
_
u
m
j 1
2u
m
j
+ u
m
j +1
_

s s s
j 1 j j + 1
m
m + 1
Given u
m
j 1
, u
m
j
, u
m
j +1
, u
m+1
j
is given explicitly by
u
m+1
j
= u
m
j 1
+ (1 2)u
m
j
+u
m
j +1
, where = k/h
2
.
67 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear system of equations

t t t
j 1 j j + 1
m
m + 1
For = k/h
2
u
m+1
j
= u
m
j 1
+ (1 2)u
m
j
+u
m
j +1
,
j = 1, 2, . . . , n 1
m = 0, 1, 2, . . .
This is a matrix-vector multiply at each time level:
_

_
u
m+1
1
.
.
.
u
m+1
j
.
.
.
u
m+1
n1
_

_
=
_

_
1 2 0
.
.
.
.
.
.
1 2
.
.
.
.
.
.
0 1 2
_

_
_

_
u
m
1
.
.
.
u
m
j
.
.
.
u
m
n1
_

_
.
68 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Consistency I
Is the explicit approximation consistent?
Theorem 14 (consistency)
The local error at the grid point (x
j
, t
m
),
T
m
j
=
1
k

+t
u(x
j
, t
m
)
1
h
2

2
x
u(x
j
, t
m
) j = 1, 2, . . . , n,
is bounded from above:

T
m
j

= O(k) +O(h
2
)
69 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Explicit Approximation II

Is the explicit approximation stable?


It all depends on = r
0 0.5 1
0
0.2
0.4
0.6
0.8
1
Explicit FD Scheme: r is 0.48
x
t
e
m
p
e
r
a
t
u
r
e
0 0.5 1
0
0.2
0.4
0.6
0.8
1
Explicit FD Scheme: r is 0.52
x
t
e
m
p
e
r
a
t
u
r
e
70 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Theorem 15
If 1 2 0 1/2 then the explicit approximation
u
m+1
j
= u
m
j 1
+ (1 2)u
m
j
+u
m
j +1
,
is non-increasing:
max
j

u
m+1
j

max
j

u
m
j

. ()
71 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Proof.
Let u
m

= max
j
[u
m
j
[.
[u
m+1
j
[ = [u
m
j 1
+ (1 2)u
m
j
+u
m
j +1
[
[u
m
j 1
[ +[(1 2)u
m
j
[ +[u
m
j +1
[

..
>0
u
m

+ (1 2)
. .
0
u
m

+ ()
..
>0
u
m

= u
m

+ (1 2)u
m

+u
m

= u
m

.
This establishes () since [u
m+1
j
[ u
m

for all j .
72 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Implicit Approximation
u
t
(x
j
, t
m
) = u
xx
(x
j
, t
m
)
Approximate
u
xx
(x
j
, t
m
)
1
h
2

2
x
u(x
j
, t
m
)
=
1
h
2
_
u(x
j
h, t
m
) 2u(x
j
, t
m
) + u(x
j
+ h, t
m
)
_
u
t
(x
j
, t
m
)
1
k

t
u(x
j
, t
m
)
=
1
k
_
u(x
j
, t
m
) u(x
j
, t
m
k)
_
.
where

2
x
u(x
j
, t
m
) = u(x
j
h, t
m
) 2u(x
j
, t
m
) + u(x
j
+ h, t
m
)

t
u(x
j
, t
m
) = u(x
j
, t
m
) u(x
j
, t
m
k).
73 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Implicit Approximation II
u
t
(x
j
, t
m
) = u
xx
(x
j
, t
m
)
j = 1, 2, . . . , n 1
m = 0, 1, 2, . . .
.
1
k

t
u
m
j
=
1
h
2

2
x
u
m
j
1
k
_
u
m
j
u
m1
j
_
=
1
h
2
_
u
m
j 1
2u
m
j
+ u
m
j +1
_

t
j 1 j j + 1
m 1
m
Thus
u
m
j 1
+ (1 + 2)u
m
j
u
m
j +1
= u
m1
j
,
where = k/h
2
.
74 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Linear system of eqns

t
j 1 j j + 1
m 1
m
For = k/h
2
u
m
j 1
+ (1 + 2)u
m
j
u
m
j +1
= u
m1
j
j = 1, 2, . . . , n 1
m = 0, 1, 2, . . .
This is a tridiagonal matrix solve at each time level:
_

_
1 + 2 0
.
.
.
.
.
.
1 + 2
.
.
.
.
.
.
0 1 + 2
_

_
_

_
u
m
1
.
.
.
u
m
j
.
.
.
u
m
n1
_

_
=
_

_
u
m1
1
.
.
.
u
m1
j
.
.
.
u
m1
n1
_

_
75 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Consistency
Theorem 16
The local error at the grid point (x
j
, t
m
),
T
m
j
=
1
k

t
u(x
j
, t
m
)
1
h
2

2
x
u(x
j
, t
m
) j = 1, 2, . . . , n,
is bounded from above:

T
m
j

= O(k) +O(h
2
).
76 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Implicit Approximation II

Is the implicit approximation stable?


Yes for any = r
0 0.5 1
0
0.2
0.4
0.6
0.8
1
Implicit FD Scheme: r is 0.48
x
t
e
m
p
e
r
a
t
u
r
e
0 0.5 1
0
0.2
0.4
0.6
0.8
1
Implicit FD Scheme: r is 0.52
x
t
e
m
p
e
r
a
t
u
r
e
77 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Theorem 17
The implicit approximation
u
m
j 1
+ (1 + 2)u
m
j
u
m
j +1
= u
m1
j
is non-increasing: max
j

u
m+1
j

max
j

u
m
j

. ()
78 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Proof.
Proof. Let u
m

= max
j
[u
m
j
[.
[ (1 + 2)
. .
>0
u
m
j
[ = [u
m
j 1
+ u
m1
j
+u
m
j +1
[.
(1 + 2) [u
m
j
[ = [u
m
j 1
+ u
m1
j
+u
m
j +1
[
[u
m
j 1
[ +[u
m1
j
[ +[u
m
j +1
[
u
m

+[u
m1
j
[ +u
m

= 2u
m

+[u
m1
j
[.
(1 + 2) u
m

2u
m

+[u
m1
k
[
This establishes () since u
m

[u
m1
k
[ max
j
[u
m1
j
[.
79 / 80
3.
20401
Scientic
Computing
Finite
dierences
and Taylors
theorem
Finite
dierences in
space
Method of
lines and time
stepping
Finite
dierences for
heat equation
Summary

We have looked at two nite dierence approximations for


the heat equation. An explicit and an implicit method.

The explicit method is easier to implement as it does NOT


involve solving a linear system of equations.

Both implicit and explicit methods are consistent with the


same order of accuracy (T
m
j
= O(k) +O(h
2
)). Second
order accurate in space; rst order accurate in time.

Stability depends on a step size condition for the explicit


method ( = k/h
2
1/2). The implicit method is always
stable.

Stable+consistency gives convergence for both methods.


The implicit method is preferred in practice due to better
stability.
80 / 80

Vous aimerez peut-être aussi