0% found this document useful (0 votes)
46 views22 pages

LNP PDF

This document discusses finite difference methods for numerically approximating solutions to partial differential equations. It begins by explaining that most differential equations cannot be solved analytically and require numerical methods. It then describes the two main categories of numerical solution schemes: finite difference methods and finite element methods. The document focuses on finite difference methods, which involve approximating derivatives with numerical differentiation formulas. It provides examples of first-order and second-order finite difference approximations and illustrates their accuracy through examples. The key points are that finite difference methods allow quantitative and qualitative analysis of solutions, and that order of accuracy depends on the approximation formula used.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views22 pages

LNP PDF

This document discusses finite difference methods for numerically approximating solutions to partial differential equations. It begins by explaining that most differential equations cannot be solved analytically and require numerical methods. It then describes the two main categories of numerical solution schemes: finite difference methods and finite element methods. The document focuses on finite difference methods, which involve approximating derivatives with numerical differentiation formulas. It provides examples of first-order and second-order finite difference approximations and illustrates their accuracy through examples. The key points are that finite difference methods allow quantitative and qualitative analysis of solutions, and that order of accuracy depends on the approximation formula used.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Numerical Analysis Lecture Notes

Peter J. Olver

11. Finite Difference Methods for


Partial Differential Equations

As you are well aware, most differential equations are much too complicated to be
solved by an explicit analytic formula. Thus, the development of accurate numerical ap-
proximation schemes is essential for both extracting quantitative information as well as
achieving a qualitative understanding of the behavior of their solutions. Even in cases, such
as the heat and wave equations, where explicit solution formulas (either closed form or in-
finite series) exist, numerical methods still can be profitably employed. Indeed, the lessons
learned in the design of numerical algorithms for solved examples are of inestimable
value when confronting more challenging problems. Furthermore, one has the ability to
accurately test a proposed numerical algorithm by running it on a known solution.
Basic numerical solution schemes for partial differential equations fall into two broad
categories. The first are the finite difference methods, obtained by replacing the derivatives
in the equation by the appropriate numerical differentiation formulae. However, there is
no guarantee that the resulting numerical scheme will accurately approximate the true so-
lution, and further analysis is required to elicit bona fide, convergent numerical algorithms.
We thus start with a brief discussion of simple finite difference formulae for numerically ap-
proximating low order derivatives of functions. The ensuing sections establish some of the
most basic finite difference schemes for the heat equation, first order transport equations,
and the second order wave equation. As we will see, not all finite difference approxima-
tions lead to accurate numerical schemes, and the issues of stability and convergence must
be dealt with in order to distinguish valid from worthless methods. In fact, inspired by
Fourier analysis, the basic stability criterion for a finite difference scheme is based on how
the scheme handles complex exponentials.
We will only introduce the most basic algorithms, leaving more sophisticated variations
and extensions to a more thorough treatment, which can be found in numerical analysis
texts, e.g., [5, 7, 29].

11.1. Finite Differences.


In general, to approximate the derivative of a function at a point, say f (x) or f (x),
one constructs a suitable combination of sampled function values at nearby points. The
underlying formalism used to construct these approximation formulae is known as the
calculus of finite differences. Its development has a long and influential history, dating

5/18/08 188
c 2008 Peter J. Olver
One-Sided Difference Central Difference
Figure 11.1. Finite Difference Approximations.

back to Newton. The resulting finite difference numerical methods for solving differential
equations have extremely broad applicability, and can, with proper care, be adapted to
most problems that arise in mathematics and its many applications.
The simplest finite difference approximation is the ordinary difference quotient
u(x + h) u(x)
u (x), (11.1)
h
used to approximate the first derivative of the function u(x). Indeed, if u is differentiable
at x, then u (x) is, by definition, the limit, as h 0 of the finite difference quotients.
Throughout our discussion, h, the step size, which may be either positive or negative, is
assumed to be small: | h | 1. When h > 0, (11.1) is referred to as a forward difference,
while h < 0 gives a backward difference. Geometrically, the  difference quotient equals
 the
slope of the secant line through the two points x, u(x) and x + h, u(x + h) on the
graph of the function. For small h, this should be a reasonably good approximation to the
slope of the tangent line, u (x), as illustrated in the first picture in Figure 11.1.
How close an approximation is the difference quotient? To answer this question, we
assume that u(x) is at least twice continuously differentiable, and examine the first order
Taylor expansion
u(x + h) = u(x) + u (x) h + 12 u () h2 . (11.2)
We have used the Cauchy form for the remainder term, [2], in which represents some
point lying between x and x + h. The error or difference between the finite difference
formula and the derivative being approximated is given by
u(x + h) u(x)
u (x) = 21 u () h. (11.3)
h
Since the error is proportional to h, we say that the finite difference quotient (11.3) is a
first order approximation. When the precise formula for the error is not so important, we
will write
u(x + h) u(x)
u (x) = + O(h). (11.4)
h
The big Oh notation O(h) refers to a term that is proportional to h, or, more rigorously,
bounded by a constant multiple of h as h 0.

