1 Three point stencil
Let us consider the boundary value problem defined by Equations (1):
The first line is the differential equation , and the second and third lines are the boundary conditions 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 HELM booklet 32.
We divide the interval into a number, say, of subintervals each of equal width . Our numerical solution will provide an approximation to at each value of where two subintervals meet (see Figure 1).
Figure 1
Key Point 1
A numerical approximation to the boundary value problem
is a sequence of numbers
,
,
,
,
,
.
Here
is an approximation to
at
, where
and
.
It is useful to give a name to the -values where we seek an approximation to . Hence we will sometimes write
The functions , , and will frequently occur evaluated at the values so it is convenient to set up the following abbreviations:
A numerical approximation to Equations (1) can be found by approximating the derivatives by finite differences. Here we will approximate and by central differences to obtain
that is, on using the abbreviations established in Key Point 1,
which we use as the motivation for the numerical method
This last equation can be rearranged, gathering together all the like -terms. It neatens things further to multiply through by as well, and the result of these manipulations appears in the following Key Point.
This approximation to the differential equation can be thought of as a three-point stencil linking three of the approximate -values. The expression
is centred around and involves , and . The general rule when dealing with a numerical stencil like this is to centre the stencil at every point where is unknown . (This general rule will appear again, for example on page 13.)
Key Point 3
Centre the stencil at every -point where is unknown. This will give a set of equations for the unknown -values, and we are guaranteed exactly as many equations as there are unknowns.
In the following Example, matters are simplified because the functions , , and are all constant.
Example 1
Let be a solution to the boundary value problem
, .
Using a mesh width of obtain a central difference approximation to the differential equation and hence find , .
Solution
In general, the central difference approximation to
is
In this case the coefficients are
These values will be the same for all because , , and are constants in this Example. Hence the general stencil is
In this case and our numerical solution consists of the values
So there are two unknowns, and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
Moving the stencil one place to the right, we put so that
In these two equations and are known from the boundary conditions and we move terms involving them to the right-hand side. This leads to the system of equations
Solving this pair of simultaneous equations we find that
to 2 decimal places.
This approximation is shown in Figure 2 in which the numerical approximations to point values of are shown as circles.
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 . We know from HELM booklet 31 that the central difference approximations get closer and closer to the derivatives which they approximate as decreases. In Figure 3 the results for are given again as circles, and a computer has been used to find more accurate approximations to using (shown as squares) and yet more accurate results (shown as dots) from using . (This involves solving larger systems of equations than are manageable by hand. The methods seen in HELM booklet 30 can be used to deal with these larger systems.)
Figure 3
We can now have some confidence that the results we calculated using tended to overestimate the true values of .
Example 2
Let be a solution to the boundary value problem
, .
Using a mesh width of obtain a central difference approximation to the differential equation and hence find simultaneous equations satisfied by the unknowns , and .
Solution
In this case the coefficients are
These values will be the same for all
because
,
,
and
are constants in this Example.
Hence the general stencil is
Here we have and our numerical solution consists of the values
So there are three unknowns, , and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
Moving the stencil one place to the right, we put so that
and finally we let so that
In these three equations and are known from the boundary conditions and we move terms involving them to the right-hand side. This leads to the system of equations
We can find (using methods from HELM booklet 30, for example) that the solution to the system of equations in Example 2 is
to 2 decimal places.
Task!
Let be a solution to the boundary value problem
, .
Using a mesh width of obtain a central difference approximation to the differential equation and hence find a system of equations satisfied by , .
In general, the central difference approximation to
is
In this case the coefficients are
These values will be the same for all
because
,
,
and
are constants in this Example.
In this case
and our numerical solution consists of the values
So there are three unknowns, , and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
Moving the stencil one place to the right, we put so that
and finally we let so that
In these three equations and are known from the boundary conditions and we move terms involving them to the right-hand side. This leads to the system of equations
(And you might like to check that the solution to this system of equations is , and .)
Example 3
The temperature of an electrically heated wire of length is affected by local air currents. This situation may be modelled by
Consider the case where , , and C and suppose that the ends of the wire are known (to 1 decimal place) to be at temperatures C and C.
Using a central difference to approximate the derivative and using 3 subintervals obtain approximations to the temperature and of the length along the wire.
Solution
This Example falls into the general case given at the beginning of this Section if we choose , , and . In this case and our numerical solution consists of the values
So there are two unknowns, and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
Moving the stencil one place to the right, we put so that
In these two equations and are known from the boundary conditions and we move terms involving them to the right-hand side. This leads to the system of equations
Solving this pair of simultaneous equations we find that
to 1 decimal place.
We conclude that the temperature of the wire’s length from the cooler end is approximately C and the temperature the same distance from the hotter end is approximately 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 , , and were each equal to a constant for all values of . More realistic engineering applications may involve coefficients that vary, and the next Example is of this type.
Example 4
Let be a solution to the boundary value problem
, .
Using a mesh width of obtain a central difference approximation to the differential equation and hence find , .
Solution
In general, the central difference approximation to
is
The coefficients will vary with in this Example because the functions , , and are not all constants. In this case and our numerical solution consists of the values
So there are two unknowns, and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
Moving the stencil one place to the right, we put so that
In these two equations and are known from the boundary conditions and we move terms involving them to the right-hand side. This gives the pair of equations
Solving this pair of simultaneous equations we find that
to 2 decimal places.
Once again we can monitor the accuracy of the results obtained in the Example above by recomputing for a smaller value of . 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 .
Figure 4
In the next Example we see that the derivative appears in the boundary condition at . This means that is not given at and we use the general rule given earlier in Key Point 3:
centre the stencil at every -value where is unknown.So this implies that we must centre the stencil at and this will cause the value 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 in terms of . This is done with the central difference
The following Example implements this idea.
Example 5
Let be a solution to the boundary value problem
,
(Note the derivative boundary condition at .)
Using a mesh width of obtain a central difference approximation to the differential equation and hence find the system of equations satisfied by , .
Solution
In general, the central difference approximation to
is
The coefficients vary with in this Example because the functions , , and are not all constants. In this case and our numerical solution consists of the values
So there are three unknowns, , and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
which introduces the fictitious quantity . We attach a meaning to on using the boundary condition at . Approximating the derivative in the boundary condition by a central difference gives
and we use this to remove from the equation where it first appeared. Hence
The remaining steps are similar to previous Examples. Putting in the stencil gives
Moving the stencil one place to the right, we put so that
In the last equation 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
where the components are given to 6 decimal places.
Exercises
-
Let
be a solution to the boundary value problem
,
Using a mesh width of obtain a central difference approximation to the differential equation and hence find and .
-
Let
be a solution to the boundary value problem
,
Using a mesh width of obtain a central difference approximation to the differential equation and hence find a system of equations satisfied by , and .
-
Let
be a solution to the boundary value problem
, . (Note the derivative boundary condition at .)
Using a mesh width of obtain a central difference approximation to the differential equation and hence find the system of equations satisfied by , .
-
In general, the central difference approximation to
is
In this case the coefficients are
These values will be the same for all because , , and are constants in this Example.
In this case and our numerical solution consists of the valuesSo there are two unknowns, and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
Moving the stencil one place to the right, we put so that
In these two equations and are known from the boundary conditions and we move terms involving them to the right-hand side. This leads to the system of equations
with solution
to 2 decimal places.
-
In general, the central difference approximation to
is
In this case the coefficients are
These values will be the same for all because , , and are constants in this Example.
In this case and our numerical solution consists of the valuesSo there are three unknowns, , and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
Moving the stencil one place to the right, we put so that
and finally we let so that
In these three equations and are known from the boundary conditions and we move terms involving them to the right-hand side. This leads to the system of equations
-
In general, the central difference approximation to
is
The coefficients vary with in this exercise because the functions , , and are not all constants. In this case and our numerical solution consists of the values
So there are three unknowns, , and . We centre the stencil at each of the corresponding values. Putting in the numerical stencil gives
which introduces the fictitious quantity . We attach a meaning to on using the boundary condition at . Approximating the derivative in the boundary condition by a central difference gives
and we use this to remove from the equation where it first appeared. Hence
The remaining steps are similar to previous exercises. Putting in the stencil gives
Moving the stencil one place to the right, we put so that
In the last equation 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