HELM Workbook 33 Numerical Boundary Value Problems
HELM Workbook 33 Numerical Boundary Value Problems
Numerical
Boundary Value Problems
33.1 Two-point Boundary Value Problems 2
Learning outcomes
In this Workbook, which follows on from Workbook 32, you will see some more numerical
methods for approximating solutions of differential equations. The methods to be
presented in this Workbook are most usually applied in engineering examples involving
so-called boundary data, that is, some of the available information arises "around the
edges" of the problem area.
Two-point Boundary
Introduction
Boundary value problems arise in applications where some physical process involves knowledge of
information at the edges. For example, it may be possible to measure the electric potential around
the edge of a semi-conductor and then use this information to infer the potential distribution near
the middle.
In this Section we discuss numerical methods that can be used for certain boundary value problems
involving processes that may be modelled by an ordinary differential equation.
2 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
The first line is the differential equation, and the second and third lines are the boundary condi-
tions which can involve derivatives.
It is our aim to approximate the solution of this problem numerically, and we adopt an approach
similar to that seen in 32.
We divide the interval 0 < x < ` into a number, J say, of subintervals each of equal width h = `/J.
Our numerical solution will provide an approximation to y = y(x) at each value of x where two
subintervals meet (see Figure 1).
yJ
yJ−1
yj
y2
y1
y0
x
h 2h jh l−h l
x1 x2 xj xJ−1 xJ
Figure 1
Key Point 1
A numerical approximation to the boundary value problem
p(x)y 00 (x) + q(x)y 0 (x) + r(x)y(x) = s(x) (0 < x < `)
a0 y 0 (0) + b0 y(0) = c0
a1 y 0 (`) + b1 y(`) = c1
is a sequence of numbers y0 , y1 , y2 , y3 , . . . , yJ .
Here yj is an approximation to y(x) at x = jh, where h = `/J and j = 0, 1, 2, . . . , J.
It is useful to give a name to the x-values where we seek an approximation to y = y(x). Hence we
will sometimes write xj = jh j = 0, 1, 2, . . . , J.
The functions p, q, r and s will frequently occur evaluated at the values xj so it is convenient to
set up the following abbreviations:
pj = p(xj ), qj = q(xj ), rj = r(xj ), sj = s(xj ).
HELM (2008): 3
Section 33.1: Two-point Boundary Value Problems
A numerical approximation to Equations (1) can be found by approximating the derivatives by finite
differences. Here we will approximate y 00 (x) and y 0 (x) by central differences to obtain
This last equation can be rearranged, gathering together all the like y-terms. It neatens things further
to multiply through by h2 as well, and the result of these manipulations appears in the following Key
Point.
Key Point 2
A central difference approximation to
p(x)y 00 (x) + q(x)y 0 (x) + r(x)y(x) = s(x)
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
This approximation to the differential equation can be thought of as a three-point stencil linking
three of the approximate y-values. The expression
h h
yj−1 pj − qj + yj h rj − 2pj + yj+1 pj + qj = h2 sj .
2
2 2
is centred around x = xj and involves yj−1 , yj and yj+1 . The general rule when dealing with a
numerical stencil like this is to centre the stencil at every point where y is unknown. (This
general rule will appear again, for example on page 13.)
4 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Key Point 3
Centre the stencil at every x-point where y is unknown. This will give a set of equations for the
unknown y-values, and we are guaranteed exactly as many equations as there are unknowns.
In the following Example, matters are simplified because the functions p, q, r and s are all constant.
Example 1
Let y = y(x) be a solution to the boundary value problem
3y 00 (x) + 4y 0 (x) + 5y(x) = 7 0 < x < 1.5
y(0) = 2, y(1.5) = 2.
Using a mesh width of h = 0.5, obtain a central difference approximation to the
differential equation and hence find yj ≈ y(jh), j = 1, 2.
Solution
In general, the central difference approximation to
p(x)y 00 (x) + q(x)y 0 (x) + r(x)y(x) = s(x)
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
In this case the coefficients are
h h
pj − qj = 2, h2 rj − 2pj = −4.75, pj + qj = 4, h2 sj = 1.75.
2 2
These values will be the same for all x because p, q, r and s are constants in this Example. Hence
the general stencil is
2yj−1 − 4.75yj + 4yj+1 = 1.75
In this case h = 0.5, and our numerical solution consists of the values
HELM (2008): 5
Section 33.1: Two-point Boundary Value Problems
Solution (contd.)
So there are two unknowns, y1 and y2 . We centre the stencil at each of the corresponding x values.
Putting j = 1 in the numerical stencil gives
2y0 − 4.75y1 + 4y2 = 1.75
Moving the stencil one place to the right, we put j = 2 so that
2y1 − 4.75y2 + 4y3 = 1.75
In these two equations y0 and y3 are known from the boundary conditions and we move terms
involving them to the right-hand side. This leads to the system of equations
−4.75 4 y1 −2.25
=
2 −4.75 y2 −6.25
Solving this pair of simultaneous equations we find that
y1 = 2.45, y2 = 2.35
to 2 decimal places.
This approximation is shown in Figure 2 in which the numerical approximations to point values of y
are shown as circles.
2.5
2.4
2.3
2.2
2.1
2
0 0.5 1 1.5
x
Figure 2
The question remains how close to the exact solution these approximations are. (Of course for
Example 1 above it is possible to find the analytic solution fairly easily, but this will not usually be
the case.)
A pragmatic way to deal with this question is to recompute the results with a smaller value of h. We
know from 31 that the central difference approximations get closer and closer to the derivatives
which they approximate as h decreases. In Figure 3 the results for h = 0.5 are given again as circles,
and a computer has been used to find more accurate approximations to y using h = 1.5 7
(shown as
1.5
squares) and yet more accurate results (shown as dots) from using h = 10 . (This involves solving
larger systems of equations than are manageable by hand. The methods seen in 30 can be
used to deal with these larger systems.)
6 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
2.5
3 subintervals
7 subintervals
2.4 10 subintervals
2.3
2.2
2.1
2
0 0.5 1 1.5
x
Figure 3
We can now have some confidence that the results we calculated using h = 0.5 tended to overestimate
the true values of y.
Example 2
Let y = y(x) be a solution to the boundary value problem
y 00 (x) + 2y 0 (x) − 2y(x) = −3 0<x<2
y(0) = 1, y(2) = −2.
Using a mesh width of h = 0.5 obtain a central difference approximation to
the differential equation and hence find simultaneous equations satisfied by the
unknowns y1 , y2 and y3 .
Solution
In this case the coefficients are
h h
pj − qj = 0.5, h2 rj − 2pj = −2.5, pj + qj = 1.5, h2 sj = −0.75.
2 2
These values will be the same for all x because p, q, r and s are constants in this Example.
Hence the general stencil is
0.5yj−1 − 2.5yj + 1.5yj+1 = −3
Here we have h = 0.5 and our numerical solution consists of the values
HELM (2008): 7
Section 33.1: Two-point Boundary Value Problems
Solution (contd.)
So there are three unknowns, y1 , y2 and y3 . We centre the stencil at each of the corresponding x
values. Putting j = 1 in the numerical stencil gives
0.5y0 − 2.5y1 + 1.5y2 = −0.75.
Moving the stencil one place to the right, we put j = 2 so that
0.5y1 − 2.5y2 + 1.5y3 = −0.75
and finally we let j = 3 so that
0.5y2 − 2.5y3 + 1.5y4 = −0.75
In these three equations y0 and y4 are known from the boundary conditions and we move terms
involving them to the right-hand side. This leads to the system of equations
−2.5 1.5 0 y1 −1.25
0.5 −2.5 1.5 y2 = −0.75
0 0.5 −2.5 y3 2.25
We can find (using methods from 30, for example) that the solution to the system of equations
in Example 2 is
y1 = 0.39 y2 = −0.18 y3 = −0.94 to 2 decimal places.
Task
Let y = y(x) be a solution to the boundary value problem
y 00 (x) + 4y 0 (x) = 4 0<x<1
y(0) = −2, y(1) = 3.
Using a mesh width of h = 0.25 obtain a central difference approximation to the
differential equation and hence find a system of equations satisfied by yj ≈ y(jh),
j = 1, 2, 3.
Your solution
Work the solution on a separate piece of paper. Record the main results and your conclusions here.
8 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Answer
In general, the central difference approximation to
p(x)y 00 (x) + q(x)y 0 (x) + r(x)y(x) = s(x)
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
In this case the coefficients are
h h
pj − qj = 0.5, h2 rj − 2pj = −2, pj + qj = 1.5, h2 sj = 0.25.
2 2
These values will be the same for all x because p, q, r and s are constants in this Example.
In this case h = 0.25 and our numerical solution consists of the values
So there are three unknowns, y1 , y2 and y3 . We centre the stencil at each of the corresponding x
values. Putting j = 1 in the numerical stencil gives
0.5y0 − 2y1 + 1.5 = 0.25
Moving the stencil one place to the right, we put j = 2 so that
0.5y1 − 2y2 + 1.5 = 0.25
and finally we let j = 3 so that
0.5y2 − 2y3 + 1.5 = 0.25
In these three equations y0 and y4 are known from the boundary conditions and we move terms
involving them to the right-hand side. This leads to the system of equations
−2 1.5 0 y1 1.25
0.5 −2 1.5 y2 = 0.25
0 0.5 −2 y3 −4.25
(And you might like to check that the solution to this system of equations is y1 = 0.95, y2 = 2.1
and y3 = 2.65.)
HELM (2008): 9
Section 33.1: Two-point Boundary Value Problems
Example 3
The temperature y of an electrically heated wire of length ` is affected by local air
currents. This situation may be modelled by
d2 y
= −a − b(Y − y), (0 < x < `).
dx2
Consider the case where ` = 3, a = 50, b = 0.1 and Y = 20◦ C and suppose
that the ends of the wire are known (to 1 decimal place) to be at temperatures
y(0) = 15.0◦ C and y(3) = 25.0◦ C.
Using a central difference to approximate the derivative and using 3 subintervals
obtain approximations to the temperature 13 and 23 of the length along the wire.
Solution
This Example falls into the general case given at the beginning of this Section if we choose p = 1,
q = 0, r = −0.1 and s = −52. In this case h = 1 and our numerical solution consists of the values
So there are two unknowns, y1 and y2 . We centre the stencil at each of the corresponding x values.
Putting j = 1 in the numerical stencil gives
y0 − 2.1y1 + y2 = −52
Moving the stencil one place to the right, we put j = 2 so that
y1 − 2.1y2 + y3 = −52
In these two equations y0 and y3 are known from the boundary conditions and we move terms
involving them to the right-hand side. This leads to the system of equations
−2.1 1 y1 −67
=
1 −2.1 y2 −77
Solving this pair of simultaneous equations we find that
y1 = 63.8, y2 = 67.1
to 1 decimal place.
We conclude that the temperature 31 of the wire’s length from the cooler end is approximately 63.8◦ C
and the temperature the same distance from the hotter end is approximately 67.1◦ C, where we have
rounded these numbers to the same number of places as the given boundary conditions.
The Examples and Task above were such that p, q, r and s were each equal to a constant for all
values of x. More realistic engineering applications may involve coefficients that vary, and the next
Example is of this type.
10 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Example 4
Let y = y(x) be a solution to the boundary value problem
ln(2 + x)y 00 (x) + xy 0 (x) + (x + 1)2 y(x) = cos(x) 0 < x < 1.2
y(0) = 0, y(1.2) = 2.
Using a mesh width of h = 0.4 obtain a central difference approximation to the
differential equation and hence find yj ≈ y(jh), j = 1, 2.
Solution
In general, the central difference approximation to
p(x)y 00 (x) + q(x)y 0 (x) + r(x)y(x) = s(x)
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
The coefficients will vary with j in this Example because the functions p, q, r and s are not all
constants. In this case h = 0.4 and our numerical solution consists of the values
So there are two unknowns, y1 and y2 . We centre the stencil at each of the corresponding x values.
Putting j = 1 in the numerical stencil gives
0.795469y0 − 1.437337y1 + 0.955469y2 = 0.147370
Moving the stencil one place to the right, we put j = 2 so that
0.869619y1 − 1.540839y2 + 1.189619y3 = 0.111473
In these two equations y0 and y3 are known from the boundary conditions and we move terms
involving them to the right-hand side. This gives the pair of equations
−1.437337 0.955469 y1 0.147370
=
0.869619 −1.540839 y2 −2.267766
Solving this pair of simultaneous equations we find that
y1 = 1.40, y2 = 2.26
to 2 decimal places.
HELM (2008): 11
Section 33.1: Two-point Boundary Value Problems
Once again we can monitor the accuracy of the results obtained in the Example above by recomputing
for a smaller value of h. In Figure 4 the values calculated are shown as circles and a computer has
been used to obtain the more accurate results (shown as dots) obtained from choosing h = 1.220
.
2.5
1.5
1
3 subintervals
20 subintervals
0.5
0
0.2 0.4 0.6 0.8 1 1.2
x
Figure 4
In the next Example we see that the derivative y 0 appears in the boundary condition at x = 0. This
means that y is not given at x = 0 and we use the general rule given earlier in Key Point 3:
So this implies that we must centre the stencil at x = 0 and this will cause the value y−1 to appear.
This is a fictitious value that plays no part in the solution we seek and we use the derivative boundary
condition to get y−1 in terms of y1 . This is done with the central difference
y1 − y−1
y 0 (0) ≈ .
2h
The following Example implements this idea.
Example 5
Let y = y(x) be a solution to the boundary value problem
ln(2 + x)y 00 (x) + xy 0 (x) + 2y(x) = cos(x) 0 < x < 1.2
y 0 (0) = −1, y(1.2) = 2
(Note the derivative boundary condition at x = 0.)
Using a mesh width of h = 0.4 obtain a central difference approximation to the
differential equation and hence find the system of equations satisfied by yj ≈ y(jh),
j = 0, 1, 2.
12 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Solution
In general, the central difference approximation to
p(x)y 00 (x) + q(x)y 0 (x) + r(x)y(x) = s(x)
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
The coefficients vary with j in this Example because the functions p, q, r and s are not all constants.
In this case h = 0.4 and our numerical solution consists of the values
So there are three unknowns, y0 , y1 and y2 . We centre the stencil at each of the corresponding x
values. Putting j = 0 in the numerical stencil gives
0.693147y−1 − 1.066294y0 + 0.6931472y1 = 0.16
which introduces the fictitious quantity y−1 . We attach a meaning to y−1 on using the boundary
condition at x = 0. Approximating the derivative in the boundary condition by a central difference
gives
y1 − y−1
= −1 ⇒ y−1 = y1 + 0.8
2h
and we use this to remove y−1 from the equation where it first appeared. Hence
−1.066294y0 + 1.386294y1 = 0.7145177
The remaining steps are similar to previous Examples. Putting j = 1 in the stencil gives
0.795469y0 − 1.430937y1 + 0.955469y2 = 0.147370.
Moving the stencil one place to the right, we put j = 2 so that
0.869619y1 − 1.739239y2 + 1.189619y3 = 0.111473
In the last equation y3 is known from the boundary conditions and we move the term involving it
to the right-hand side. This leaves us with the system of equations
−1.066294 1.386294 0 y0 0.714518
0.795469 −1.430937 0.955469 y1 = 0.147370
0 0.869619 −1.739239 y2 −2.267766
where the components are given to 6 decimal places.
HELM (2008): 13
Section 33.1: Two-point Boundary Value Problems
Exercises
1. Let y = y(x) be a solution to the boundary value problem
y(0) = 2, y(0.75) = 1
Using a mesh width of h = 0.25 obtain a central difference approximation to the differential
equation and hence find y1 ≈ y(0.25) and y2 ≈ y(0.5).
Using a mesh width of h = 0.3 obtain a central difference approximation to the differential
equation and hence find a system of equations satisfied by y1 ≈ y(0.3), y2 ≈ y(0.6) and
y3 ≈ y(0.9).
Using a mesh width of h = 0.5 obtain a central difference approximation to the differential
equation and hence find the system of equations satisfied by yj ≈ y(jh), j = 0, 1, 2.
14 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Answers
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
So there are two unknowns, y1 and y2 . We centre the stencil at each of the corresponding x
values. Putting j = 1 in the numerical stencil gives
In these two equations y0 and y3 are known from the boundary conditions and we move terms
involving them to the right-hand side. This leads to the system of equations
−1.8125 0.75 y1 −2.125
=
1.25 −1.8125 y2 −0.375
with solution
y1 = 1.76, y2 = 1.42
to 2 decimal places.
HELM (2008): 15
Section 33.1: Two-point Boundary Value Problems
Answers
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
So there are three unknowns, y1 , y2 and y3 . We centre the stencil at each of the corresponding
x values. Putting j = 1 in the numerical stencil gives
In these three equations y0 and y4 are known from the boundary conditions and we move
terms involving them to the right-hand side. This leads to the system of equations
−4 2.45 0 y1 3.55
1.55 −4 2.45 y2 = 0.45
0 1.55 −4 y3 −6.9
16 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Answers
is
h
2
h
yj−1 p j − qj + yj h rj − 2pj + yj+1 p j + qj = h2 sj .
2 2
The coefficients vary with j in this exercise because the functions p, q, r and s are not all
constants. In this case h = 0.5 and our numerical solution consists of the values
So there are three unknowns, y0 , y1 and y2 . We centre the stencil at each of the corresponding
x values. Putting j = 0 in the numerical stencil gives
y−1 − 1.25y0 + y1 = 0
which introduces the fictitious quantity y−1 . We attach a meaning to y−1 on using the
boundary condition at x = 0. Approximating the derivative in the boundary condition by a
central difference gives
y1 − y−1
=2 ⇒ y−1 = y1 − 2
2h
and we use this to remove y−1 from the equation where it first appeared. Hence
−1.25y0 + 2y1 = −2
The remaining steps are similar to previous exercises. Putting j = 1 in the stencil gives
In the last equation y3 is known from the boundary conditions and we move the term involving
it to the right-hand side. This leads to the system of equations
−1.25 2 0 y0 −2
0.9375 −1.25 1.0625 y1 = 0.125
0 0.75 −1.25 y2 −1
HELM (2008): 17
Section 33.1: Two-point Boundary Value Problems
Introduction
In 32.4 and 32.5, we saw methods of obtaining numerical solutions to Parabolic and Hyperbolic
partial differential equations (PDEs). Another class of PDEs are the Elliptic type, and these usually
model time-independent situations. In this Section we will concentrate on two particularly important
Elliptic type PDEs: Laplace’s equation and Poisson’s equation.
' $
• familiarise yourself with difference methods
for approximating second derivatives (
Prerequisites 31.3 )
Before starting this Section you should . . . • revise the Jacobi and Gauss-Seidel methods
from ( 30.5)
&
%
18 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
1. Elliptic equations
Consider a region R (for example, a rectangle) in the xy-plane. We might pose the following boundary
value problem
uxx + uyy = f (x, y) a given function, in R
u = g a given function, on the boundary of R
• if f = 0 everywhere, then the PDE is called Laplace’s equation
• if f is non-zero somewhere in R then the PDE is called Poisson’s equation
Laplace’s equation models a huge range of physical situations. It is used by coastal engineers to
approximate the motion of the sea; it is used to model electric potential; it can give an approximation
to heat distribution in certain steady state problems. The list goes on and on. The generalisation
to Poisson’s equation opens up further application areas, but for our purposes in this Section we will
concentrate on how to solve the equation, rather than on how it is applied.
Key Point 4
In deriving numerical solutions to elliptic PDEs we use equal steps in the x and y directions. That
is, we take
δx = δy = h (say)
HELM (2008): 19
Section 33.2: Elliptic PDEs
Key Point 5
We use subscripts on u to relate to space variables. For Elliptic PDEs both of the independent
variables measure distance and so we have two subscripts.
Key Point 6
If there is no danger of ambiguity we may omit the comma from the subscript. That is,
ui,j may be written uij and fi,j may be written fij
Given all of this preamble we can now write down a difference equation which approximates the
partial differential equation:
ui+1,j − 2ui,j + ui−1,j ui,j+1 − 2ui,j + ui,j−1
2
+ 2
= fi,j
| h
{z } | h
{z }
↑
≈ uxx ≈ uyy notation for f (ih, jh)
Rearranging this gives
−4ui,j + ui+1,j + ui−1,j + ui,j+1 + ui,j−1 = h2 fi,j
This equation defines a five-point stencil approximating the PDE. The following diagram shows
the stencil.
ui,j+1
j+1
j−1
ui,j−1
j−2
i−1 i i+1
The idea in an implementation of this stencil is to centre the cross-shape on each i, j node where we
want to find u. This guarantees that we will end up with the same number of equations as unknowns.
An example of this approach will follow shortly, but first we note other ways of writing down the
five-point stencil.
20 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
As the diagram above shows, the stencil involves a centre point and four additional points each
corresponding to one of the points of the compass. It is this observation which has led to a simplified
version of the mathematical expression and the diagram. The symbolic stencil can be written
−4u0 + uE + uW + uN + uS = h2 f0 ,
where a subscript 0 corresponds to the centre of the stencil and other subscripts correspond to
compass points (North, South, East, West) in the obvious way. The diagram becomes
uN
uW u0 uE
uS
and we reinterpret the local “0, N, S, E, W ” positions each time we move the stencil on the global
grid.
Another way of writing the stencil is as follows:
1 −4 1
1
This latest version has the advantage of showing the values of the coefficients used in approximating
uxx + uyy .
We summarise in Key Point 7 the main idea using the notation established above.
Key Point 7
The five-point stencil used to approximate the partial differential equation
uxx + uyy = f (x, y)
gives rise to the difference equation
−4u0 + uE + uW + uN + uS = h2 f0
HELM (2008): 21
Section 33.2: Elliptic PDEs
Example 6
Consider the boundary value problem
uxx + uyy = 0 in the square 0 < x < 1, 0 < y < 1
u = x2 y on the boundary.
1
Use h = 3
and formulate a system of simultaneous equations for the 4 unknowns.
Solution
0 0 0 0 → x
The numerical stencil in this case is −4u0 + uE + uW + uN + uS = 0 and we centre this at each
of the places where u is sought. There are four such places in this example:
bottom left: −4u11 + u21 + 0 + u12 + 0 = 0
1
bottom right: −4u21 + 3
+ u11 + u22 + 0 = 0
1
top left: −4u12 + u22 + 0 + 9
+ u11 = 0
2 4
top right: −4u22 + 3
+ u12 + 9
+ u21 = 0
↑ ↑ ↑ ↑ ↑
Centre East West North South
This is a system of equations in the four unknowns which may be written
−4 1 1 0 u11 0
1
1 −4 0 1 u21
3
= −
1
1
0 −4 1 u12
9
10
0 1 1 −4 u22 9
It is now a (simple, in theory) matter of solving the system to obtain the numerical approximation
to u.
22 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
1 7 5
It turns out that the solution to the system of equations is u11 = 12 , u21 = 36 , u12 = 36 and
13
u22 = 36 . These values are, to four decimal places, 0.0833, 0.1944, 0.1389 and 0.3611, respectively.
We will say more later about how to solve the system of equations, but first there is a Task to help
consolidate what we have covered so far.
Task
Consider the boundary value problem
Use h = 13 and hence formulate a system of simultaneous equations for the four
unknowns.
Your solution
HELM (2008): 23
Section 33.2: Elliptic PDEs
Answer
0 0 0 0 → x
The numerical stencil in this case is
1 2
−4u0 + uE + uW + uN + uS = h2 f0 = ( )2 × (−2) = −
3 9
and we centre this at each of the places where u is sought. In this Example there are four such
places:
bottom left: −4u11 + u21 + 0 + u12 + 0 = − 92
1
bottom right: −4u21 + 3
+ u11 + u22 + 0 = − 29
1
top left: −4u12 + u22 + 0 + 3
+ u11 = − 92
2 2
top right: −4u22 + 3
+ u12 + 3
+ u21 = − 92
↑ ↑ ↑ ↑ ↑
Centre East West North South
This is a system of equations in the four unknowns and it may be written
2
−4 1 1 0 u11 9
5
1 −4 0 1 u21
9
= −
5
1
0 −4 1 u12
9
14
0 1 1 −4 u22 9
24 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
3. Systems of equations
In order to obtain accurate results over a large number of interior points, we need to decrease h
compared to the values used in the Examples above.
The diagram below shows a case where 5 steps are used in each direction on a square domain. It
follows that there will be 4 × 4 = 16 unknowns. Positioning the stencil over each xy position where u
is unknown will give the right number of equations, and the order we take the 16 points is indicated
by the arrows on the diagram.
x
It follows that there will be a system of equations involving
−4
0 10 1
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 u11
B CB C
−4
B CB C
B
B 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 CB
CB u21 C
C
B CB C
−4
B CB C
B 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 CB u31 C
B CB C
B CB C
−4
B
0 0 1 1 0 0 1 0 0 0 0 0 0 0 0
CB
u41 C
C
B CB
B CB C
B CB C
1 0 0 1 −4 1 0 0 1 0 0 0 0 0 0 0 u12 C
B CB C
B CB
B CB C
B CB C
0 1 0 0 1 −4 1 0 0 1 0 0 0 0 0 0 u22 C
B CB C
B CB
B CB C
B CB C
0 0 1 0 0 1 −4 1 0 0 1 0 0 0 0 0 u32 C
B CB C
B CB
B CB C
B CB C
0 0 0 1 0 0 1 −4 1 0 0 1 0 0 0 0 u42 C
B CB C
B CB
C = ...
B CB C
B CB
0 0 0 0 1 0 0 1 −4 1 0 0 1 0 0 0 u13 C
B CB C
B CB
B CB C
B CB C
B 0 0 0 0 0 1 0 0 1 −4 1 0 0 1 0 0 CB u23 C
C
B CB
B CB C
B CB C
B
B 0 0 0 0 0 0 1 0 0 1 −4 1 0 0 1 0 CB
CB u33 C
C
B CB C
B CB C
B
B 0 0 0 0 0 0 0 1 0 0 1 −4 1 0 0 1 CB
CB u43 C
C
B CB C
B CB C
B
B 0 0 0 0 0 0 0 0 1 0 0 1 −4 1 0 0 CB
CB u14 C
C
B CB C
B CB C
B
B 0 0 0 0 0 0 0 0 0 1 0 0 1 −4 1 0 CB
CB u24 C
C
B CB C
B CB C
B
B 0 0 0 0 0 0 0 0 0 0 1 0 0 1 −4 1 CB
CB u34 C
C
@ A@ A
0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 −4 u44
with a right-hand side that depends on the function f and the boundary conditions.
There is a great deal of structure in this matrix. Most of the elements are zero. Apart from that there
are five non-zero diagonal bands (from top-left to bottom-right), each corresponding to a component
of the five-point stencil. The main diagonal is made up of repetitions of −4, the coefficient from the
centre of the 5-point stencil. Immediately above and below the main diagonal are terms that come
from the easterly and westerly extremes of the stencil, respectively. Separated from the tridiagonal
band are two outlying lines of 1s. The uppermost sequence of 1s is due to the northerly point on the
stencil and the lowermost is a consequence of the southerly point.
HELM (2008): 25
Section 33.2: Elliptic PDEs
It is worth noting that much of this structure failed to emerge in the numerical examples considered
earlier. This was because the mesh was so coarse (that is, h was so large) that the stencil was
always in touch with the boundary. It is more usual that most placings of the stencil will produce an
equation involving five unknowns.
In general, then, an implementation of the five-point stencil will ultimately involve having to solve a
potentially large number of simultaneous equations. We have seen in 30 methods for dealing
with systems of equations, for example we saw the Jacobi and Gauss-Seidel iterative methods. It is
possible, in the present application, to implement these methods directly via the numerical stencil.
The next subsection describes how this may be achieved.
4. Iterative methods
An implementation of the five-point stencil
−4u0 + uE + uW + uS + uN = h2 f0
leads to a system of simultaneous equations in the unknowns. This system of equations can be dealt
with using methods seen in 30, but here we show ways in which systematic iterative methods
can be derived directly from the numerical stencil.
The general approach is as follows:
1. Start with an initial guess for the unknowns. Call this initial guess u0i,j .
2. Use some means to improve the guess. Call the improvement u1i,j .
Jacobi iteration
The approach we adopt here is to update the approximation at the centre of the stencil using the
four old values around the edge of the stencil. That is
−4un+1
0 + unE + unW + unS + unN = h2 f0
rearranging this gives
1 n
un+1 uE + unW + unS + unN − h2 f0
0 =
4
The following Example uses the same data (rounded to four decimal places here) as in Example 6.
26 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Example 7
Suppose that u = u(x, y) satisfies Laplace’s equation
uxx + uyy = 0
in the square region 0 < x, y < 1 with u = x2 y on the boundary. Assuming
a mesh size of h = 13 use the Jacobi iteration, with starting values u0ij = 0, to
perform two iterations. The boundary data are as given in the schematic below.
y↑
0.0000 0.1111 0.4444 1.0000
0.0000 u12 u22 0.6667
0.0000 u11 u21 0.3333
0.0000 0.0000 0.0000 0.0000 → x
Solution
Putting in the initial guesses for the four unknowns u11 , u12 , u21 , u22 we obtain the situation depicted
below.
y↑
0.0000 0.1111 0.4444 1.0000
0.0000 0 0 0.6667
0.0000 0 0 0.3333
0.0000 0.0000 0.0000 0.0000 → x
The first iteration involves using
4u10 = u0E + u0W + u0N + u0S − h2 f0
where, in this case, h2 f0 = 0. So the first iteration gives us
u111 = 0.0000 u121 = 0.0833 u112 = 0.0278 u122 = 0.2778
The second iteration begins by putting these new approximations to the interior values into the grid.
This gives
y↑
0.0000 0.1111 0.4444 1.0000
0.0000 0.0278 0.2778 0.6667
0.0000 0.0000 0.0833 0.3333
0.0000 0.0000 0.0000 0.0000 → x
We now apply 4u20 = u1E + u1W + u1N + u1S to obtain
u211 = 0.0278 u221 = 0.1528 u212 = 0.0972 u222 = 0.3056
HELM (2008): 27
Section 33.2: Elliptic PDEs
In practice, using a computer to carry out the arithmetic, we would continue iterating until the results
settle down to a converged value. Using a computer spreadsheet, for example, we can see that a
total of 15 iterations is enough to achieve results converged to four decimal places. We noted earlier
that, to four decimal places, u11 = 0.0833, u21 = 0.1944, u12 = 0.1389 and u22 = 0.3611.
The following Task uses the same data as the preceding Task (pages 23-24), except that we have
rounded the boundary data to four decimal places instead of using the exact fractions.
Task
Suppose that u = u(x, y) satisfies Poisson’s equation
uxx + uyy = −2
in the square region 0 < x, y < 1 with u = xy on the boundary. Assuming a mesh
size of h = 31 use the Jacobi iteration, with starting values u0ij = 0, to perform
two iterations. The boundary data are as given in the schematic below.
y↑
0.0000 0.3333 0.6667 1.0000
0.0000 u12 u22 0.6667
0.0000 u11 u21 0.3333
0.0000 0.0000 0.0000 0.0000 → x
Your solution
First iteration:
Answer
Putting in the initial guesses for the four unknowns we obtain the situation depicted below.
y↑
0.0000 0.3333 0.6667 1.0000
0.0000 0 0 0.6667
0.0000 0 0 0.3333
0.0000 0.0000 0.0000 0.0000 → x
The first iteration involves using
4u10 = u0E + u0W + u0N + u0S − h2 f0
where in this case h2 f0 = −0.2222. So the first iteration gives us
u111 = 0.0556 u121 = 0.1389 u112 = 0.1389 u122 = 0.3889
28 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Your solution
Second iteration:
Answer
The second iteration begins by putting these new approximations to the interior values into the grid.
This gives
y↑
0.0000 0.3333 0.6667 1.0000
0.0000 0.1389 0.3889 0.6667
0.0000 0.0556 0.1389 0.3333
0.0000 0.0000 0.0000 0.0000 → x
We now perform the second iteration 4u20 = u1E + u1W + u1N + u1S − h2 f0 again, but with the new
values. We obtain
u211 = 0.1250
u221 = 0.2500
u212 = 0.2500
u222 = 0.4583
In the case above 17 iterations are required to achieve results that have converged to 4 decimal
places. We find that u11 = 0.2222, u12 = 0.3333, u21 = 0.3333 and u22 = 0.5556.
Gauss-Seidel iteration
In the implementation of the Jacobi method we used old values for the southerly and westerly points
when new values had already been calculated.
new values
already found
HELM (2008): 29
Section 33.2: Elliptic PDEs
The Gauss-Seidel method uses the new values as soon as they are available. Stating this formally we
have
Example 8
Suppose that u = u(x, y) satisfies Laplace’s equation
uxx + uyy = 0
in the square region 0 < x, y < 1 with u = x2 y on the boundary. Assuming a
mesh size of h = 31 , use the Gauss-Seidel iteration, with starting values u0ij = 0, to
perform two iterations. The boundary data are as given in the schematic below.
y↑
0.0000 0.1111 0.4444 1.0000
0.0000 u12 u22 0.6667
0.0000 u11 u21 0.3333
0.0000 0.0000 0.0000 0.0000 → x
Solution
Putting in the initial guesses for the four unknowns we obtain the situation depicted below.
y↑
0.0000 0.1111 0.4444 1.0000
0.0000 0 0 0.6667
0.0000 0 0 0.3333
0.0000 0.0000 0.0000 0.0000 → x
The first iteration involves using
4u10 = u0E + u1W + u0N + u1S − h2 f0
where in this case h2 f0 = 0. So the first iteration gives us
u111 = 0.0000
u121 = 0.0833
u112 = 0.0278
u122 = 0.3056
30 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Solution (contd.)
The second iteration begins by putting these new approximations to the interior values into the grid.
This gives
y↑
0.0000 0.1111 0.4444 1.0000
0.0000 0.0278 0.3056 0.6667
0.0000 0.0000 0.0833 0.3333
0.0000 0.0000 0.0000 0.0000 → x
We now apply 4u20 = u1E + u2W + u1N + u2S − h2 f0 to obtain
u211 = 0.0278 u221 = 0.1667 u212 = 0.1111 u222 = 0.3472
(And, using a computer spreadsheet, for example, we can see that a total of 7 iterations is enough to
achieve results converged to four decimal places. This compares well with the 15 iterations required
by Jacobi in Example 7.)
Task
Suppose that u = u(x, y) satisfies Poisson’s equation
uxx + uyy = −2
in the square region 0 < x, y < 1 with u = xy on the boundary. Assuming a
mesh size of h = 13 use the Gauss-Seidel iteration, with starting values u0ij = 0, to
perform two iterations. The boundary data are as given in the schematic below.
y↑
0.0000 0.3333 0.6667 1.0000
0.0000 u12 u22 0.6667
0.0000 u11 u21 0.3333
0.0000 0.0000 0.0000 0.0000 → x
Your solution
First iteration:
HELM (2008): 31
Section 33.2: Elliptic PDEs
Answer
Putting in the initial guesses for the four unknowns we obtain the situation depicted below.
y↑
0.0000 0.3333 0.6667 1.0000
0.0000 0 0 0.6667
0.0000 0 0 0.3333
0.0000 0.0000 0.0000 0.0000 → x
The first iteration involves using
4u10 = u0E + u1W + u0N + u1S − h2 f0
where in this case h2 f0 = −0.2222. We need to take care so as to use new values as soon as they
are available So the first iteration gives us
u111 = 0.0556
u121 = 0.1528 using the new u11 approximation
u112 = 0.1528 using the new u11 approximation
u122 = 0.4653 using the new u12 and u21 approximations
Your solution
Second iteration:
32 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Answer
The second iteration begins by putting these new approximations to the interior values into the grid.
This gives
y↑
0.0000 0.3333 0.6667 1.0000
0.0000 0.1528 0.4653 0.6667
0.0000 0.0556 0.1528 0.3333
0.0000 0.0000 0.0000 0.0000 → x
We now apply 4u20 = u1E + u2W + u1N + u2S − h2 f0 again, but with the new values. We obtain
u211 = 0.1319
u221 = 0.2882 using the new u11 approximation
u212 = 0.2882 using the new u11 approximation
u222 = 0.5330 using the new u12 and u21 approximations
Again, a computer can be used to continue iterating until convergence. This method applied to this
Task needs 8 iterations to achieve 4 decimal place convergence, a fact which compares very well with
the 17 required by the Jacobi method.
Convergence
We now summarise some important points
1. For the problems discussed in these pages, the Jacobi and Gauss-Seidel methods will always
converge for any initial guesses u0ij . (Of course, very poor initial guesses will result in more
iterations being required.)
2. For a given problem and given starting guesses u0ij , the Gauss-Seidel method will, in general,
converge in fewer iterations than Jacobi. (That is, using the new, improved values as
soon as they are available speeds up the process.)
3. One possible advantage with the Jacobi approach is that it can be parallelised, that is, it is in
theory possible to do all the calculations for a given iteration simultaneously. In other words,
everything we will need to know to carry out an iteration is known before the iteration begins.
This is not the case with Gauss-Seidel in which during an iteration, most calculations use a
result from within the current iteration. This advantage with Jacobi only manifests itself when
using computers with a parallelisation option and for large problems.
HELM (2008): 33
Section 33.2: Elliptic PDEs
Exercises
1. Suppose that u = u(x, y) satisfies Laplace’s equation
uxx + uyy = 0
in the square region 0 < x, y < 1. Assuming a mesh size of h = 13 use the Jacobi iteration,
with starting values u0ij = 0, to perform two iterations. The boundary data are as given in the
schematic below:
y↑
0.0000 0.2500 0.7500 1.0000
0.4000 u12 u22 0.8000
0.8000 u11 u21 0.4000
0.0000 0.7500 0.2500 0.0000 → x
uxx + uyy = 0
in the square region 0 < x, y < 1. Assuming a mesh size of h = 31 use the Gauss-Seidel
iteration, with starting values u0ij = 0, to perform two iterations. The boundary data are as
given in the schematic below.
y↑
0.0000 0.2500 0.7500 1.0000
0.4000 u12 u22 0.8000
0.8000 u11 u21 0.4000
0.0000 0.7500 0.2500 0.0000 → x
34 HELM (2008):
Workbook 33: Numerical Boundary Value Problems
®
Answers
1. Putting in the initial guesses for the four unknowns we obtain the situation depicted below.
y↑
0.0000 0.2500 0.7500 1.0000
0.4000 0 0 0.8000
0.8000 0 0 0.4000
0.0000 0.7500 0.2500 0.0000 → x
u111 = 0.3875
u121 = 0.1625
u112 = 0.1625
u122 = 0.3875
The second iteration begins by putting these new approximations to the interior values into
the grid. This gives
y↑
0.0000 0.2500 0.7500 1.0000
0.4000 0.1625 0.3875 0.8000
0.8000 0.3875 0.1625 0.4000
0.0000 0.7500 0.2500 0.0000 → x
u211 = 0.4688
u221 = 0.3563
u212 = 0.3563
u222 = 0.4688
HELM (2008): 35
Section 33.2: Elliptic PDEs
Answers
2. Putting in the initial guesses for the four unknowns we obtain the situation depicted below.
y↑
0.0000 0.2500 0.7500 1.0000
0.4000 0 0 0.8000
0.8000 0 0 0.4000
0.0000 0.7500 0.2500 0.0000 → x
u111 = 0.3875
u121 = 0.2594
u112 = 0.2594
u122 = 0.5172
The second iteration begins by putting these new approximations to the interior values into
the grid. This gives
y↑
0.0000 0.2500 0.7500 1.0000
0.4000 0.2594 0.5172 0.8000
0.8000 0.3875 0.2594 0.4000
0.0000 0.7500 0.2500 0.0000 → x
u211 = 0.5172
u221 = 0.4211
u212 = 0.4211
u222 = 0.5980
36 HELM (2008):
Workbook 33: Numerical Boundary Value Problems