5/18/08 189
c 2008 Peter J. Olver
Example 11.1. Let u(x) = sin x. Let us try to approximate u (1) = cos 1 =
.5403023 . . . by computing finite difference quotients
sin(1 + h) sin 1
cos 1 .
h
The result for different values of h is listed in the following table.
h 1 .1 .01 .001 .0001
approximation .067826 .497364 .536086 .539881 .540260
error .472476 .042939 .004216 .000421 .000042
1
We observe that reducing the step size by a factor of 10 reduces the size of the error by
approximately the same factor. Thus, to obtain 10 decimal digits of accuracy, we anticipate
needing a step size of about h = 1011 . The fact that the error is more of less proportional
to the step size confirms that we are dealing with a first order numerical approximation.
To approximate higher order derivatives, we need to evaluate the function at more
than two points. In general, an approximation to the nth order derivative u(n) (x) requires
at least n+1 distinct sample points. For simplicity, we shall only use equally spaced points,
leaving the general case to the exercises.
For example, let us try to approximate u (x) by sampling u at the particular points x,
x + h and x h. Which combination of the function values u(x h), u(x), u(x + h) should
be used? The answer to such a question can be found by consideration of the relevant
Taylor expansions
h2 h3
u(x + h) = u(x) + u (x) h + u (x) + u (x) + O(h4 ),
2 6 (11.5)
h2 h3
u(x h) = u(x) u (x) h + u (x) u (x) + O(h4 ),
2 6
where the error terms are proportional to h4 . Adding the two formulae together gives

u(x + h) + u(x h) = 2 u(x) + u (x) h2 + O(h4 ).


Rearranging terms, we conclude that
u(x + h) 2 u(x) + u(x h)
u (x) = + O(h2 ), (11.6)
h2
The result is known as the centered finite difference approximation to the second derivative
of a function. Since the error is proportional to h2 , this is a second order approximation.
2 2
Example 11.2. Let u(x) = ex , with u (x) = (4 x2 + 2) ex . Let us approximate
u (1) = 6 e = 16.30969097 . . . by using the finite difference quotient (11.6):
2 2
e(1+h) 2 e + e(1h)
6e .
h2
The results are listed in the following table.

5/18/08 190
c 2008 Peter J. Olver
h 1 .1 .01 .001 .0001
approximation 5.16158638 16.48289823 16.31141265 16.30970819 16.30969115
error 33.85189541 .17320726 .00172168 .00001722 .00000018
1
Each reduction in step size by a factor of 10 reduces the size of the error by a factor of
1
100
and results in a gain of two new decimal digits of accuracy, confirming that the finite
difference approximation is of second order.
However, this prediction is not completely borne out in practice. If we take h = .00001
then the formula produces the approximation 16.3097002570, with an error of .0000092863
which is less accurate that the approximation with h = .0001. The problem is that
round-off errors have now begun to affect the computation, and underscores the difficulty
with numerical differentiation. Finite difference formulae involve dividing very small quan-
tities, which can induce large numerical errors due to round-off. As a result, while they
typically produce reasonably good approximations to the derivatives for moderately small
step sizes, to achieve high accuracy, one must switch to a higher precision. In fact, a similar
comment applied to the previous Example 11.1, and our expectations about the error were
not, in fact, fully justified as you may have discovered if you tried an extremely small step
size.

Another way to improve the order of accuracy of finite difference approximations is


to employ more sample points. For instance, if the first order approximation (11.4) to the
first derivative based on the two points x and x + h is not sufficiently accurate, one can try
combining the function values at three points x, x + h and x h. To find the appropriate
combination of u(x h), u(x), u(x +h), we return to the Taylor expansions (11.5). To solve
for u (x), we subtract the two formulae, and so

h3
u(x + h) u(x h) = 2 u (x) h + u (x) + O(h4 ).
3
Rearranging the terms, we are led to the well-known centered difference formula

u(x + h) u(x h)
u (x) = + O(h2 ), (11.7)
2h
which is a second order approximation to the first derivative. Geometrically, the cen-
tered difference quotient
 represents the slope of the secant line through the two points
x h, u(x h) and x + h, u(x + h) on the graph of u centered symmetrically about
the point x. Figure 11.1 illustrates the two approximations; the advantages in accuracy in
the centered difference version are graphically evident. Higher order approximations can be
found by evaluating the function at yet more sample points, including, say, x + 2 h, x 2 h,
etc.


This next computation depends upon the computers precision; here we used single precision
in Matlab.

The terms O(h4 ) do not cancel, since they represent potentially different multiples of h4 .

5/18/08 191
c 2008 Peter J. Olver
Example 11.3. Return to the function u(x) = sin x considered in Example 11.1.
The centered difference approximation to its derivative u (1) = cos 1 = .5403023 . . . is
sin(1 + h) sin(1 h)
cos 1 .
2h
The results are tabulated as follows:

h .1 .01 .001 .0001


approximation .53940225217 .54029330087 .54030221582 .54030230497
error .00090005370 .00000900499 .00000009005 .00000000090

As advertised, the results are much more accurate than the one-sided finite difference
approximation used in Example 11.1 at the same step size. Since it is a second order
1
approximation, each reduction in the step size by a factor of 10 results in two more decimal
places of accuracy.
Many additional finite difference approximations can be constructed by similar manip-
ulations of Taylor expansions, but these few very basic ones will suffice for our subsequent
purposes. In the following subsection, we apply the finite difference formulae to develop
numerical solution schemes for the heat and wave equations.

11.2. Numerical Algorithms for the Heat Equation.


Consider the heat equation
u 2u
= , 0 < x < , t 0, (11.8)
t x2
representing a bar of length and constant thermal diffusivity > 0. To be concrete, we
impose time-dependent Dirichlet boundary conditions
u(t, 0) = (t), u(t, ) = (t), t 0, (11.9)
specifying the temperature at the ends of the bar, along with the initial conditions
u(0, x) = f (x), 0 x , (11.10)
specifying the bars initial temperature distribution. In order to effect a numerical approx-
imation to the solution to this initial-boundary value problem, we begin by introducing a
rectangular mesh consisting of points (ti , xj ) with
0 = t 0 < t1 < t2 < and 0 = x0 < x1 < < xn = .
For simplicity, we maintain a uniform mesh spacing in both directions, with

