You are on page 1of 6

# MATH317 TWENTY-SECOND & TWENTY-FOURTH

TUTORIAL
JAN FEYS

1. F INITE D IFFERENCE M ETHODS FOR PDE S
In many cases a problem will reduce to solving a given partial differential equation on a domain with initial data and some boundary conditions.
There are many numerical methods for doing this. One of the most intuitive is the finite difference concept for PDEs. First we will look at two
important examples. Later on we will study the stability of the schemes
via matrix method and Von Neumann stability analysis.
The first equation that will come up is the one-way wave equation
∂u
∂u
+c
= 0.
∂t
∂x
Here c is a positive parameter modeling the wave speed. Some initial condition u(x, 0) has to be given. The second and more important equation is
the diffusion equation
∂u
∂ 2u
− κ 2 = 0.
∂t
∂x
The constant k is associated to the thermal diffusivity of the medium. Again,
initial conditions and boundary conditions should be supplied.
2. D ISCRETIZING T IME AND S PACE
To be able to handle differential equations on a computer there is a need
to discretize the data. Let us choose a time step ∆t and a spatial step ∆x.
We are always going to assume u = u(x, t), t ≥ 0 and the spatial domain
to be x ∈ [0, L]. Denote with unj the value of u at time point n and spatial
point j,
unj = u(xj , tn ) = u(j∆x, n∆t).
Let us assume xJ = J∆x = L. All calculations are going to take place on
the grid on space-time we just came up with. Except for discretizing x, t
and u we also need to transform the derivatives in our equation into finite
differences. The formulas from the chapter on numerical differentiation
1

In a formula we get un+1 − unj unj − unj−1 j +c = 0. . Boundary conditions may be given on un0 and unJ for all n. 2∆x • Centered difference method for the second derivative u(x + ∆x) − 2u(x) + u(x − ∆x) u00 (x) = + O(∆x)2 . . . WAVE E QUATION B ASICS For the wave equation there are a number of ways to discretize. ∆x j Stepping in time happens from initial data u00 . • Forward difference method for the first derivative u(x + ∆x) − u(x) + O(∆x). (∆x)2 3. . un+1 =− j Other possible discretizations are the forward central scheme un+1 − unj unj+1 − unj−1 j +c + O(∆t) + O(∆x)2 = 0 ∆t 2∆x 2 . ∆t ∆x This method is called the forward upward scheme for the one-way wave equation. Replacing x with t will get the formulas for the time derivative. u0J .will come in handy here. A short overview is presented below for spatial variables. By rewriting the discretization to   c∆t n c∆t n+1 unj + u uj = 1 − ∆x ∆x j−1 one can make things more convenient by shaping the computation using a matrix form. u0j−1 . Arguably the most obvious one is to construct an explicit scheme using a forward difference in time and a forward difference in space. . u0 (x) = ∆x • Centered difference method for the first derivative u(x + ∆x) − u(x − ∆x) u0 (x) = + O(∆x)2 . u0j+1 . u0 (x) = ∆x • Backward difference method for the first derivative u(x) − u(x − ∆x) + O(∆x). . . u0j . The error term associated to the method is O(∆t) + O(∆x). The forward upward formula is explicit so that one can write c∆t n (u − unj−1 ) + unj .

  .  .   ..the backward central scheme n+1 un+1 − unj un+1 j j+1 − uj−1 +c + O(∆t) + O(∆x)2 = 0.   n       uj+1      . ∆t 2∆x and more famously the Crank-Nicolson central scheme ! n+1 n+1 un+1 − unj unj+1 − unj−1 c uj+1 − uj−1 j + + + O(∆t)2 + O(∆x)2 = 0. .   . Written explicitly we have un+1 = j  κ∆t unj+1 − 2unj + unj−1 + unj .           n  d 1 − 2d uJ−1   n+1 n uJ uJ 3 . .      . 4..    n       uj−1       n   n+1  d 1 − 2d d    uj  = uj  . j Assume for a minute that the boundary conditions given are homogeneous un0 = unJ = 0.  .       . ∆t (∆x)2 The error is O(∆t) + O(∆x)2 . Then un+1 = dunj+1 + (1 − 2d)unj + dunj−1 .   . ∆t 2 2∆x 2∆x The O symbols express the error on the formulas.   ..  . 2 (∆x) Say d = κ∆t/(∆x)2 to simplify notation. The finite difference scheme in matrix form is a tridiagonal matrix system that looks like  n   n+1  u1 u1   n     1 − 2d d  u2           . as we will see later on. The specific scheme we will look at here is the explicit centered difference scheme un+1 − unj unj+1 − 2unj + unj−1 j −κ = 0.   . The stability of these methods turns out to be very different. H EAT E QUATION B ASICS The heat equation offers a similar if not bigger range of possibilities.

