4. Finite Difference Schemes for the Heat Equation

4. Finite Difference Schemes for the Heat Equation
Topic: Numerical methods for solving parabolic equations.
We now know Fourier’s analytic method. But, often analytic
solutions can not be found, e.g., for nonlinear problems, or
problems with variable coefficients.
4.1 An Explicit Scheme
Consider the initial-boundary value heat equation
ut (x, t) = uxx (x, t),
u(0, t) = u(1, t) = 0,
x ∈ (0, 1), t > 0.
t > 0. (4.1)
u(x, 0) = f (x) x ∈ (0, 1).
Using approximations
ut (x, t) =
u(x, t + ∆t) − u(x, t)
+ O(∆t),
∆t
1 / 18
and
uxx (x, t) =
u(x − ∆x, t) − 2u(x, t) + u(x + ∆x, t)
+ O((∆x)2 ).
(∆x)2
Use grid points xj = j∆x for j = 0, 1, . . . , n + 1, where
∆x = 1/(n + 1). Similarly, for time, use tm = m∆t for integers
m ≥ 0, where ∆t is the time step. Finally, we let vjm denote an
approximation of u(xj , tm ).
This motivates the equation
vjm+1 − vjm
∆t
=
m − 2v m + v m
vj−1
j
j+1
(∆x)2
(j = 1, . . . , n, m ≥ 0) (4.4)
and from boundary conditions
m
v0m = 0, vn+1
= 0. (4.5)
This scheme is initialized by vj0 = f (xj ) (j = 1, . . . , n).
2 / 18
Defining r = ∆t/∆x 2 the scheme becomes
m
m
vjm+1 = rvj−1
+ (1 − 2r )vjm + rvj+1
,
(j = 1, . . . , n, m ≥ 0). (4.2)
This scheme is called explicit since values at time t + 1 are
computed directly from those at time t. So, easy to implement.
Example 4.2: see the book, with figures. Instability of the problem:
a slight change in grid parameters may cause the numerical
solution to oscillate.
4.2 Fourier Analysis of the Numerical Solution
We shall use a discrete version of Fourier’s method to compare
numerical and analytical solutions.
One can solve by guessing a separable solution vjm = Xj Tm for
j = 1, . . . , n, m ≥ 0, where X is a vector with n components while
{Tm }m≥0 is a sequence. See the book for this. Alternatively, we
can use linear algebra as follows.
3 / 18


0

.. 
 −1 2
. 


1 

..
A=

.
0 

(∆x)2  0
 ..

..
. −1 2 −1 
 .