t = ti+1 ti , x = xj+1 xj =
,
n
representing, respectively, the time step size and the spatial mesh size. It will be essential
that we do not a priori require the two to be the same. We shall use the notation
ui,j u(ti , xj ) where ti = i t, xj = j x, (11.11)

5/18/08 192
c 2008 Peter J. Olver
to denote the numerical approximation to the solution value at the indicated mesh point.
As a first attempt at designing a numerical method, we shall employ the simplest
finite difference approximations to the derivatives. The second order space derivative is
approximated by (11.6), and hence

2u u(ti , xj+1 ) 2 u(ti , xj ) + u(ti , xj1 ) 


2
(ti , xj ) 2
+ O (x)2
x (x)
(11.12)
ui,j+1 2 ui,j + ui,j1 2

+ O (x) ,
(x)2
where the error in the approximation is proportional to (x)2 . Similarly, the one-sided
finite difference approximation (11.4) is used to approximate the time derivative, and so

u u(ti+1 , xj ) u(ti , xj ) ui+1,j ui,j


(ti , xj ) + O(t) + O(t), (11.13)
t t t
where the error is proportion to t. In practice, one should try to ensure that the approx-
imations have similar orders of accuracy, which leads us to choose

t (x)2 .
Assuming x < 1, this requirement has the important consequence that the time steps
must be much smaller than the space mesh size.
Remark : At this stage, the reader might be tempted to replace (11.13) by the second
order central difference approximation (11.7). However, this produces significant compli-
cations, and the resulting numerical scheme is not practical; see Exercise 11.2.11.
Replacing the derivatives in the heat equation (11.14) by their finite difference ap-
proximations (11.12), (11.13), and rearranging terms, we end up with the linear system
i = 0, 1, 2, . . . ,
ui+1,j = ui,j+1 + (1 2 )ui,j + ui,j1 , (11.14)
j = 1, . . . , n 1,
in which
t
= . (11.15)
(x)2
The resulting numerical scheme takes the form of an iterative linear system, in which,
starting at the initial time t0 , the solution values ui+1,j u(ti+1 , xj ) at time ti+1 are
calculated from those at the preceding time ti .
The initial condition (11.10) means that we should initialize our numerical data by
sampling the initial temperature at the mesh points:

u0,j = fj = f (xj ), j = 1, . . . , n 1. (11.16)


Similarly, the boundary conditions (11.9) require that

ui,0 = i = (ti ), ui,n = i = (ti ), i = 0, 1, 2, . . . . (11.17)

5/18/08 193
c 2008 Peter J. Olver
For consistency, we should assume that the initial and boundary conditions agree at the
corners of the domain:

f0 = f (0) = u(0, 0) = (0) = 0 , fn = f () = u(0, ) = (0) = 0 .

The three equations (11.1417) completely prescribe the numerical approximation algo-
rithm for solving the initial-boundary value problem (11.810).
Let us rewrite the scheme in a more transparent matrix form. First, let
T T
u(i) = ui,1 , ui,2 , . . . , ui,n1 u(ti , x1 ), u(ti , x2 ), . . . , u(ti , xn1 ) (11.18)

be the vector whose entries are the numerical approximations to the solution values at
time ti at the interior nodes. We omit the boundary nodes x0 = 0, xn = , since those
values are fixed by the boundary conditions (11.9). Then (11.14) has the form

u(i+1) = A u(i) + b(i) , (11.19)

where

1 2 i
1 2 0

1 2 0

A= ..
.
..
. , b(i) = ..

. (11.20)
.
.. .. 0
. .

1 2 i

The coefficient matrix A is symmetric and tridiagonal. The contributions (11.17) of the
boundary nodes appear in the vector b(i) . This numerical method is known as an explicit
scheme since each iterate is computed directly without relying on solving an auxiliary
equation unlike the implicit schemes to be discussed below.

Example 11.4. Let us fix the diffusivity = 1 and the bar length = 1. For
illustrative purposes, we take a spatial step size of x = .1. In Figure 11.2 we compare
two (slightly) different time step sizes on the initial data

x,
0 x 15 ,
u(0, x) = f (x) = x 25 , 1
5
7
x 10 , (11.21)

7
1 x, 10 x 1.

The first sequence uses the time step t = (x)2 = .01 and plots the solution at times
t = 0., .02, .04. The numerical solution is already showing signs of instability, and indeed
soon thereafter becomes completely wild. The second sequence takes t = .005 and plots
the solution at times t = 0., .025, .05. (Note that the two sequences of plots have different
vertical scales.) Even though we are employing a rather coarse mesh, the numerical solution
is not too far away from the true solution to the initial value problem.

5/18/08 194
c 2008 Peter J. Olver
1 1 1

0.5 0.5 0.5

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1

-0.5 -0.5 -0.5

-1 -1 -1

0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1

-0.1 -0.1 -0.1

-0.2 -0.2 -0.2

Figure 11.2. Numerical Solutions for the Heat Equation


Based on the Explicit Scheme.

In light of this calculation, we need to understand why our scheme sometimes gives
reasonable answers but at other times utterly fails. To this end, we investigate the effect
of the numerical scheme on simple functions. As we know, the general solution to the heat
equation can be decomposed into a sum over the various Fourier modes. Thus, we can
concentrate on understanding what the numerical scheme does to an individual complex
exponential function, bearing in mind that we can then reconstruct the cumulative effect
by taking suitable linear combinations.
Suppose that, at a time t = ti , the solution is a pure exponential