2 5. Again. unj−1 = uˆn exp (if (j − 1)∆x). the Fourier frequencies. Stepping in time simply comes down to multiplying with the matrix A. V ON N EUMANN S TABILITY The most important notion of stability for a PDE is without a doubt Von Neumann stability. It turns out that the error behaves similarly. ρ is the spectral radius. Now take for u just one Fourier term u(x. t) = uˆ(t) exp (if x). The growth rate G is defined as . λk = (1 − 2d) + 2d cos J +1 One guarantees the biggest absolute value to be bounded by 1 by demanding 2d < 1. Assume we have a Fourier expansion in space of our function X u(x. Then unj = uˆn exp (if j∆x). To simplify notation we can write uˆn = uˆ(tn ). The matrix form stability criterion is thus κ∆t ≤ (∆x)2 . j These expressions can be plugged directly into any finite difference scheme to check for stability. AE n = E n+1 . For the error to remain bounded in time we need ρ(A) < 1. t) = uˆ(t) exp (if x) and evaluate it at (xj .In symbols AU n = U n+1 with A ∈ RJ×J . f The sum is over f . un+1 = uˆn+1 exp (if j∆x). unj+1 = uˆn exp (if (j + 1)∆x). tn ) to get unj = uˆ(tn ) exp (if j∆x). From linear algebra the eigenvalues of the matrix A are   πk .

.

.

uˆn+1 .

.

. G = .

.

uˆn .

For stability we need G < 1 for all frequencies f . Conditional stability means we only have stability on a certain condition. Usually the condition 4 .

It is important to note that we are checking the stability for a method. The condition for forward upwind is that c∆t ≤ ∆x. ∆t (∆x)2 Secondly let us divide the result by uˆn eif j∆x . The equation we will be looking at is the heat equation. (∆x)2 There’s some clear need for rearranging the terms. We will not derive these here but it turns out that the forward central scheme is unstable. ∆t (∆x)2 Start by plugging in the Fourier term expressions. 6. un+1 − unj unj+1 − 2unj + unj−1 j −κ = 0. both the backward central scheme and CrankNicolson are unconditionally stable and the forward upwind method is conditionally stable. uˆn (∆x)2 On the left hand side we have the growth rate. not for an equation. One obtains u ˆn+1 u ˆn −1 ∆t −κ eif ∆x − 2 + e−if ∆x = 0. but have very different stability properties. The result is  κ∆t uˆn+1 if ∆x −if ∆x = e − 2 + e + 1.limits ∆t in function of ∆x. The four methods discussed in the chapter on the one-way wave equation all solve the same equation. V ON N EUMANN FOR THE H EAT E QUATION Let us do one rigorous stability analysis. One then obtains uˆn+1 eif j∆x − uˆn eif j∆x uˆn eif (j+1)∆x − 2ˆ un eif j∆x + uˆn eif (j−1)∆x −κ = 0. The method is the one presented earlier. On the right hand side we can use the expression from complex analysis eif ∆x + e−if ∆x = 2 cos (f ∆x). It follows that .

.

.

.

κ∆t .

.

. G = .

1 + (2 cos (f ∆x) − 2) .

(∆x)2 Trigonometry saves us via the identity cos (f ∆x) − 1 = −2 sin2 (f ∆x/2). The final result is that .

.

.

.

κ∆t 2 .

G = .

1 − 4 sin (f ∆x/2).

.

. 2 (∆x) 5 .

To ensure a bounded growth rate we need to require 1 κ∆t < . (∆x)2 Elementary algebra leads to κ∆t sin2 (f ∆x/2) > 0. (∆x)2 The square of the sine is always a positive number so the right inequality is trivially satisfied. In fact.For stability we need G < 1 so −1 < 1 − 4 κ∆t sin2 (f ∆x/2) < 1. The left however might not be if sin2 (f ∆x/2) = 1. 2>4 6 . the time step should be less than the square of the spatial step. 2 (∆x) 2 The criterion we just discovered is important in practical numerical calculations: it says that for the numerics to stay under control a much more fine time step is required.