error analysis of the numerical method of lines

Back to Start
ERROR ANALYSIS OF THE NUMERICAL METHOD OF
LINES
J. N. M. Bidie, S. V. Joubert and T.H. Fay
Department of Mathematics and Statistics
Tshwane University of Technology, South Africa
e-mail: [email protected]
Abstract
The literature states that numerical method of lines (MOL) is a technique for solving
partial differential equations (PDEs) by discretising in all but one dimension. This paper
will demonstrate (using an example) how to estimate the default accuracy of the MOL
solution to a second order partial differential equation (PDE) being produced by a
computer algebra system (CAS). This technique is easy enough to introduce to
undergraduates doing a first course in PDE.
1. Introduction
There are numerous methods used to estimate the accuracy of a numerical solution to an
n th order ordinary differential equation or a system of n first order ODE. See for instance
[1], [2] and [9]. Further accuracy estimations were developed by Knapp and Wagon, ([7]
and Fay and Joubert [4]. Joubert and Greeff [5] and Joubert, Greeff and Fay [6] refined
the method of Fay and Joubert [4]. Broadly speaking, both these methods require that,
for instance, a second order ODE with initial conditions (that is, an IVP or Cauchy
problem) be differentiated once (if possible) and another initial condition be calculated,
resulting in a third order IVP equivalent to the original. Solving both equivalent IVP and
comparing their numerical solutions (solved by the CAS at the same working precision
for both systems of IVP) yields a method of assessing the CAS’s ability to solve the IVP
as well as estimating the accuracy of the solution produced. In an attempt to extend the
method by Joubert, Greeff and Fay [6] to PDEs, we use the method of lines (MOL) on an
example of Wolfram [8].
2. The numerical method of lines
The MOL is a technique for solving PDEs [8]. The PDE is discretised in all but one
dimension, and then the semi-discrete problem is integrated as a system of ODEs. It is
necessary that the PDE be well posed as an IVP in at least one dimension, since we will
use a CAS that employs a Runge-Kutte based IVP solver (we use Mathematica’s
NDSolve routine, but other CAS routines such as DERIVE’s RK routine also work
satisfactorily). The basic idea of the MOL is to replace the spatial (boundary value)
derivatives in the PDE with algebraic approximations by making use of Finite Difference
approximation equations.
3. An illustrative example
Using the example discussed in Wolfram [8], consider a one dimensional boundary value
problem (BVP) for seasonal variation of heat in soil:
∂u ( x, t ) 1 ∂ 2u ( x, t )
=
8 ∂x 2
∂t
u ( x , 0) = 0,
u (0, t ) = sin(2π t ),
∂ u (1, t )
= 0.
∂x
(1)
2
We choose a uniform grid xi , 0 ≤ i ≤ M with spacing h =
1
such that xi = ih . If we let
M
ui [t ] = u ( xi , t ) , then we calculate M + 1 coupled ODE as follows. Indeed, by setting
du0 d
= u (0, t )
dt
dt
(2)
and by using the second order central finite difference approximation equations
dui 1 ui +1 − 2ui + ui −1
=
+ O(h 2 ), 1 ≤ i ≤ M − 1,
2
dt 8
h
(3)
we obtain M ODE. Now, as discussed in [8], by assuming symmetry, we obtain
duM 1 2uM −1 − 2uM
=
+ O(h 2 ) .
2
dt
8
h
(4)
By way of illustration, we set M = 10. Now using the Mathematica code discussed in [8],
we obtain a system of 11 coupled first order ODE as given in Figure 1. Of course these
ODE can be coded individually into Mathematica or DERIVE.
u0 @ tD
2 π Cos@ 2 π tD , u1 @ tD
u2 @ tD
1
H 100 u1@ tD − 200 u2@ tD + 100 u3 @ tDL ,
8
1
H 100 u2@ tD − 200 u3@ tD + 100 u4 @ tDL ,
8
1
H 100 u3@ tD − 200 u4@ tD + 100 u5 @ tDL ,
8
1
H 100 u4@ tD − 200 u5@ tD + 100 u6 @ tDL ,
8
1
H 100 u5@ tD − 200 u6@ tD + 100 u7 @ tDL ,
8
1
H 100 u6@ tD − 200 u7@ tD + 100 u8 @ tDL ,
8
1
H 100 u7@ tD − 200 u8@ tD + 100 u9 @ tDL ,
8
1
H 100 u8@ tD − 200 u9@ tD + 100 u10 @ tDL ,
8
1
H 200 u9@ tD − 200 u10@ tDL
8
u3 @ tD
u4 @ tD
u5 @ tD
u6 @ tD
u7 @ tD
u8 @ tD
u9 @ tD
u10 @ tD
1
H 100 u0@ tD − 200 u1 @ tD + 100 u2 @ tDL ,
8
Figure 1: The eleven ODE under consideration
The initial condition u ( x, 0) = 0 yields ui (0) = u (ih, 0) = 0, i = 0,
,10 and so it is a
simple matter to solve this system using the NDSolve routine of Mathematica or the RK
3
routine of DERIVE. A plot of the solution produces eleven curves (lines) as shown in
Figure 2 below.
4
3
t
2
1
0
1
0 .5
u
0
- 0 .5
- 1
0
0 .2 5
0 .5
0 .7 5
x
1
Figure 2: Eleven solution curves (lines) produced by Mathematica
⎛ u0 ⎞
⎜ ⎟
The solution represented in Figure 3 will be denoted by u = ⎜ ⎟ .
⎜u ⎟
⎝ 10 ⎠
4. Error analysis
We make use of the method of Joubert, Greeff and Fay as discussed in [6] to do an error
analysis. Hence (assuming that u ( x, t ) is twice differentiable in the variable t ) we
differentiate the last ODE in the system shown in Figure 2 above (we could have chosen
to differentiate any one of them). We then transform this second order ODE into two
first order ODEs and determine a new initial condition as discussed in [6]. We have thus
4
determined a system of 12 IVP that is equivalent to the original system of 11 IVP. If the
⎛ w0 ⎞
⎜ ⎟
numerical solution to the system of 12 IVP is w = ⎜ ⎟ , then, as discussed in [6], we can
⎜w ⎟
⎝ 11 ⎠
estimate the error in the solution by considering
⎛ e0 ⎞ ⎛ u0 − w0 ⎞
⎜ ⎟ ⎜
⎟
E (t ) = ⎜ ⎟ = ⎜
⎟,
⎜e ⎟ ⎜u − w ⎟
10 ⎠
⎝ 10 ⎠ ⎝ 10
Joubert and Greeff ([5], 2006) suggested that, in order to see how well the algorithm is
performing, a visual comparison of the graphs of the component solutions uk and wk ,
k = 1,
, M should be done on the same set of axes. From an inspection of the graphs of
the solutions obtained for the example above it would appear that the algorithm is solving
the IVP (with ODE given in Figure 1) correctly. This is confirmed by plotting the graphs
of the estimated absolute errors ek , k = 1,
, M . For example, we plot e2 and e10 as
shown in Figures 3 and 4 below.
5
Figure 2: Absolute estimated error u2 − w2
Figure 3: Absolute estimated error u10 − w10
The other estimated absolute errors show a similar trend. This indicates that the CAS is
solving the given IVP to an accuracy of at most six digits over the domain 0 ≤ t ≤ 4 for
each i = 0,… , M .
Because we started with a local error of O(h 2 ) ≈ 10−2 = 0.01 for each ODE (see Equations
(3) and (4)), we cannot expect a six digit accuracy numerical solution to the BVP (1). In
fact, for any h =
1
, let n be the number of digits of accuracy (as indicated by the
M
graphical method described above) over the domain 0 ≤ t ≤ 4 for each i = 0,… , M . We
conjecture that the error in the MOL solution of the BVP (1) over the domain
0 ≤ t ≤ 4, 0 ≤ x ≤ 1 is approximately O(h 2 + 10− n ). Hence, in order to achieve six digit
accuracy we would probably need to take M ≥ 1000. This type of analyses is reserved for
a future project. With M = 10 we have probably achieved at most two digit accuracy for
this example.
6
5. Future research possibilities
We will investigate fitting an interpolating to the data contained in the solutions that we
have obtained, using a method developed by Kloppers [9]. Because the BVP (1) has an
analytical solution, we will be able to determine the accuracy of our “interpolating
function solution” and compare this with the accuracy of Mathematica’s NDSolve
InterpolatingFunction.
6. Conclusion
With a step size of h = 0.1 we have demonstrated how to estimate the accuracy of the
MOL for the example being studied. Undergraduate students that have already been
introduced to the numerical solution of higher order differential equations may be readily
taught the MOL and how to estimate the accuracy of the solution. As an introduction to
the error analysis of both ODE and PDE numerical approximation techniques, this
method can be readily taught. Students should be able to easily formulate the two
systems of IVP, check the equivalence of their solutions, solve the systems with an
estimation of accuracy for the solution and graphically check the ability of the CAS to
solve the IIVP involved.
REFERENCES
[1] Boyce W.E. and Di Prima R.C. (2001). Elementary Differential Equations and
Boundary Value Problems, 7th ed . New York????United States of America: John Wiley
& Sons, Inc.
7
[2] Burden R.L. and Faires J.D. (1993). Numerical Analysis, 5th ed. United States of
America: PWS – KENT.
[3] Fay T.H. and Joubert S.V. (2003). “Postanalysis of numerical solutions to Ordinary
Differential Equations”. New Zealand J. Math. 32, Suppl. issue, pp 67 – 75.
[5] Joubert S.V. & Greeff J.C. (2006). “Accuracy estimates for computer algebra
system initial – value problem (IVP) solvers”. South Africa Journal of Science, Vol. 102,
No. 12, pp. 46 – 50.
[6] Joubert S.V., Greeff J.C. and Fay T.H. (2008). “Can CAS be trusted?” Proceedings
of the TIME2008 Conference, Buffelspoor, South Africa.
[7] Knapp R. and Wagon S. (2001). Check your answers…But how? Mathematica in
action for Issue 7 – 4 of Mathematica in Education and Research, pp. 76 – 85. Online:
http://library.wolfram.com/infocenter/Articles/1658
[8] Wolfram research Mathematica documentation. (2008). “The numerical method of
lines”. Online: http://documents.wolfram.com/mathematica/BuiltinFunctions/AdvancedDocumentation/DifferentialEquations/NDSolve/PartialDifferential
Equations/TheNumericalMethodOfLines/index.en.html
[9] Zill D.G. & Cullin M.R. (1997). Differential equations with boundary – value
problems. New York: Brooks & Cole.
[10] Kloppers, P. H. (2007).XXXXXXXXXXXXXXXXXXXXXXXXXX
8