u(ti , x) = e i k x , and so ui,j = u(ti , xj ) = e i k xj . (11.22)


Substituting these values into our numerical equations (11.14), we find the updated value
at time ti+1 is also an exponential:

ui+1,j = ui,j+1 + (1 2 )ui,j + ui,j1 = e i k xj+1 + (1 2 )e i k xj + e i k xj1


= e i k(xj +x) + (1 2 )e i k xj + e i k(xj x) = e i k xj ,
(11.23)
where

= e i k x + (1 2 ) + e i k x = 1 2 (1 cos k x) = 1 4 sin2 21 k x. (11.24)


Thus, the effect of a single step of the numerical scheme is to multiply the complex expo-
nential (11.22) by the so-called magnification factor :

u(ti+1 , x) = e i k x , and so ui+1,j = u(ti+1 , xj ) = e i k xj . (11.25)


As usual, complex exponentials are much easier to work with than real trigonometric func-
tions.

5/18/08 195
c 2008 Peter J. Olver
In other words, e i k x assumes the role of an eigenfunction, with the magnification factor
being the corresponding eigenvalue, of the linear operator governing each step of the
numerical scheme. Continuing, we find that the effect of n further iterations of the scheme
is to multiply the exponential by the nth power of the magnification factor:

u(ti+n , x) = n e i k x . (11.26)
Thus, the stability of the scheme will be governed by the size of the magnification factor.
If | | > 1, then n is exponentially growing as n , and so the numerical solutions
(11.26) become unbounded as t . This is clearly incompatible with the analytical
behavior of solutions to the heat equation, and so a necessary condition for the stability
of our numerical scheme is that its magnification factor satisfy

| | 1. (11.27)

This method of stability analysis was developed by the mid-twentieh century Hungar-
ian mathematician and father of the electronic computer John von Neumann. The
stability criterion (11.27) effectively distinguishes the stable, and hence valid numerical al-
gorithms from the unstable, and hence worthless schemes. For the particular case (11.24),
the von Neumann stability criterion requires

t 1 (x)2
= 2
, or t , (11.28)
(x) 2 2
and thus restricts the allowable time step size. For instance, if we have x = .01, and
= 1, then we can only use a time step size t .00005, which is minuscule. It would
take an inordinately large number of time steps to compute the value of the solution at
even a moderate times, e.g., t = 1. Moreover, owing to the limited accuracy of computers,
the propagation of round-off errors might then cause a significant reduction in the overall
accuracy of the final solution values. Since not all choices of space and time steps lead to
a convergent scheme, the explicit scheme (11.14) is called conditionally stable.
An unconditionally stable method one that does not restrict the time step can
be constructed by using the backwards difference formula

u u(ti , xj ) u(ti1 , xj ) 
(ti , xj ) + O (t)2 (11.29)
t t
to approximate the time derivative. Substituting (11.29) and the same approximation
(11.12) for uxx into the heat equation, and then replacing i by i + 1, leads to the iterative
system
i = 0, 1, 2, . . . ,
ui+1,j+1 + (1 + 2 )ui+1,j ui+1,j1 = ui,j , (11.30)
j = 1, . . . , n 1,
where the parameter = t/(x)2 is as above. The initial and boundary conditions
also have the same form (11.16, 17). The system can be written in the matrix form

b u(i+1) = u(i) + b(i+1) ,


A (11.31)

5/18/08 196
c 2008 Peter J. Olver
0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.1 -0.1 -0.1

-0.2 -0.2 -0.2

0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.1 -0.1 -0.1

-0.2 -0.2 -0.2

Figure 11.3. Numerical Solutions for the Heat Equation


Based on the Implicit Scheme.

where A b is obtained from the matrix A in (11.20) by replacing by . This serves to


define an implicit scheme, since we have to solve a linear system of algebraic equations at
each step in order to compute the next iterate u(i+1) . However, as the coefficient matrix A b
is tridiagonal, the system can be solved very rapidly, [42], and so speed is not a significant
issue in the practical implementation of this implicit scheme.
Let us apply the von Neumann analysis to investigate the stability of the implicit
scheme. Again, we need only look at the effect of the scheme on a complex exponential.
Substituting (11.22, 25) into (11.30) and canceling the common exponential factor leads to
the equation 
e i k x + 1 + 2 e i k x = 1.
We solve for the magnification factor
1 1
= = . (11.32)
1 + 2 1 cos k x 1 + 4 sin2 21 k x
Since > 0, the magnification factor always less than 1 in absolute value, and so the
stability criterion (11.27) is satisfied for any choice of step sizes. We conclude that the
implicit scheme (11.14) is unconditionally stable.
Example 11.5. Consider the same initial-boundary value problem considered in
Example 11.4. In Figure 11.3, we plot the numerical solutions obtained using the implicit
scheme. The initial data is not displayed, but we graph the numerical solutions at times
t = .2, .4, .6 with a mesh size of x = .1. On the top line, we use a time step of t = .01,
while on the bottom t = .005. Unlike the explicit scheme, there is very little difference
between the two both come much closer to the actual solution than the explicit scheme.
Indeed, even significantly larger time steps give reasonable numerical approximations to
the solution.
Another popular numerical scheme for solving the heat equation is the CrankNicolson
method
1
ui+1,j ui,j = 2 (ui+1,j+1 2 ui+1,j + ui+1,j1 + ui,j+1 2 ui,j + ui,j1 ). (11.33)

