FiniteDifferences
FiniteDifferences
These notes discuss using finite differences to solve physical problems that are ex-
pressed using partial differential equations (PDEs). If a PDE cannot be solved ana-
lytically, then we approximate the solution by solving it numerically. Finite difference
methods are just one way to approximate the solution of PDEs that are linear. The
solutions are motivated by examples; the PDEs are linear equations. Nonlinear PDEs
require different approximation techniques.
Just like the solution to an integral is a family of functions1 , the solution to a PDE
is also a family of functions.
To obtain a unique solution to the PDE we can constrain the solution by specifying
the boundary conditions of the region. and then use these (fixed) boundary values
to determine the values of the interior region. These constraints, usually defined as
functions, are called the Dirichtlet boundary conditions.
∂2u ∂2u
∇2 u ≡ (x, y) + (x, y) = f (x, y)
∂x2 ∂y 2
2
x2
It is called elliptic because of its similarity to the equation for an ellipse: a2
+ yb2 = r.
We want to find the solution to this PDE: the function u(x, y), which denotes the
temperature at position (x, y) in the plane; x and y have physical units.
If the function f (x, y) 6= 0 at x, y, then this positions is a heat source (or sink). When
f (x, y) == 0 for all interior positions, it means that the interior has no heat sources
or sinks:
1
Recall taking integrals: you learned that you had to add a parameter c to the result, called the
constant of integration. This result represents a family of solutions. You make the solution unique
by substituting a value for c.
1
∂2u ∂2u
∇2 u ≡ (x, y) + (x, y) = 0
∂x2 ∂y 2
This is called Laplace’s equation, and commonly is denoted ∇2 = 0.
Consider a thin metal square plate with dimensions 0.5 meters by 0.5 meters. Two ad-
jacent boundaries are held at a constant 0 deg C. The heat on the other two boundaries
increases linearly from 0 deg C to 100 deg C. We want to know what the temperature
is at each point when the temperature of the metal has reached steady-state,
It is called parabolic because of its similarity to the parabolic equation: y = ax2 (or,
y − ax2 = 0).
If we again use heat as an example, solution to this equation is the function u(x, t),
where u(x, t) is the temperature of x at time t.
Consider a rod of length l that is perfectly insulated. We want to examine the flow
of heat along the rod over time.
The two ends of the rod are held at 0 deg C. We denote heat as temperature, and
seek the solution to the equation u(x, t): the temperature of x at time t > 0.
2
∂2u ∂2u
α2 (x, t) = (x, t)
∂x2 ∂t2
x2 y2
Again, note the similarity to the equation for a hyperbola: a2
− b2
= r.
An elastic string is stretched between two horizontal supports that are separated by
length l. The PDE defines vertical displacement of the string at time t. (We are
assuming that when we “pluck” the string, it only vibrates in one direction.)
4 Finite Differences
We approximate the solution to u(x, y) (and also u(x, t)) by only looking at the values
at only particular points in the problem space. This is done by constructing a grid.
Each point gi,j on the grid (implemented as a 2-dimensional array) represents the
approximation of u(xi , yj ) (and also u(xi , tj )).
We seek a solution to
∂2u ∂2u
∇2 u ≡ (x, y) + (x, y) = f (x, y)
∂x2 ∂y 2
where, a < x < b, c < y < d, and boundary values are defined by some function
g(x, y), over all ordered pairs (x, y) that denote the borders.
Choose integers n and m so that the interval [a, b] is partitioned into h equal parts, and
interval [c, d] is partitioned into k equal parts. h corresponds to a non-infinitessimal
δx), so the smaller the h(k) the better the approximation. (And similarly for k and
δy.)
xi = a + ih, 0 ≤ i ≤ n
yj = c + jk, 0 ≤ j ≤ m
3
The Taylor series expansion in the variable x about xi , with just the first term gives
the central-difference formula
Using these central difference formulas, the Poisson equation at the points (xi , yj )
becomes:
Using this Central Difference formula to calculate every inner grid point gi,j , (1 ≤ i ≤
n − 1 and 1 ≤ j ≤ m − 1) (which approximates the function u(xi , yj )) results in the
Central Difference Method:
" #
2 2
h h
2 + 1 gi,j − (gi+1,j + gi−1,j ) − (gi,j+1 + gi,j−1 ) = −h2 f (xi , yj )
k k
where gi,j is computed for every inner grid cell 1 ≤ i ≤ n − 1, 1 ≤ j ≤ m − 1. Hence
gi,j approximates the function u(xi , yj ).
The Taylor series expansion in t about tj , with just the first term is the formula
4
∂u u(xi , tj+1 ) − u(xi , tj )
(xi , tj ) =
∂t k
and in x about xi is
2α2 k
2 k
gi,j+1 = 1− gi,j + α (gi+1,j + gi−1,j )
h2 h2
This is known as the Forward Difference method. The initial conditions must be
defined for all x at t = 0. The Forward Difference method is conditionally stable only
k 1
when h and k are chosen so that α2 2 ≤
h 2
The Backward-Difference method is unconditionally stable. We use, instead, the
backward-difference formula for ∂u
∂t
:
The moral of the story: check first for stability before using Forward Differences.
5
5 Hyperbolic PDEs and 5-star Difference Equa-
tion
where λ = αk/h.
But the values at t = 1 is not a border value! To make a long story short, we use the
difference equation
λ2 λ2
gi,1 = (1 − λ2 )f (xi ) + f (xi+1 ) + f (xi−1 ) + kg(xi )
2 2
for gi,1 , 1 ≤ i ≤ m − 1 and hope for the best.
Jacobi iteration uses the values from the previous iteration l − 1 to compute the value
at the current iteration l.
6
(We assume h = k = 1 and ∇2 = 0.)
(gi,j )l = 0.25 (gi−1,j )l−1 + (gi+1,j )l−1 + (gi,j−1 )l−1 + (gi,j+1 )l−1
we see that, in iteration l, at g[i][j] we have already computed the values for g[i-1][j]l
and g[i][j-1]l . The values computed in iteration l are “better” than those computed
in iteration l − 1. Gauss-Seidel uses the “best” values:
SOR (Successive Over-Relaxation) takes Gauss-Seidel one step further. The idea is
that since the value gi,j in iteration l is better than value gi,j in iteration l − 1, give
additional weight to the value in iteration l. It’s basically a weighted average. Notice,
l
also, that SOR actually uses gi,j ; just plain Gauss-Seidel doesn’t.
7
0 < ω < 1 is the relaxation parameter. Typical values for ω range between 0.6 . . . 0.8.
(You will also see 1 < ω < 2, in which case the typical range is 1.25 . . . 1.80, and often
ω is 1.25. In this case you multiply the l − 1 value by (2 − ω) and divide the result
by 2).
2. Initialize the border points with the boundary values; initialize the inner points
to 0.
3. Perform either: Jacobi (see 6.1), Gauss-Seidel (see 6.2) or Gauss-Seidel with
SOR (see 6.3) iteration using the appropriate differences equation.
4. If this is a steady-state problem, iterate until, for a < i < b, c < j < d
l l−1
|(gi,j ) − (gi,j )| ≤ T OLERAN CE
8 Annotated Bibliography
Most of these are “old” books that I’ve accumulated over the years. One thing I’ve
found about old books is that they give warm-and-folksy explanations with lots of
pictures.
C. Ray Wylie and Louis CV. Barrett. Advanced Engineering Mathmatics. 5th Ed.
McGraw-Hill NY 1982. This text was used by the engineering students in GE’s Ad-
vanced Engineering Course.
8
Hugh Hildreth Skilling. Fundamentals of Electric Waves. John Wiley & Sons. 1942.
Yup, an oldie that I got years ago at a library book sale. It’s one of my warm-and-fuzzy
books. It gives such a wonderful explanation of pdes, and you realize that basically
everything can be thought of in terms of electricity.
Probably any numerical analysis or numerical methods book that discusses finite
differences.
The following figures graphically depict the various difference methods. Multiply each
value by the formula inside the square (should a formula exist).
Central Differences
j+1 λ
+ / +
j 1 2(λ+1) 1
λ
j−1
i−1 i i+1
Figure 1: Central Differences Method for Two-Dimensional Elliptic PDE
9
Forward Differences
j+1
+ +
+
j λ 1−2λ λ
i−1 i i+1
Figure 2: Forward Differences Method for One-Dimensional Parabolic PDE
10
Higher−Order Differences
j+1
+ +
+ +
2
j λ 2(1−λ2 ) λ2
−1
j−1
i−1 i i+1
Figure 3: Higher-Order Differences Method for One-Dimensional Hyperbolic PDE
11