Escolar Documentos
Profissional Documentos
Cultura Documentos
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
(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
(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
_
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
_
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
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
+ ru = f
is known as a reaction diusion equation, as the term u
.
Convection-diusion
u
+ wu
+ wu
+ wu
(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
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
(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,
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
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
2
where
j = 1, 2, . . . , J.
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
_
_
_
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.
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
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
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