5/18/08 197
c 2008 Peter J. Olver
0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.1 -0.1 -0.1

-0.2 -0.2 -0.2

0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.1 -0.1 -0.1

-0.2 -0.2 -0.2

Figure 11.4. Numerical Solutions for the Heat Equation


Based on the CrankNicolson Scheme.

which can be obtained by averaging the explicit and implicit schemes (11.14, 30). We can
write (11.33) in matrix form

B u(i+1) = C u(i) + 12 b(i) + b(i+1) ,
where

1+ 21 1 1
2
21 1 + 21 21 1 1

2
B=
.. ..
. , C=
.. ..
. . (11.34)
12 .
1
2
.
.. .. .. ..
. . . .
Applying the von Neumann analysis as before, we deduce that the magnification factor
has the form
1 2 sin2 21 k x
= . (11.35)
1 + 2 sin2 21 k x
Since > 0, then | | 1 for all choices of step size, and so the CrankNicolson scheme
is also unconditionally stable. A detailed analysis will show that the errors are of the
order of (t)2 and (x)2 , and so it is reasonable to choose the time step to have the same
order of magnitude as the space step, t x. This gives the CrankNicolson scheme
one advantage over the previous two methods. However, applying it to the initial value
problem considered earlier points out a significant weakness. Figure 11.4 shows the result
of running the scheme on the initial data (11.21). The top row has space and time step
sizes t = x = .1, and does a rather poor job replicating the solution. The second row
uses t = x = .01, and performs better except near the corners where an annoying and
incorrect local time oscillation persists as the solution decays. Indeed, unlike the implicit
scheme, the CrankNicolson method fails to rapidly damp out the high frequency modes
associated with small scale features such as discontinuities and corners in the initial data.
In such situations, a good strategy is to first evolve using the implicit scheme until the
small scale noise is dissipated away, and then switch to CrankNicolson to use a much
larger time step for the final large scale changes.

5/18/08 198
c 2008 Peter J. Olver
11.3. Numerical Solution Methods for
First Order Partial Differential Equations.
We begin with the initial value problem for the elementary constant coefficient trans-
port equation
u u
+c = 0, u(0, x) = f (x). (11.36)
t x
The solution is a simple traveling wave

u(t, x) = f (x c t), (11.37)


that is constant along the characteristic lines of slope c in the t x plane. Although the
analytical solution is completely elementary, there will be valuable lessons to be learned
from an attempt to reproduce it by numerical approximation. Indeed, each of the numerical
schemes developed below has an evident adaptation to transport equations with variable
wave speeds c(t, x), and even to nonlinear transport equations whose wave speed depends
on the solution u and can admit shock wave solutions.
As usual, we restrict our attention to a regular mesh (ti , xj ) with uniform time and
space step sizes t = ti+1 ti and x = xj+1 xj . We use ui,j u(ti , xj ) to denote
our numerical approximation to the solution u(t, x) at the indicated mesh point. The
most elementary numerical solution scheme is obtained by replacing the time and space
derivatives in the transport equation by their first order finite difference approximations
(11.1):
u ui+1,j ui,j u ui,j+1 ui,j
(ti , xj ) + O(t), (ti , xj ) + O(x). (11.38)
t t x x
The result is the explicit numerical scheme

ui+1,j = ui,j+1 + ( + 1)ui,j , (11.39)


in which the parameter
c t
= (11.40)
x
depends upon the wave speed and the ratio of space and time step sizes. Since we are
employing first order approximations to both derivatives, we should choose the time and
space step sizes to be of comparable size t x. When working on a bounded interval,
say 0 x , we will need to specify a value for the numerical solution at the left end,
e.g., setting ui,n = 0; this corresponds to imposing the boundary condition u(t, ) = 0.
In Figure 11.5, we plot the solutions arising from the following initial conditions
2 2
u(0, x) = f (x) = .4 e300(x.5) + .1 e300(x.65) , (11.41)
at times t = 0, .15 and .3. We use step sizes t = x = .005, and try four different values
of the wave speed. The cases c = .5 and c = 1.5 are clearly exhibiting some form of
numerical instability. The numerical solution c = .5 is a bit more reasonable, although one
can already observe some degradation due to the relatively low accuracy of the scheme.

5/18/08 199
c 2008 Peter J. Olver
0.7 0.7 0.7

0.6 0.6 0.6

0.5 0.5 0.5

0.4 0.4 0.4

0.3 0.3 0.3

0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1

c = .5
0.7 0.7 0.7

0.6 0.6 0.6

0.5 0.5 0.5

0.4 0.4 0.4

0.3 0.3 0.3

0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1

c = .5
0.7 0.7 0.7

0.6 0.6 0.6

0.5 0.5 0.5

0.4 0.4 0.4

0.3 0.3 0.3

0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1

c = 1
0.7 0.7 0.7

0.6 0.6 0.6

0.5 0.5 0.5

0.4 0.4 0.4

0.3 0.3 0.3

0.2 0.2 0.2

0.1 0.1 0.1

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1

c = 1.5

Figure 11.5. Numerical Solutions to the Transport Equation.

This can be overcome by selecting a smaller step size. The case c = 1 looks particularly
good but this is an accident. The analytic solution also happens to be an exact solution
to the numerical equations, and so the only possible source of error is round-off.
The are two ways to understand the observed numerical instability. First, we recall
the exact solution is constant along the characteristic lines x = c t + , and hence the
value of u(t, x) only depends on the initial value f () at the point = x c t. On
the other hand, at time t = tn , the numerical solution un,j u(tn , xj ) computed using
(11.39) depends on the values of un1,j and un1,j+1 . The latter two values have been