0 . . . 0 −1 2
2
−1
0
...
.
−1 . .
..
..
.
.
Then (4.4)-(4.5) may be written with v m = (v1m , v2m , . . . , vnm ):
v m+1 = (I − ∆tA)v m
so by induction we get
v m = (I − ∆tA)m v 0 .
From Section 2.4: the eigenvalue problem (2.44) is equivalent to
the eigenvalue problem for the matrix A.
4 / 18
Hence, the vectors Xk introduced above are eigenvectors for the
matrix A with corresponding eigenvalue µk . So Xk is also an
eigenvector for the matrix (I − ∆tA)m with eigenvalue
(1 − ∆tµk )m . Hence, if v 0 = Xk we get
vjm = (1 − ∆tµk )m sin(kπxj )
as a particular solution of (4.4)-(4.5). By taking linear
combinations we get all solutions.
5 / 18
4.2.2 Comparison of the Analytical and Discrete Solution
The exact solution:
u(x, t) =
∞
X
ck e −λk t sin(kπx) (4.19)
k=1
R1
where λk = (kπ)2 and ck = 2 0 f (x) sin(kπx)dx. The discrete
solution is
n
X
m
vj =
γk (1 − ∆tµk )m sin(kπxj )
k=1
where µk =
Let
4
(∆x)2
ujm
2
sin (kπ∆x/2), γk = 2∆xk
= u(xj , tm ) =
∞
X
Pn
k=1 f (xj ) sin(kπxj ).
ck e −λk tm sin(kπxj )
k=1
We shall show that
vjm
≈
ujm
by suitable grid parameters.
6 / 18
We consider a fixed grid point (xj , tm ) where tm ≥ t̄ for t̄ > 0
independent of the mesh parameters. We have:
P
ujm = ∞
ck e −λk tm sin(kπxj )
Pnk=1
P
−λk tm sin(kπx )
= k=1 ck e −λk tm sin(kπxj ) + ∞
j
k=n+1 ck e
Bessel’s inequality implies that limk→∞ ck = 0, so c := maxk |ck |
exists (finite), and
P
P∞
−λk tm sin(kπx )| ≤ c
−(kπ)2 tm
| ∞
j
k=n+1 ck e
k=n+1 e
P
−π 2 t̄ )k
≤c ∞
k=n+1 (e
2
= c(e −π t̄ )n+1
1
1−e −π2 t̄
≈0
for large n. So
ujm ≈
Pn
k=1 ck e
−λk tm
sin(kπxj )
≈ γk (1 − ∆tµk )m sin(kπxj )
= vjm
as |ck − γk | = O((∆x)2 ) by using the trapezoidal-rule for
7 / 18
R1
approximation of the integral 0 f (x) sin(kπx)dx (assuming f
suitably smooth). We discuss why
e −λk tm ≈ (1 − ∆tµk )m
Here λk tm > 0 so |e −λk tm | ≤ 1 and therefore we also want
|1 − ∆tµk | ≤ 1, so ∆tµk ≤ 2. Inserting for µk here we see that
this inequality holds provided that
∆t
≤ 1/2 (4.25)
(∆x)2
This condition gives stability of the numerical scheme; if
|1 − ∆tµk | > 1 , the errors blow up, as the example showed.
Choose the discretization so we have equality in (4.25), i.e.,
∆t = (∆x)2 /2, and fix tm = 1. Then one can also compare
αk = e −λk and
p
βk = (1 − ∆tµk )1/∆t = (1 − 2 sin2 (kπ ∆t/2)1/∆t .
Examples show that αk and βk are very small for large k. So one
uses the approximations sin(y ) ≈ y and e y ≈ (1 + y )1/ , and a
computation shows then that αk ≈ βk .
8 / 18
4.3 Von Neumann’s Stability Analysis
In von Neumann’s stability analysis one compare the growth of the
analytical and discrete particular solutions. Want conditions on the
mesh parameters ∆x and ∆t such that the growth of the discrete
solutions are bounded by the growth of the analytical solutions.
Example 4.3: Consider again the heat equation ut = uxx . Inserting
a particular solution u(x, t) = Tk (t)e ikπx gives
Tk0 (t) = −(kπ)2 Tk (t)
so
2t
Tk (t) = e −(kπ)
where we use Tk (0) = 1.
We approximate the solution with the scheme
vjm+1 − vjm
∆t
=
m − 2v m − v m
vj−1
j
j+1
(∆x)2
.
9 / 18
One can argue that there are particular solutions of the discrete
problem of the form
{(ak )m e ikπxj }∞
k=−∞
(In the explicit scheme one has ak = 1 − ∆tµk .) By inserting this
solution into the heat equation and doing some calculations one
gets an expression for ak which is
ak = 1 −
4∆t
sin2 (kπ∆x/2)
(∆x)2
But since |Tk (t)| ≤ 1 we also require |(ak )m (t)| ≤ 1 for all k. A
sufficient condition for this is that
∆t
≤ 1/2.
(∆x)2
Thus, for both Dirichlet, Neumann, and periodic boundary
conditions, this condition has to be satisfied in order to get
reasonable numerical results
10 / 18
We summarize our discussion so far by stating that a numerical
solution is said to be stable in the sense of von Neumann if the
growth of the discrete particular solutions can be bounded by the
growth of the continuous particular solutions.
More precisely, let T (t) = maxk |Tk (t)|, then von Neumann
stability means that
max |(ak )m | ≤ T (tm ) for all tm ≥ 0
k
11 / 18
4.4 An Implicit Scheme
The previous scheme is very simple to implement, but the
drawback is very small time steps for stability. So we give an
alternative method, and implicit scheme.
Consider the initial-boundary value heat equation.
ut (x, t) = uxx (x, t),
u(0, t) = u(1, t) = 0,
x ∈ (0, 1), t > 0.
t > 0. (4.1)
u(x, 0) = f (x) x ∈ (0, 1).
Using approximations
ut (x, t + ∆t) ≈
u(x, t + ∆t) − u(x, t)
∆t
12 / 18
and
uxx (x, t+∆t) =
u(x − δx, t + ∆t) − 2u(x, t + ∆t) + u(x + δx, t + ∆t)
(∆x)2
we get
vjm+1 − vjm
∆t
=
m+1
m+1
vj−1
− 2vjm+1 + vj+1
(∆x)2
(j = 1, . . . , n, m ≥ 0) (4.4)
and from boundary conditions
m
v0m = 0, vn+1
= 0 (m ≥ 0)
and initial condition
vj0 = f (xj ) (j ≤ n)
Define v m = (v1m , . . . , vnm ) ∈ Rn . The scheme may be written
(I + ∆tA)v m+1 = v m (m ≥ 0)
where
13 / 18


0

.. 
 −1 2
. 


1 

.
.
A=

.
0 

(∆x)2  0
 ..

..
. −1 2 −1 
 .
0 . . . 0 −1 2
2
−1
0
...
.
−1 . .
..
..
.
.
Lemma 4.1 The matrix (I + ∆tA) is symmetric and positive
definite for all mesh parameters.
This follows from the fact that A is symmetric and positive definite
(so its eigenvalues are all positive).
In the implicit scheme one solves this linear system in each time
step. Since the coefficient matrix is the same, the procedure can
be made more efficient by computing the Cholesky factorization of
the matrix.
From numerical experiments one sees that the solution is well
behaved even for small ∆t and ∆x, smaller than we can use for
the explicit scheme.
14 / 18
4.5 Numerical Stability by Energy Arguments
We now introduce an energy technique for analyzing finite
difference schemes.
Consider the scheme we used for the heat equation in (4.1), with
r = ∆t/(∆x)2 :
m
m
vjm+1 = vjm + r (vj−1
− 2vjm + vj+1
),
(j = 1, . . . , n, m ≥ 0). (4.42)
with boundary conditions
m
v0m = vn+1
= 0 (m ≥ 0).
Also assume that the stability condition 1 − 2r ≥ 0 holds. Define
the discrete energy
E
m
n
X
= ∆x
(vjm )2 (4.45)
j=1
15 / 18
The goal is to show that
E m+1 ≤ E m (m ≥ 0)
We have
P
E m+1 − E m = ∆x nj=1 [(vjm+1 )2 − (vjm )2 ]
P
= ∆x nj=1 [(vjm+1 + vjm )(vjm+1 − vjm )]
P
m − 2v m + v m )] (4.47)
= r ∆x nj=1 [(vjm+1 + vjm )(vj−1
j
j+1
Pn
m
m
m
m
= r ∆x{ j=1 vj (vj−1 − 2vj + vj+1 )]
P
P
m + v m )}
−2 nj=1 vjm+1 vjm + nj=1 vjm+1 (vj−1
j+1
We consider these three terms separately:
a) Using summation by parts formula
n
n
X
X
(yj+1 − yj )zj = yn+1 zn+1 − y0 z0 +
(zj+1 − zj )yj+1
j=0
j=0
and boundary condition gives
n
n
X
X
m m
m
m
m
vj (vj−1 − 2vj + vj+1 )] = −
(vj+1
− vjm )2
j=1
j=1
16 / 18
b) Another use of summation by parts and the difference scheme
gives
−2
n
X
j=1
vjm+1 vjm = −2
n
X
(vjm )2 + 2r
j=1
n
X
m
(vj+1
− vjm )2 .
j=1
c) From (a + b)2 ≥ 0 we get ab ≤ (1/2)(a2 + b 2 ) we get
Pn
Pn
m+1 m
m+1 2
m ) ≤
m )2 + (v m )2 ))
(vj−1 + vj+1
) + (1/2)((vj−1
j=1 ((vj
j=1 vj
j+1
Pn
≤ j=1 (vjm+1 )2 + (vjm )2 )
All together:
E m+1 − E m ≤ r (E m+1 − E m ) − r (1 − 2r )∆x
Pn
m 2
j=1 [(vj+1 )
− (vjm )2
≤ r (E m+1 − E m )
Therefore (1 − r )(E m+1 − E m ) ≤ 0 and as 1 − 2r ≥ 0, we get
E m+1 ≤ E m (m ≥ 0)
17 / 18
Theorem 4.1 Let {vjm } be a solution of the finite difference scheme
(4-42)- (4-43) and let the corresponding energy {E m } be given by
(4-45). If the stability condition ∆t/(∆x)2 ≤ 1/2 (in (4.25))
holds, then {Em }is nonincreasing with respect to m.
Corollary 4.1 Assume that the stability condition (4-25) holds and
let {vjm } and {wjm } be two solutions of the finite difference
scheme (4-42)- (443). Then, for all m ≥ 0
∆x
n
X
j=1
(vjm − wjm )2 ≤ ∆x
n
X
(vj0 − wj0 )2
j=1
This means that the difference scheme is a stable dynamical
system in the sense that an error in the initial data bounds the
error in the corresponding solutions
18 / 18