5/18/08 200
c 2008 Peter J. Olver
x x

t t

Stable Unstable
Figure 11.6. The CFL Condition.

computed from the previous approximations un2,j , un2,j+1 , un2,j+2 . And so on. Going
all the way back to the initial time t0 = 0, we find that un,j depends on the initial
values u0,j = f (xj ), . . . , u0,j+n = f (xj + n x) at the mesh points lying in the interval
xj x xj + n x. On the other hand, the actual solution u(tn , xj ) depends only on the
value of f () where
= xj c tn = xj c n t.

Thus, if lies outside the interval [ xj , xj + n x ], then varying the initial condition f (x)
nearby x = will change the solution value u(tn , xj ) without affecting its numerical ap-
proximation un,j at all! So the numerical scheme cannot possibly provide an accurate
approximation to the solution value. As a result, we must require

xj = xj c n t xj + n x, and hence 0 c n t n x,

which we rewrite as
c t x
0= 1, or, equivalently, c 0. (11.42)
x t
This is the simplest manifestation of the CourantFriedrichsLewy condition, or CFL con-
dition for short, established in the 1950s by three of the pioneers in the development of
numerical solutions schemes for hyperbolic partial differential equations. Note that the
CFL condition requires that the wave speed be negative, but not too negative. For nega-
tive wave speeds, the method is conditionally stable, since stability restricts the possible
time step sizes.
The CFL condition can be recast in a more geometrically transparent manner as
follows. For the finite difference scheme (11.39), the numerical domain of dependence of a
point (tn , xj ) is the triangle

T(tn ,xj ) = (t, x) 0 t tn , xj x xj + tn t . (11.43)

5/18/08 201
c 2008 Peter J. Olver
The reason for this term is that the numerical approximation to the solution at (tn , xj )
depends on the computed values at the mesh points lying within its numerical domain of
dependence; see Figure 11.6. The CFL condition (11.42) requires that, for 0 t ti , the
characteristic passing through the point (tn , xj ) lies entirely within the numerical domain
of dependence (11.43). If the characteristic ventures outside the domain, then the scheme
will be numerically unstable. With this geometric formulation, the CFL criterion can
be applied to both linear and nonlinear transport equations that have non-uniform wave
speeds.
The CFL criterion (11.42) is reconfirmed by a von Neumann stability analysis. We
test the numerical scheme on an exponential function, as in (11.22, 25): Substituting

ui,j = e i k xj , ui+1,j = e i k x , (11.44)

into (11.39) leads to



e i k x = e i k xj+1 + ( + 1)e i k xj = e i k x + + 1 e i k xj .

The resulting magnification factor



= 1 + 1 e i k x

satisfies the stability criterion (11.27) if and only if

| |2 = 1 + 2 ( + 1)(1 cos(k x)) 1,

for all k. Thus, stability requires that 1 0, in complete accord with the CFL
condition (11.42).
To obtain a finite difference scheme that can be used for positive wave speeds, we
replace the forward finite difference approximation to u/x by the corresponding back-
wards difference quotient (11.1) with h = x leading to the alternative first order
numerical scheme
ui+1,j = (1 )ui,j + ui,j1 , (11.45)

where = c t/x is as above. A similar analysis, left to the reader, produces the
corresponding stability criterion
c t
0= 1,
x
now permitting a positive range of wave speeds.
In this manner, we have produced one numerical scheme that works for a range of
negative wave speeds, and an alternative scheme for positive speeds. The question arises
particularly when one is desaling with equations with variable wave speeds whether
one can devise a scheme that is (conditionally) stable for both positive and negative wave
speeds. One might be tempted to use the centered difference approximation (11.7) for

u ui,j+1 ui,j1 
(ti , xj ) + O (x)2 . (11.46)
x x
5/18/08 202
c 2008 Peter J. Olver
Figure 11.7. The CFL Condition for the Centered Difference Scheme.
1 1 1

0.8 0.8 0.8

0.6 0.6 0.6

0.4 0.4 0.4

0.2 0.2 0.2

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1

-0.2 -0.2 -0.2

-0.4 -0.4 -0.4

t = .15 t = .3 t = .45
Figure 11.8. Centered Difference Numerical Solution to the Transport Equation.

Substituting this and the previous approximation to the time derivative into (11.36) leads
to the numerical scheme

ui+1,j = 21 ui,j+1 + ui,j + 21 ui,j1 , (11.47)


where = c k/h is the same as above. In this case, the numerical domain of dependence
of the mesh point (tn , xj ) consists of the mesh points in the triangle

Te(tn ,xj ) = (t, x) 0 t tn , xj tn + t x xj + tn t . (11.48)

The CFL condition asks that, for 0 t tn , the characteristic going through (tn , xj ) lie
within this triangle, as in Figure 11.7, which requires

c t x
| | = 1,
or, equivalently, |c| . (11.49)
x t
Unfortunately, although it satisfies the CFL condition over this range of wave speeds,
the centered difference scheme is, in fact, always unstable! For instance, the instability
of the numerical solution to the preceding initial value problem (11.41) for c = 1 can
be seen in Figure 11.8. This is confirmed by applying the von Neumann analysis: We

5/18/08 203
c 2008 Peter J. Olver
substitute (11.44) into (11.47), and cancel the common exponential factors. The resulting
magnification factor
= 1 i sin(k x)
satisfies | | > 1 except when = 0, which would mean c = 0. Thus, the centered
difference scheme (11.47) is unstable for all (nonzero) wave speeds!
One elementary means of overcoming the sign restriction on the wave speed is to use
the forward difference scheme (11.39) when the wave speed is negative and the backwards
scheme (11.45) when it is positive. The resulting scheme, valid for varying wave speeds
c(t, x),
( c t
ui,j+1 + ( + 1)ui,j , c 0, = ,
ui+1,j = where x (11.50)
(1 )ui,j + ui,j1 , c > 0, c = ci,j = c(ti , xj ),
is known as the upwind scheme, since the second mesh point always lies upwind
that is away from the direction of motion of the reference point (ti , xj ). The upwind
scheme works reasonably well over short time intervals assuming the space step size is
chose sufficiently small and the time step satisfies the CFL condition (11.42). However,
over longer time intervals, as we already observed in Figure 11.5, it tends to exhibit an
unacceptable rate of damping of waves or, alternatively, require an unacceptably small
step size. One way of overcoming this defect is to use the popular LaxWendroff scheme

ui+1,j = 1
2 (1 + ) ui,j+1 + (1 2 )ui,j 12 (1 ) ui,j1 , (11.51)
which is based on a quadratic approximation to the derivatives, [39]. The stability analysis
of this scheme is relegated to the exercises.

11.4. Numerical Solution Methods for the Wave Equation.


Let us now develop the basic numerical solution techniques for the second order wave
equation. As above, although we are in possession of the explicit dAlembert solution
formula, the lessons learned in designing stable schemes in this simple case will carry over
to more complicated equations, including inhomogeneous media and higher dimensional
problems, where analytic solution formulas are no longer readily available.
Consider the wave equation

2u 2
2 u
= c , 0 < x < , t 0, (11.52)
t2 x2
modeling vibrations of a homogeneous bar of length with constant wave speed c > 0. We
impose Dirichlet boundary conditions

u(t, 0) = (t), u(t, ) = (t), t 0, (11.53)


Unless sin(k x) = 0, but we need the stability criterion to hold for all values of k.

5/18/08 204
c 2008 Peter J. Olver
along with the usual initial conditions
u
u(0, x) = f (x), (0, x) = g(x), 0 x . (11.54)
t
We adopt the same uniformly spaced mesh as before

ti = i t, xj = j x, . where x =
n
In order to discretize the wave equation, we replace the second order derivatives by their
standard finite difference approximations (11.6), namely

2u u(ti+1 , xj ) 2 u(ti , xj ) + u(ti1 , xj ) 


2
(ti , xj ) 2
+ O (t)2 ,
t (t)
(11.55)
2u u(ti , xj+1 ) 2 u(ti , xj ) + u(ti , xj1 ) 2

(t , x ) + O (x) ,
x2 i j (x)2
Since the errors are of orders of (t)2 and (x)2 , we expect to be able to choose the space
and time step sizes of comparable magnitude:

t x.
Substituting the finite difference formulae (11.55) into the partial differential equation
(11.52), and rearranging terms, we are led to the iterative system
i = 1, 2, . . . ,
ui+1,j = 2 ui,j+1 + 2 (1 2 ) ui,j + 2 ui,j1 ui1,j , (11.56)
j = 1, . . . , n 1,
for the numerical approximations ui,j u(ti , xj ) to the solution values at the mesh points.
The positive parameter
c t
= > 0 (11.57)
x
depends upon the wave speed and the ratio of space and time step sizes. The boundary
conditions (11.53) require that
ui,0 = i = (ti ), ui,n = i = (ti ), i = 0, 1, 2, . . . . (11.58)
This allows us to rewrite the system in matrix form

u(i+1) = B u(i) u(i1) + b(i) , (11.59)


where
2
2 (1 2 ) 2 ui,1 i
2 2 (1 2 ) 2 ui,2 0
.
.. .. .
B= 2 . . , u(i) = .. , b =
(i) .
. .
.. .. 0
. . 2 u
i,n2
2
2 (1 2 ) uii,n1 2 i
(11.60)

5/18/08 205
c 2008 Peter J. Olver
The entries of u(i) are, as in (11.18), the numerical approximations to the solution values
at the interior nodes. Note that (11.59) describes a second order iterative scheme, since
computing the next iterate u(i+1) requires the value of the preceding two, u(i) and u(i1) .
The one subtlety is how to get the method started. We know u(0) since u0,j = fj =
f (xj ) is determined by the initial position. However, we also need to find u(1) with entries
u1,j u(t, xj ) at time t1 = t in order launch the iteration and compute u(2) , u(3) , . . . ,
but the initial velocity ut (0, x) = g(x) prescribes the derivatives ut (0, xj ) = gj = g(xj )
at time t0 = 0 instead. One way to resolve this difficulty would be to utilize the finite
difference approximation

u u(t, xj ) u(0, xj ) u1,j fj


gj = (0, xj ) (11.61)
t t t
to compute the required values
u1,j = fj + t gj .

However, the approximation (11.61) is only accurate to order t, whereas the rest of the
scheme has errors proportional to (t)2 . The effect would be to introduce an unacceptably
large error at the initial step.
To construct an initial approximation to u(1) with error on the order of (t)2 , we
need to analyze the local error in (11.61) in more detail. Note that, by Taylors theorem,

u(t, xj ) u(0, xj ) u t 2 u 2

= (0, xj ) + (0, x j ) + O (t)
t t 2 t2
u c2 t 2 u 2

= (0, xj ) + (0, xj ) + O (t) ,
t 2 x2
where, in the final equality, we have used the fact that u(t, x) solves the wave equation.
Therefore, we find

u c2 (t)2 2 u
u1,j = u(t, xj ) u(0, xj ) + t (0, xj ) + (0, xj )
t 2 x2
c2 (t)2 c2 (t)2
= f (xj ) + t g(xj ) + f (xj ) fj + t gj + (f 2 fj + fj1 ) ,
2 2 (x)2 j+1

where we can use the finite difference approximation (11.6) for the second derivative of
f (x) if no explicit formula is known. Therefore, when we initiate the scheme by setting

u1,j = 1
2 2 fj+1 + (1 2 )fj + 1
2 2 fj1 + t gj , (11.62)

or, in matrix form,

u(0) = f , u(1) = 1
2 B u(0) + t g + 12 b(0) , (11.63)

we will have maintained the desired order (t)2 (and (x)2 ) accuracy.

5/18/08 206
c 2008 Peter J. Olver
1 1 1
0.75 0.75 0.75
0.5 0.5 0.5
0.25 0.25 0.25

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.25 -0.25 -0.25
-0.5 -0.5 -0.5
-0.75 -0.75 -0.75
-1 -1 -1

1 1 1
0.75 0.75 0.75
0.5 0.5 0.5
0.25 0.25 0.25

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.25 -0.25 -0.25
-0.5 -0.5 -0.5
-0.75 -0.75 -0.75
-1 -1 -1

Figure 11.9. Numerically Stable Waves.

1 1 1
0.75 0.75 0.75
0.5 0.5 0.5
0.25 0.25 0.25

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.25 -0.25 -0.25
-0.5 -0.5 -0.5
-0.75 -0.75 -0.75
-1 -1 -1

1 1 1
0.75 0.75 0.75
0.5 0.5 0.5
0.25 0.25 0.25

0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1 0.2 0.4 0.6 0.8 1
-0.25 -0.25 -0.25
-0.5 -0.5 -0.5
-0.75 -0.75 -0.75
-1 -1 -1

Figure 11.10. Numerically Unstable Waves.

Example 11.6. Consider the particular initial value problem


2
u(0, x) = e 400 (x.3) , ut (0, x) = 0, 0 x 1,
utt = uxx ,
u(t, 0) = u(1, 0) = 0, t 0,

subject to homogeneous Dirichlet boundary conditions on the interval [ 0, 1 ]. The initial


data is a fairly concentrated single hump centered at x = .3, and we expect it to split into
two half sized humps, which then collide with the ends. Let us choose a space discretization
1
consisting of 90 equally spaced points, and so x = 90 = .0111 . . . . If we choose a time
step of t = .01, whereby = .9, then we get reasonably accurate solution over a fairly
long time range, as plotted in Figure 11.9 at times t = 0, .1, .2, . . . , .5. On the other hand,
if we double the time step, setting t = .02, so = 1.8, then, as plotted in Figure 11.10 at
times t = 0, .05, .1, .14, .16, .18, we observe an instability that eventually overwhelms the
numerical solution. Thus, the numerical scheme appears to only be conditionally stable.

5/18/08 207
c 2008 Peter J. Olver
Stable Unstable
Figure 11.11. The CFL Condition for the Wave Equation.

The stability analysis of this numerical scheme proceeds along the same lines as in
the first order case. The CFL condition for stability requires that the characteristics
emanating from a mesh point (tn , xj ) must, for 0 t tn , remain in its numerical domain
of dependence, which, for our particular numerical scheme, is the same triangle

Te(tn ,xj ) = (t, x) 0 t tn , xj tn + t x xj + tn t ,
that we plotted Figure 11.11. Since the characteristics are the lines of slope c, the CFL
condition is the same as in (11.49):
c t x
= 1, or, equivalently, 0c . (11.64)
x t
This explains the difference between the numerically stable and unstable cases exhibited
above.
However, as we noted above, the CFL condition is only necessary for stability of the
numerical scheme; one should perform a von Neumann stability analysis for a complete
verification. Inspired by fourier analysis, the goal is to determine how the scheme affects
complex exponentials. Specifically, after one time step, the scheme has the effect of mul-
tiplying a complex exponential e i k x by the (local) magnification factor = (k). In this
case, we set
ui1,j = e i k xj , ui,j = e i k xj , ui+1,j = 2 e i k xj , (11.65)
since going from ti1 to ti multiplies the exponential by , and from ti to ti+1 multiplies
by an additional factor . Substituting (11.65) into (11.56) and canceling the common
exponential, we find that each magnification factor must satisfy the following quadratic
equation: 
2 = 2 4 2 sin2 12 k x + 1,


Stability is a long term effect, and so we need not concern ourselves with the anomalous first
time step.

5/18/08 208
c 2008 Peter J. Olver
whence p
= 2 1 , where = 1 2 2 sin2 12 k x. (11.66)
Thus, there are two different magnification factors associated with each complex exponen-
tial which is a consequence of the scheme being of second order. Stability requires that
both be 1 in modulus. Now, if the CFL condition (11.64) holds, then | | 1, which
implies that the magnification factors (11.66) are complex numbers of modulus | | = 1,
and thus the numerical scheme satisfies the stability criterion (11.27). On the other hand,
if > 1, then, for some values of k, we have < 1, which implies that the two factors
(11.66) are both real, one of which is < 1, and thus violates the stability criterion. Thus,
the CFL condition (11.64) does indeed distinguish between the (conditionally) stable and
unstable numerical schemes for the wave equation.

5/18/08 209
c 2008 Peter J. Olver

You might also like