Alternate Num Analysis Notes
Alternate Num Analysis Notes
Getting Started
1.1 Introduction
This book is the second in a series of Computer Illustrated Texts on Nu-
merical Methods; the first was called A Simple Introduction to Numerical
Analysis. A Computer Illustrated Text (CIT) consists of a software package
which is integrated with a textbook. It is intended that the reader should,
ideally, use the software frequently whilst working through the book, as the
textbook and software components have been designed to complement and
reinforce each other. However, it is also intended that the textbook compo-
nent can be used without access to a computer, and that the software can
be used on its own, for example, to generate demonstration programs or to
solve problems beyond the scope of this introductory text. It is the com-
bination of text and programs which gives an ideal teaching environment.
Each CIT is self-contained in that all the programs which are required are
either included in the text or supplied on the disc. However, the nature of
the subject means that no short introductory textbook can include all the
material required and so explicit references are given to other sources that
may be needed. No ordering in terms of difficulty is implied between this
CIT and the first, but some of the exercises in the text can be performed
more easily if the disc associated with A Simple Introduction to Numerical
Analysis is available. This first chapter describes how to run the programs,
input data, store results and display graphics.
It is assumed that the reader has a basic knowledge of how to use a
microcomputer but no knowledge of programming languages is needed, only
1
2 CHAPTER 1. GETTING STARTED
For BBC microcomputer users with the disc version of the software, load-
ing of the program INTERP is accomplished by inserting the disc in drive 0,
holding down SHIFT and then pressing and releasing BREAK. This should
put up a menu on the screen giving a list of all the programs which are
available. (On a network system it will be necessary to ask for advice re-
garding the appropriate loading instructions.) On some screens you may find
that either the top line or the bottom line is obscured; this can be overcome
by selecting the menu option Screen adjustment and then following the
screen instructions to obtain the best setting. Once the menu is visible use
the cursor keys to select the required program. Now select the program IN-
TERP. The screen should clear and after a short delay it should look like
figure 1.1. The screen has been split into three windows. The top window
is used for dialogue, the bottom window contains current settings and the
middle window is used either for graphic or tabular display. Initially, the
option prompt should read
Select data options
where the data option is in inverse colours and a flashing cursor appears
under the ‘d’of data. The data option enables you to input, edit, plot
1.2. THE SOFTWARE: AN EXAMPLE 3
and store data. Other options can be selected by pressing normal character
keys: the SPACE bar is very convenient for this purpose. Alternatively, the
key marked ↑ can be used to cycle forwards and the key marked ↓ to cycle
backwards through the options available. An option is selected by pressing
RETURN, but do not press RETURN just yet.
Whenever the program is loaded a default set of data is supplied and
plotted; the five default points are shown in the display window by crosses.
These values can be tabulated and a method for doing so will be described
later. In the bottom window the current ranges of plotting are given together
with the number of data points (N). It is also possible to input data using
the cursor, the current position of which is also given in the bottom window.
It is a uniform convention, used throughout the software, that all data which
may be changed by the user will have its existing setting left unchanged if the
user presses RETURN or ENTER. Where options need to be selected, the
alternative may be viewed by pressing the SPACE bar repeatedly until the
desired option is showing, then selected by pressing RETURN or ENTER.
The purpose of the program INTERP is to construct smooth curves
through given data points. However, in this chapter we will only be interested
in how data can be input, examined, edited, plotted and stored. Therefore,
ensure that the Select option reads data options and then press RETURN
to select this option. A new prompt should appear:
Data: from keys
Cycle through the options available at this point by pressing the SPACE bar
repeatedly. If at any time you wish to quit press ESCAPE which will take
you back to the following prompt:
Action: Continue
Try it and see. Since we wish to continue, accept the default setting by
pressing RETURN; the program should then advance to the Select data
options prompt as above. Press RETURN again and we arrive back at the
Data prompt.
Select the option Data: from keys by pressing RETURN. Next we
have the option of clearing any existing data points. For the moment let us
just add to the existing points by using the default setting, i.e. by pressing
RETURN. Additional points can either be input in tabular or graphical form.
Pressing RETURN again will select the option
Data input format: tabular
4 CHAPTER 1. GETTING STARTED
and display the current points. A flashing cursor should now appear at
the bottom of the table and instructions concerning the input of data are
given in the top window. Try adding the point (0.95, 0.95) by typing in
each coordinate followed by RETURN. If you make a mistake you can delete
characters using the DELETE key before correcting them but each coordinate
is terminated by RETURN. To quit press Q. This process will return the
program to the option Data: from keys after sorting the tabular points
into ascending order. Now press RETURN to accept the current option of
supplying data from the keyboard and then press RETURN again to retain
the existing points. The program now advances to the option Data input
format: tabular. Press the SPACE bar to change this to Data input
format: graphical and then press RETURN. All the current data points
are displayed on the default graphical settings. These can be changed at this
point using the Graph data option. Cycle through the options available,
superimpose, clear - same axes and clear - new axes. For example, the
last of these options allows the user to set up different sets of axes. When
this option is shown press RETURN. The flashing cursor now appears in the
bottom window and it is possible to alter the range of each axis in turn. For
the moment accept the default settings by pressing RETURN each time the
flashing cursor moves to a new position in the bottom window. When all the
required values have been input the axes will be redrawn.
We will next investigate the graphical editing options. Firstly, select the
option Add point. It is now possible to add additional points either by (i)
specifying the x and y coordinates or (ii) using the cursor. For (i) first press
‘X’ and a flashing cursor will appear in the bottom window as the x coordi-
nate of the cursor. Try inputting a value 0.05 followed by RETURN. Now
press ‘Y’ and input a y coordinate of 0.0 followed by RETURN. The flashing
cursor in the middle window is now at the position (0.05, 0.0). In order to
add this point to the table press RETURN again, this will be confirmed by
an increase in N in the bottom window. To try out method (ii), first select
the Add point option again by pressing RETURN. Additional points can
now be added by moving the cursor with the arrow keys. The increment by
which the cursor moves is controlled by the ‘<’ (increase) or ‘>’ (decrease)
keys and is displayed in the top window. Note that the two methods can
be combined; for example, you may set the x coordinate and then adjust it
using the cursor control keys. The x and y values are open to change up to
the moment when you press RETURN.
The other graphical editing options are Change point, Delete point
1.2. THE SOFTWARE: AN EXAMPLE 5
and Quit editor. The Change point option first asks you to select a point
by using the cursor control keys; at this stage each keystroke makes the cursor
jump to the next point in ascending order (right or up arrow), or descending
order (left or down arrow). When the cursor flashes on the point you wish to
change press RETURN, and the situation is exactly as it was with the Add
point option. The Delete point option also begins by asking you to select
a point; once you have selected it you are asked to confirm that you wish to
delete the current point. The Quit editor option takes the program back
to the option level from which the editor was invoked.
At any stage of data input it is possible to view the current set of data
points by escaping from the current option and selecting the option
Data: tabulate
An option to send any tabulation to a connected printer is available which
reminds you to ensure that the printer is switched on. The option
Data: plot &/or edit
is available to display or modify any existing data set.
It is possible to store data in a file using the option
Data: store on file
and retrieve suitable data using
Data: from file
Wherever possible data files created by one program can be used as input for
any other when it is appropriate, but if an inappropriate data file is requested
then the program will display a suitable error message. Five simple data files
are provided on the program disc1 , as follows:
DATA
SIN
SPLINE
RAMP
FE
When loading a file you will need to type the whole file name at every occa-
sion, however, you need not distinguish between upper and lower case. You
will not be able to store any data on the program disc which is supplied be-
cause it is write protected and so you will need an unprotected disc of your
1
With BBC discs data files have a prefix D.; MS-DOS files will have a .DAT extension.
6 CHAPTER 1. GETTING STARTED
own. You can give the data files any name which is consistent with the rules
of the filing system you are using. Try loading the file DATA, examining it,
editing it and then storing the result.
cility for copying the screen image to memory, usually a disc file. The dump
file can then be used to recreate the screen image and users can then provide
their own software to make a hardcopy on any printer available. The details
of this process will depend on the hardware available and the system being
used. For the BBC microcomputer to which a disc drive is connected it is
possible to obtain a screen dump as follows. Whenever a dump option is
shown press RETURN at which point the top window should show
Dump to filename:
Make sure that the disc in the drive is not write-protected and then type in
a suitable file name, which must satisfy the usual BBC filename conventions,
followed by RETURN.
If an Epson printer, or any other device which is software compatible,
is to be used then the screen dump can be copied to the printer using the
program PRNTDMP which is available from the main menu. Selecting
this program gives a self-explanatory dialogue for the user to follow.
One final advantage to this method of obtaining screen dumps is that it
is possible to keep a permanent copy of screen images and recall them to the
screen for future demonstration. For BBC users this can be carried out from
within the program or else in intermediate command mode. In the latter
case if the file DMPF were the name given to a dumpfile created in mode 4
then it can be recalled to the screen, but not printed, using the command
MODE 4:*LOAD DMPF
Interpolation
Example 2.1.1
In an experiment the yield of a chemical species is recorded as a function
of the concentration of another reagent which is present. As it is impossible
to vary the concentration of the reagent continuously, only a finite set of
different values can be tabulated. Let us assume that the following results
have been obtained.
9
10 CHAPTER 2. INTERPOLATION
BE (0.77210 − 0.58813)
CD = AD = 0.01 = 0.00920,
AE (0.7 − 0.5)
to five significant figures. (Only five significant figures are quoted here since
the original tabular values are only given to this accuracy.) Hence, y(0.51)
is approximately 0.58813 + 0.00920 = 0.59733.
2.1. POLYNOMIAL INTERPOLATION 11
1.5
1.0
0.5
-0.5
C
A E
D
0.5 x 0.7
Instead of using the similar triangle argument above we could have de-
termined an explicit expression for the equation of the straight line joining
the points A and B in figure 2.2. This line will be of the form
y = c0 + c1 x,
and passes through the points (0.5, 0.58813) and (0.7, 0.77210). Therefore,
0.58813 = c0 + 0.5c1
and
0.77210 = c0 + 0.7c1 .
Eliminating c0 gives c1 = (0.77210 − 0.58813)/(0.7 − 0.5) = 0.91985, which
is the gradient of the line. The intercept c0 is then found to be at 0.12821,
hence the equation of the line joining the points A and B is
y = 0.12821 + 0.91985x,
from which y(0.51) = 0.59733 as before. Clearly, this very naive approach is
simple to use but ignores most of the information given in the table. Fur-
thermore, it fits an unnatural function to the data supplied since the fitted
function has a strange derived function. Between each pair of consecutive
data points the fitted function is linear and therefore has constant slope. The
derivative of the piecewise linear function shown in figure 2.1 will therefore be
piecewise constant and look like the function shown in figure 2.3. In order to
overcome this problem we could use higher order functions rather than linear
ones. For example, through any three points we can fit a unique parabola.
Exercise 2.1.1 (Analytical/Computational) Find the parabola through the
points (0.3, 0.39646), (0.5, 0.58813) and (0.7, 0.77210). (Hint: the general
parabolic function is y = a + bx + cx2 , and the three coefficients can be
determined by substituting the three points into this equation to produce
three linear equations which must be solved to find values for a, b and c.)
If the idea of fitting a polynomial through a number of points is unfamiliar,
then it is important to work through exercise 2.1.1. In particular, check that
2.1. POLYNOMIAL INTERPOLATION 13
the resulting quadratic function takes the correct values at x = 0.3, x = 0.5
and x = 0.7. It is not difficult to extend this process to work for arbitrary
polynomials, and it is to this problem that we next turn our attention.
A polynomial of degree n has n + 1 coefficients and so we can fit a unique
polynomial of degree n through n + 1 distinct tabular points, xi , i = 0, . . . , n.
Let us assume that we are given a table of values (xi , yi ), i = 0, . . . , n, and
try to fit such a polynomial. Let Pn be the interpolating polynomial
Pn (x) = c0 + c1 x + c2 x2 + . . . + cn xn .
Now we select the coefficients cj , j = 0, . . . , n, so that the equations
Pn (xi ) = yi, i = 0, . . . , n, (2.1)
are satisfied. This gives a system of n + 1 linear equations in the n + 1
unknown coefficients cj , j = 0, . . . , n. These linear equations may then be
solved using, for example, Gaussian elimination with partial pivoting. (See
Harding and Quinney (1986).)
Example 2.1.2
For the five values in table 2.1 we can fit a unique polynomial of degree 4,
i.e.
P4 (x) = c0 + c1 x + c2 x2 + c3 x3 + c4 x4 .
Evaluating this polynomial at the five data points in table 2.1 gives the
following system of linear equations:
1.5
1.0
0.5
-0.5
Notice that the values in the third column of table 2.2 are displayed to
seven decimal places even though the data are only given to five. This is
to emphasize the fact that whenever this process is carried out it will be
prone to numerical errors. For this example, if we round the results in col-
umn 3 to five decimal places we recover the initial data. Whether this is
always the case will be examined later. The function obtained, P4 (x), is
shown in figure 2.4. Notice that between the tabulated points the interpo-
lating polynomial is quite smooth and so we are justified in evaluating it at
non-tabular points. For example, we can determine a value for y(0.51) by
P4 (0.51) = 0.59733892. However, this is not always the case as the next ex-
ample will demonstrate. Outside the range of the tabular points it would be
unwise to use the interpolating polynomial to extrapolate the given values.
This can be seen by examining the curve in figure 2.4 for values of x in excess
of 0.9 where one might expect a monotonic increasing function.
2.1. POLYNOMIAL INTERPOLATION 15
Example 2.1.3
The interpolating polynomial which passes through the points (−2, e−4 ),
(−1, e−1 ), (0, 1), (1, e−1 ), and (2, e−4 ) is shown in figure 2.5. These val-
ues are obtained from the function exp(−x2 ) which is always positive but
as figure 2.5 shows the same is not true of the interpolating polynomial for
values of x in the intervals (−2, −1) and (1, 2)! Furthermore, as the number
of points increases the interpolating polynomial behaves less like the func-
tion exp(−x2 ). This is called Runge’s problem and will be discussed in more
detail in the next chapter. (See also exercises 2.1.4 and 3.4.4.)
1.5
1.0
0.5
-2 -1 1 2
-0.5
selecting the graphics parameters which are used to plot the resulting poly-
nomial. For the moment select the option
Graph data: superimpose
The interpolating polynomial is now drawn in the graphics window and the
actual polynomial is given in the bottom window. (The coefficients are lim-
ited to five significant figures by the space available to display them.) We
can now evaluate the required interpolating polynomial using the option
Option: Evaluate interpolant
Entering the value for x = 0.51 produces the same value as in example
2.1.2. All computation is carried out to full accuracy; only the coefficients
are displayed to five significant figures.
Exercise 2.1.3 (Computational) Use the program INTERP and any four
values from table 2.1 to determine a cubic interpolant and compare the esti-
mate for y(0.51) with the value determined above. This can be carried out by
quitting the current option by pressing Q and then selecting the option Edit
data. Press RETURN in order to accept the current plotting parameters
and then cycle through the edit options available by pressing any key but
RETURN. (Recall that you can cycle backwards using the key marked ↓.)
When the current option is Delete point press RETURN and use the cursor
keys to select the point you wish to remove and then press RETURN again.
Cycle through the options now available until the option is Quit editor and
then press RETURN. Once again cycle through the options available until
the current option becomes Select method and press RETURN yet again.
Accepting the option Method: Construct interpolating polyn., the in-
terpolating polynomial through the remaining points will be determined and
plotted. The effect of deleting another point can be examined as follows.
Cycle until the option Edit data is current and then press RETURN twice.
This will take you into the data editor; the current edit option should be Add
point. If this is the case press RETURN, if not cycle until it is and then
press RETURN. The cursor in the graphics window should now be flashing
at the point which was previously deleted; this point can be added back to
the table simply by pressing RETURN. Other points can then be deleted to
consider the effect of fewer points in the table. How does the selection of the
four points influence the interpolated value?
Exercise 2.1.4 (Computational) Use the program INTERP to obtain five
equally spaced points in the interval (−5, 5) from y = exp(−x2 ) and then
2.1. POLYNOMIAL INTERPOLATION 17
Ac = y, (2.3)
where A is an n+1 by n+1 matrix and c and y are vectors of dimension n+1.
The columns and rows of A are numbered 0 to n and the components of A
are aij = xji , i = 0, . . . , n, j = 0, . . . , n. Similarly yi = y(xi ), i = 0, . . . , n, and
ci are the coefficients of the interpolating polynomial which is required. (See
equations (2.2) for a simple example with n = 4.) This system of equations
will have a unique solution provided the matrix A is non-singular, therefore,
we examine the possibility of it being singular or almost singular. In order to
do this we consider the determinant of A; this matrix is called a Vandermonde
matrix and it is possible to show that it has determinant
Y
(xi − xj ).
i=1,...,n, j<i
1 x0 x20
1 x1 x21 ,
1 x2 x22
determinant may be small, i.e. the equations are nearly singular, and hence
the solution may be inaccurate. This type of inaccuracy is usually called
inherent ill-conditioning and is a fundamental part of the problem, i.e. in-
dependent of the method of solution. In order to demonstrate the problems
which may arise when determining interpolating polynomials in such circum-
stances let us consider the following example.
Example 2.1.4 (Computational)
Let us begin by finding the quartic polynomial which passes through the
points in table 2.3. Using the program INTERP produces the interpolating
polynomial shown in figure 2.6. In order to consider how sensitive this prob-
lem is let us perturb the y value of the third entry in table 2.3 from 1.05 to
0.95 and see how this affects the computed solution. The resulting quartic
polynomial is shown in figure 2.7. Compared with the original interpolation
quartic it is clear that this problem is inherently ill-conditioned.
Table 2.3:
x y
0.00 2.00
0.95 1.00
1.00 1.05
1.05 1.00
2.00 0.00
0
0.5 1.0 1.5 2.0
-1
-2
-3
-4
-5
-6
0
0.5 1.0 1.5 2.0
-2
Now let us round the entries in table 2.1 to four decimal places and then con-
struct a polynomial through the resulting points. This gives the polynomial
The maximum relative change in any coefficient is less than 0.12% and so
this problem is relatively well conditioned.
Exercise 2.1.6 (Computational) Use the program INTERP to construct the
interpolating polynomial through the tabular values in the file SIN. Investi-
gate the sensitivity of the data provided by examining the effect of perturbing
one or more of the values given. Is this problem inherently well conditioned?
Is it susceptible to induced ill-conditioning?
i = 0, ..., n, as
Πj6=i(x − xj )
Li (x) =
Πj6=i(xi − xj )
We see that each of these polynomials has degree n and that Li (xk ) = 0if
k 6= ibut is equal to 1 when k = i. Now consider the function
i=n
X
P (x) = yi Li (x).(2.5)
i=0
1.0
0.8
0.6
0.4
0.2
-0.4
where
p1 (x1 ) = y0 + a1 (x1 − x0 ) = y1 .
Next dene
p2 (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ),
then since a0 = y0 and a1 = (y1 − y0 )/(x1 − x0 ) we have that p2 (x0 ) = y0 and
p2 (x1 ) = y1. Furthermore,
then p2 (x2 ) = y2 , i.e. p2 (x) passes through (x0 , y0 ), (x1 , y1 ) and (x2 , y2 ). We
can repeat this process by dening
p0 (x) = y0 = 0.09956,
p1 (x) = p0 (x) + a1 (x − x0) = 0.09956 + a1 (x − 0.1).
(0.39646−0.09956)
Select a1 so that p1 (x1 ) = 0.39646, i.e. a1 = (0.3−0.1)
which gives
The process outline above can be automated in the following way. Given
the table of values (xi , yi), i = 0, ..., n, we dene the first divided differences
associated with these values by
(yi+1 − yi )
f [xi , xi+1 ] = .
(xi+1 − xi )
Next we compute second divided di?erences as
(f [xi+1 , xi+2 ] − f [xi , xi+1 ])
f [xi , xi+1 , xi+2 ] =
(xi+2 − xi )
and so on. When the (k − 1)th divided di?erences have been obtained,
i.e. f [xi , xi+1 , ..., xi+k−1 ] and f [xi+1 , xi+2 , ..., xi+k ] we dene the k th divided
di?erence as
(f [xi+1 , ..., xi+k ] − f [xi , ..., xi+k?1 ])
f [xi , xi+1 , ..., xi+k ] =
(xi+k − xi )
These differences can be shown schematically as in table 2.4. We can
then show that the polynomial pn (x), given by
pn (x) = y0 + f [x0 , x1 ](x − x0 ) + f [x0 , x1 , x2 ](x − x0 )(x − x1 )
= + . . . + f [x0 , x1 , . . . , xn ](x − x0 )(x − x1 ) . . . (x?xn?1),
passes through the points (xi , yi ), i = 0, ..., n, and is therefore identical to
the interpolating polynomial Pn (x). (See exercise 2.2.4.)
Exercise 2.3.1 (Analytical) Show that the above expression is the interpolat-
ing polynomial through the points (xi , yi), i = 0, ..., n.
Exercise 2.3.1 (Analytical) Show that f [x1 , x2 , . . . , xk ] is invariant with re-
spect to all permutations of the tabular points x1 , x2 , . . . , xk .
Example 2.3.2 (Calculator)
To demonstrate the use of divided differences we construct the interpolating
polynomial through the ve points in table 2.1. Firstly, we obtain the table
of divided differences given by table 2.5, as illustrated in table 2.4. The
required quartic polynomial is then given by
P4 (x) = 0.09956 + 1.48450(x − 0.1) − 1.31538(x − 0.1)(x − 0.3)
+ 2.031875(x − 0.1)(x − 0.3)(x − 0.5)
− 3.9015625(x − 0.1)(x − 0.3)(x − 0.5)(x − 0.7),
26 CHAPTER 2. INTERPOLATION
where the coe?cients are given by the rst entry in each column of the tableau
of divided di?erences. Expanding this expression gives the polynomial
which agrees with the interpolating polynomial through these points as com-
puted previously.
Exercise 2.3.3 (Analytical) Use the method given in section 2.1 to determine
an interpolating polynomial of degree 2 which passes through the points (0,
3), (1, 6) and (2, 11). Obtain the corresponding Lagrangian polynomials L0 ,
L1 and L2 and hence show that the polynomial
is identical with the interpolating polynomial which was derived using equa-
tion (2.1). Construct a table of divided di?erences for these data points and
hence construct a quadratic function which passes through the same points.
Conrm that all three methods give the same polynomial.
Exercise 2.3.4 (Programming) Write a simple program to read in a set of
tabular points and construct a table of divided differences. Test your pro-
gram on the data given in exercise 2.3.3. Extend the program to produce
polynomial interpolants as described in example 2.3.1.
this file is obtained from the function y = sin x. Insert additional points
and investigate how the accuracy of the interpolated point depends on the
spacing and number of points.
x y
0.4 −0.040
0.38261
0.3 0.190 0.38189
0.38636 0.38195
0.5 −0.250 0.38261 0.38196
0.39130 0.38213 0.38196
0.2 0.440 0.38392 0.38202
0.36296 0.38258
0.1 0.710 0.37721
0.34483
0.0 1.000
x2 − 3x + 1 = 0.
Exercise 2.4.5 (Computational) Find the larger root of the quadratic equation
given in example 2.4.3 by tabulating the function f (x) in the interval (2.5, 3)
and then using inverse interpolation.
Exercise 2.4.6 (Computational) Load the data from file SIN and use inverse
interpolation to determine a value of x such that y = 0.5. The data in this file
are obtained from the function y = sin x; investigate the effect of additional
points and different orderings.
0.8
0.6
0.4
0.2
in the interval (xi−1 , xi ); then as there are n intervals we shall have 3n coeffi-
cients to find. First of all, we require that the resulting functions interpolate
the points (xi , yi ), i = 0, . . . , n, i.e.
which gives 2n equations. (This condition will ensure that the resulting
functions are continuous at the internal points x1 , . . . , xn−1 .) Furthermore,
at each internal point, xi , we require that the derivatives of Qi and Qi+1
agree, i.e.
Q′i (xi ) = Q′i+1 (xi ), i = 1, . . . , n − 1. (2.7)
Therefore, we have 3n − 1 equations to determine the 3n coefficients ai ,
bi , ci , i = 1, . . . , n. It would appear that we can select any one coefficient
arbitrarily. Combining together the resulting quadratic functions gives a
quadratic spline.
1.5
1.0
0.5
Q HxL d
d i i-1
i-1
x x
i-1 i
therefore, Q′i (xi ) = Q′i+1 (xi ) = di , which will ensure that the conditions (2.7)
are satisfied. Next we integrate this expression to get
(x − xi−1 )2 di − (x − xi )2 di−1
Qi (x) = + ci ,
2(xi − xi−1 )
where ci is a constant produced by the integration. Finally, we select the
constants ci to ensure that the combined spline is continuous across each
mesh node x = xi , i = 1, . . . , n − 1. (This ensures that equations (2.6) are
satisfied.) Notice that
and
Qi (xi−1 ) = 21 (xi−1 − xi )di−1 + ci = yi−1 .
We then eliminate ci between these equations to give
2(yi−1 − yi)
di = − di−1 . (2.8)
(xi−1 − xi )
This is a first-order recurrence relation and so all the required values, d1 , d2 , . . .
can be found once d0 is specified. However, in general we will not be able to
specify both d0 and dn . (See Harding and Quinney (1986).)
Example 2.5.1 (Computational)
Load INTERP and when the prompt shows Select method press RE-
TURN. Now change the option to Method: Quadratic spline and then
36 CHAPTER 2. INTERPOLATION
press RETURN again. Use the graph option to set up suitable plotting
ranges and then you will be requested to supply a value for the slope of the
spline at its left end, i.e. the value d0 . For the moment accept the default
value d0 = 1.4845 and then observe the corresponding quadratic spline being
plotted. (See figure 2.12.) Alternatively, we could take d0 = 0 which gives the
quadratic spline shown in figure 2.10. The value d0 = (y1 − y0 )/(x1 − x0 ) is
obtained by using a finite difference approximation for the slope at x0 which
explains why a better result is produced. (This is the default value which
the program adopts.)
Exercise 2.5.1 (Computational) Use the program INTERP to determine a
quadratic spline through the data points in table 2.1.1. Investigate the effect
of changing the value of d0 . (The quadratic spline for the default choice is
given by figure 2.12.)
1.5
1.0
0.5
From figure 2.12 we see that a quadratic spline and its derivative are
continuous at each node. However, the curvature is not smooth since
(d1 − d0 )
lim Q′′0 (x) =
x→x1 (x1 − x0 )
but
(d2 − d1 )
lim Q′′1 (x) =
x→x1 (x2 − x1 )
and these may not be the same. A further problem with quadratic splines
is that they tend to produce oscillatory functions as is also demonstrated
2.5. SPLINE INTERPOLATION 37
in figure 2.10. In order to ensure that both the first and second derivatives
are continuous we need to use a higher order local interpolant in each sub-
interval. One of the most popular is to use cubic functions in each sub-interval
and then attempt to select the coefficients so that both the slope and the
curvature are continuous across internal tabular points.
S HxL yi-1
i
x x
i-1 i
Let us suppose that we are given a table of data in the form of data points
(xi , yi), i = 0, . . . , n. In the interval (xi , xi+1 ) we use the cubic polynomial
Si (x) = ai + bi x + ci x2 + di x3 . (2.9)
and
′′
Si−1 (xi ) = Si′′ (xi ), i = 1, . . . , n − 1,
which gives a further 2n − 2 conditions (see figure 2.13). It would appear
that we can specify any two values arbitrarily. Once all 4n parameters are
determined we shall have a unique cubic in each subinterval. This collection
38 CHAPTER 2. INTERPOLATION
Mi+1 (x − xi )3 − Mi (x − xi+1 )3
Si (x) = + αi x + βi , (2.11)
6hi
where hi = xi+1 − xi . Now we fit this expression to the data points (xi , yi )
and (xi+1 , yi+1 ), i.e.
(yi+1 − yi ) 1
αi = − (xi+1 − xi )(Mi+1 − Mi ) (2.12)
(xi+1 − xi ) 6
and
βi = yi − αi xi − 61 Mi (xi+1 − xi )2 . (2.13)
2.5. SPLINE INTERPOLATION 39
i.e.
Mi (xi − xi−1 ) + 2αi−1 = Mi (xi − xi+1 ) + 2αi
or
αi − αi−1 = 12 Mi (xi+1 − xi−1 ). (2.14)
Finally, we use equation (2.12) to eliminate αi and αi−1 from (2.14) to give
6(yi+1 − yi ) 6(yi − yi−1 )
hi−1 Mi−1 + 2(hi−1 + hi )Mi + hi Mi+1 = − . (2.15)
hi hi−1
This second-order recurrence relation holds at all internal points, there-
fore, we have a system of n − 1 linear equations in the n + 1 unknowns
M0 , M1 , . . . , Mn . In particular this system of equations has a special form
since in a matrix notation we obtain entries only on the main diagonal and
the diagonals directly above and below this diagonal. These equations are
therefore called tridiagonal and special methods have been developed to solve
them which take advantage of their structure. (For an introduction to second-
order recurrence relations and the solution of tridiagonal systems of linear
equations see Harding and Quinney (1986).) The general solution of this re-
currence relation will involve two arbitrary values which can be determined
if two additional conditions are supplied. There are two particularly popular
ways they can be specified: (i) free splines and (ii) clamped splines.
(i) Free splines (natural splines). The simplest way of imposing additional
conditions is to set both M0 and Mn equal to zero. (This is equivalent to
assuming that the interpolating function is approximately linear at x0 and
xn since Mi is the second derivative at xi .)
Example 2.5.2
Use the program INTERP to determine the natural spline through the data
points given in table 2.1. As there are five points there will be five second
derivative values to be determined. Let these values be M0 , M1 , M2 , M3 and
M4 , but because the spline is to be natural we have M0 = M4 = 0. Next we
write down the equation (2.15) at the internal points, i.e.
6 6
0.2M0 +0.8M1 +0.2M2 = (0.58813−0.39646)− (0.39646−0.09956)
0.2 0.2
40 CHAPTER 2. INTERPOLATION
6 6
0.2M1 +0.8M2 +0.2M3 = (0.77210−0.58813)− (0.58813−0.39646)
0.2 0.2
6 6
0.2M2 +0.8M3 +0.2M4 = (0.89608−0.77210)− (0.77210−0.58813)
0.2 0.2
or
0.8 0.2 0 M1 −3.156899
0.2 0.8 0.2
M
2 =
−0.231000 .
M3 (x − x2 )3 − M2 (x − x3 )3
S2 (x) = + α2 x + β2 ,
6(x3 − x2 )
where
(0.7721 − 0.58813) 1
α2 = − × 0.2(−2.660967 − 1.440214)
0.2 6
and
1
β2 = 0.58813 − 0.5α2 − × 1.440214(0.2)2
6
from (2.12) and (2.13). Evaluating these expressions gives the component
of the spline in the interval (0.5, 0.7) and hence S2 (0.51) = 0.59731 to five
decimal places.
Exercise 2.5.2 (Analytical) Determine an explicit expression for the natural
cubic spline through the data points of table 2.1. By direct evaluation show
that the resulting spline is continuous and has continuous first and second
derivatives at the internal points x1 ,...,xn−1 .
Exercise 2.5.3 (Computational) Use the program INTERP with the option
Method: Cubic spline - free to confirm the results of example 2.5.2.
2.5. SPLINE INTERPOLATION 41
1.5
1.0
0.5
Figure 2.14: The free cubic spline for the points in table 2.1.1
(ii) Clamped splines. If it is possible to supply values for the slope of the
interpolating function at x0 and xn then we can use equation (2.11) to provide
the additional equations required. Let us suppose that we are given that
S0′ (x0 ) = d0 and Sn′ (xn ) = dn then differentiating (2.11) and substituting we
have
(y1 − y0 ) h0
d0 = − (M1 + 2M0 )
h0 6
or
6(y1 − y0 )
2h0 M0 + h0 M1 = − 6d0. (2.16)
h0
and
(yn − yn−1) hn−1
dn = + (Mn−1 + 2Mn )
hn−1 6
or
(yn − yn−1 )
hn−1 Mn−1 + 2hn−1 Mn = 6dn − 6 . (2.17)
hn−1
Next we combine equations (2.16) and (2.17) with the linear equations given
by (2.15) to obtain n + 1 linear equations in the unknown values Mi , i =
0, ..., n. Once these values are known the required cubic spline is uniquely de-
termined. The matrix system which is formed in this way is both tridiagonal
and diagonally dominant and can be solved in a relatively straightforward
way by Gaussian elimination without partial pivoting. (See Harding and
Quinney (1986).)
Example 2.5.3 (Computational)
42 CHAPTER 2. INTERPOLATION
Use the program INTERP to determine the clamped cubic spline which
passes through the data points in table 2.1 and has slope 1.4845 at x = 0.1
and 0.6199 at x = 0.9. (These values are default settings.) This clamped
cubic spline is shown in figure 2.15 and can be compared with the free spline
in figure 2.14.
1.5
1.0
0.5
as required.
In order to demonstrate the importance of this result consider the follow-
ing example.
Exercise 2.5.4 (Computational) Determine a polynomial approximation for
the data in table 2.10. (These data points are stored in the file SPLINE).
Now construct the natural cubic spline which passes through these points
and compare the results obtained.
44 CHAPTER 2. INTERPOLATION
1.0
0.8
0.6
0.4
0.2
-3 -2 -1 1 2 3
ter 3 will consider this further, but for the moment we conclude this chapter
with the following general remarks.
4. The curve which has minimum curvature through a set of points and
yet has continuous first and second derivatives is a natural cubic spline.
Such a function is made up from a set of cubic functions, one in each
tabular interval, which are continuous and have continuous first and
second derivatives at each internal tabular point.
46 CHAPTER 2. INTERPOLATION
The Approximation of
Functions
‘I’ve got fourteen pots of honey left, or is it fifteen, as the case may be’,
said Pooh humbly.
‘Well, let’s call it sixteen’ said Rabbit.
With apologies to A A Milne.
In an age of the ever increasing use of pocket calculators and micro-computers,
the need to evaluate standard mathematical functions is also increasing.
Clearly, electronic devices cannot store all possible values of such functions;
the question therefore is how do such machines evaluate expressions such as
sin(1.4) or exp(−3.456)? Inherent in such a problem is not only the need
to carry out such an evaluation but also the need to know how accurate the
presented result is going to be. In this chapter we will examine this question
and try to provide some sensible answers.
47
48 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
(x − a)(n+1) (n+1)
Rn = f (θ), (3.2)
(n + 1)!
and θ lies between x and a. Therefore, if we knew the value of f (a), f ′ (a),
f ′′ (a), . . . , f (n) (a), we could use equation (3.1) to estimate f (x). Further-
more, the maximum possible error of such an approximation is given by
max|Rn | for all values of θ between x and a.
Example 3.1.1
We can use a Taylor series with a = 0, which is sometimes called a Maclaurin
series, to estimate exp(0.1). We can then consider questions such as the
following. If five terms of this series are used what is the maximum possible
error? How many terms are required to evaluate exp(0.5) correct to six
decimal places? The Taylor series expansion of exp(x) about x = 0 is given
by
x2 x3 x4 xn
exp(x) = 1 + x + + + + ...+ + ....
2! 3! 4! n!
Taking the first five terms gives
compared with the actual error of 9.0 × 10−8 . Suppose we now wanted to
find exp(0.5) using the same quartic polynomial expression then
RETURN. The function will now be plotted in the graphics window and
then the program will return to the option Plot: function. Now change
the Plot option to approximation by pressing the SPACE BAR and press
RETURN to show the required cubic Taylor series approximation for exp(x)
on this interval. It is also possible to plot the error between the function and
approximation by changing the plotting option, Plot, to show Plot: error.
The result is shown in figure 3.1. The associated error function is plotted on
the same x axis but the corresponding y axis is scaled by a suitable factor
which is displayed on the screen. In order to find this approximation it is
necessary to determine suitable values for the coefficients in equation (3.1)
and with the option calculate coeffs this is done by using finite difference
approximations. (See Appendix B.) Exercise 3.1.1 demonstrates how it is
possible for the user to supply these coefficients manually.
2.5
2.0
1.5
1.0
Exercise 3.1.1 (Computational) Load the program APPROX and the func-
tion exp(x), |x| ≤ 1. Select the Method: Taylor Series and the Option:
calculate coeffs and then plot the function, its cubic Taylor series approxi-
mation and the associated error as described in example 3.1.2. Exit from this
part of the program by taking the option Plot: quit and follow the instruc-
tions given. This will return the program to the prompt Option: calculate
coeffs. Again cycle through the options available at this point which in-
clude the possibility of storing the current coefficients on a suitable disc file,
reading another set of coefficients which you have previously stored, or set
coefficients manually. The degree of the current approximation should be
3 and the point about which the expansion is determined should be a = 0;
3.1. TAYLOR SERIES APPROXIMATION 51
if not reset these values. The correct values for the first four coefficients in
the Taylor series of exp(x) about x = 0 are 1, 1, 21 and 61 . Accept the option
to set coefficients manually and then input these values; notice that the
current values, which are determined by finite differences, are shown on the
screen and are very close to the correct values. Compare the approximations
which are determined.
Exercise 3.1.2 (Computational) Use the program APPROX to determine a
cubic Taylor series expansion about x = 0 for exp(x), |x| ≤ 2. Compare the
results with a corresponding expansion about the points x = 1 and x = −1.
Exercise 3.1.3 (Analytical) How many terms are required to evaluate the
function log(1 + x), |x| < 21 , correct to eight decimal places?
As the evaluation of polynomials plays a fundamental role in this type of
approximation it is appropriate to consider the most efficient way of carrying
out this task. We shall illustrate a technique called nested multiplication.
This method permits the evaluation of a polynomial expression without the
storage of intermediate results and therefore it can be carried out on a hand
calculator which does not have a memory.
Exercise 3.1.4 (Analytical) Polynomial evaluation by nested multiplication.
Let pn (x) = an xn + an−1 xn−1 + . . . + a1 x + a0 . Determine the number of
multiplications and additions required to evaluate this polynomial directly
for a fixed value of x. Show that if we define a sequence uj by
which ensures that all the terms raised to powers are less than 1; hence we
should have a stable recurrence relation and reasonable conditioning. This
introduces a very important point, for clearly this problem will always arise
if we attempt to approximate any function outside the interval either [0, 1]
or [−1, 1]. However, we can always scale any interval [a, b] to either of these
standard intervals by a suitable linear scaling procedure.
Exercise 3.1.5 (Calculator) By examining the possible errors in the coeffi-
cients of the polynomial (3.5) determine upper and lower error functions for
this expression.
Exercise 3.1.6 (Analytical) Scale the interval [2, 10] to the standard intervals
[0, 1] and [−1, 1].
exp(x) = 1 + x + 12 x2 + 61 x3 + R3 (x),
where the remainder term satisfies |R3 (x)| ≤ max|x|≤1 |f iv |/4! ≤ 0.113. This
approximation is shown in figure 3.2 and the error function, R3 (x), in fig-
ure 3.3. As an alternative method we can make the function and approximat-
ing polynomial agree at a given set of points, i.e. we select the coefficients a
nth degree polynomial so that pn (xi ) = f (xi ), i = 0, ..., n+ 1. Thus the prob-
lem becomes one of constructing an interpolating polynomial through n + 1
points. Firstly, we need to decide where we are going to put the tabulation
points xi , i = 0, 1, 2, 3, at which the polynomial and function agree. For the
moment, let us put them at equally spaced points in [−1, 1], i.e. −1, − 13 , 13
and 1, and assume that the required cubic polynomial is
p3 (x) = a0 + a1 x + a2 x2 + a3 x3 .
p3 (−1) = a0 − a1 + a2 − a3 = exp(−1).
This function is also plotted in figure 3.2 and its error in figure 3.3. Notice
that the maximum error associated with the polynomial (3.6) is much less
than the maximum error associated with the corresponding Taylor expansion
of the same order.
We have already seen how it is possible to estimate the error associated
with a Taylor series approximation of a given function. Now we will con-
struct an error function for polynomial interpolation. Firstly, we recall that
f (x) and the interpolant pn (x) agree at the n + 1 points xi , i = 0, 1, . . . , n,
therefore,
2.5
2.0
x
1.5 e
1.0
0.5
0.025
0.015
0.010
0.005
-0.010
where K(x) is to be determined. For any given value of x let us define the
function φ by
φ(t) = f (t) − pn (t) − K(x)w(t),
where w(t) = (t−x0 )(t−x1 ) . . . (t−xn ), and then notice that φ vanishes at the
points n + 2 points x, x0 , . . . ,xn . By Rolle’s theorem φ′ must vanish between
any two points at which φ vanishes and so φ′ has n + 1 zeros. Similarly, φ′′
has n zeros and so on until we find that the (n + 1)th derivative of φ, φ(n+1) ,
has exactly one zero; let this zero be θ, then
0 = φ(n+1) (θ) = f (n+1) (θ) − pn(n+1) (θ) − Kw (n+1) (θ).
However, p(n+1)
n is identically zero and w (n+1) = (n + 1)!, therefore,
f (n+1) (θ)
K= ,
(n + 1)!
or
f (n+1) (θ)
f (x) − pn (x) = (x − x0 )(x − x1 ) . . . (x − xn ) . (3.7)
(n + 1)!
(Recall that θ will depend upon the choice of x.) Notice the similarity be-
tween the form of this error function and that associated with the Taylor
series expansion given by equation (3.2).
Example 3.2.2 (Calculator/Computer)
We shall determine an upper bound on the error associated with the cubic
approximation for exp(x) which was derived in example 3.2.1, i.e.
p3 (x) = 0.995196 + 0.999049x + 0.547885x2 + 0.176152x3 .
From equation (3.7) with n = 3 we have that
|f (x) − p3 (x)| ≤ |(x + 1)(x + 13 )(x − 31 )(x − 1)|M/4!,
where M = sup |f iv |, x ∈ [−1, 1], and f (x) = exp(x). (We define the supre-
mum as follows: if M ≥ |f iv | and ∀ L ≥ |f iv |, M ≤ L then M is the
supremum.) We now examine the first four terms and note that for values √of
1
x between −1 and 1 this takes a maximum value of 0.19753 at x = ± 3 5.
(See figure 3.4.) Therefore, since |f iv (x)| = |ex | ≤ e, for x ∈ [−1, 1], the error
function e3 (x) satisfies |e3 (x)| ≤ 0.0224, which is the required error bound. In
fact this is a severe overestimate since the maximum error is actually 0.00481
but even a crude bound is better than none. (Recall that the corresponding
bound on the cubic Taylor series approximation was |R3 (x)| ≤ 0.113.)
56 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
0.4
0.3
0.2
0.1
-0.1
the polynomial through these points, display the resulting polynomial in the
bottom window and then display the prompt Plot: function. By changing
the prompt you can plot the approximation or the error between the function
and the computed polynomial. Use the editor to change the interpolation
points and investigate how the approximation and its error change. Now
return to the editor and add another two points and then determine quartic
polynomial approximations for exp(x), x ∈ [−1, 1].
Exercise 3.2.4 (Computational) Use the program APPROX with the option
Method: Interpolation to determine the cubic polynomial approximations
for the function exp(x), x in [−1, 1], by interpolation at −1, −0.5, 0.5 and
1. Investigate how the error between the interpolating polynomial and the
function changes as the tabular points change. Investigate how the error
changes as the number of tabular points increases. Find the polynomial
of smallest degree which approximates this function to an accuracy of at
worst 0.001 throughout this interval for interpolation points which are equally
spaced. Investigate how the error function behaves for different interpolation
points.
exp(x) ≈ 1 + x + 21 x2 + 61 x3 , (3.8)
and
exp(x) ≈ 0.99520 + 0.99905x + 0.54788x2 + 0.17615x3 , (3.9)
are both cubic approximations. The first is a truncated Taylor series, the
second is an interpolating polynomial which agrees with exp(x) at the points
−1, − 31 , 13 and 1. We can compare these functions as shown in figure 3.2
but it is more informative to look at their respective error functions shown
in figure 3.3. If we were to obtain another interpolating cubic approximation
by adjusting the tabular points we could plot the associated error function
in the same way and compare it. In general we need to find a polynomial,
pn (x), which minimizes the maximum value of the error function, i.e. for any
other polynomial of degree n, qn (x) say, the minimax error ǫn satisfies
ǫn = max |f (x) − pn (x)| ≤ max |f (x) − qn (x)| for all x ∈ [a, b].
2.5
2.0
x
1.5 e
1.0
0.5
e1 (x) = exp(x) − ax − b.
exp(x) − a = 0.
60 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
This equation has only one solution, therefore only one of x0 , x1 and x2
is a turning point. Let this be x1 . Accordingly, e1 (x) will have maximum
absolute value at both x0 and x2 neither of which will be turning points.
Therefore,
exp(−1) + a − b = E
exp(x1 ) − ax1 − b = −E
exp(1) − a − b = E
which gives three equations in the four unknowns; the unknown point x1 , the
coefficients a and b, and the error E. However, at x1 the error function has
a turning point and so
de1
(x1 ) = exp(x1 ) − a = 0,
dx
which gives a fourth equation. The solution of these equations is:
(exp(1) − exp(−1))
a = = 1.17520119,
2
x1 = loge (a) = 0.161439361,
(exp(x1 ) + exp(1) − ax1 − a)
b = = 1.26427905
2
E = exp(1) − a − b = 0.278801586.
0.2
0.1
-0.1
-0.2
which is shown in figure 3.2. The associated error, as shown in figure 3.3,
has the correct number of minima and maxima but they are of different
magnitude. The internal stationary points of the error function occur at
approximately −0.7, 0 and 0.8, therefore let us solve the equations (3.10)
with x1 = −0.7, x2 = 0 and x3 = 0.8. This produces the linear equations
1 −1 1 −1 1 a0 exp(−1)
2 3
1 −0.7 0.7 −0.7 −1 a exp(−0.7)
1
1 0 0 0 a2
1
=
exp(0)
2 3
1 0.8 0.8 0.8 −1 a3
exp(0.8)
1 1 1 1 1 E exp(1)
The error e3 (x) = exp(x) − q3 (x) is shown in figure 3.7, together with the
computed value for E, and has turning points at −0.687312, 0.045814 and
0.727528 in addition to the maxima at −1 and +1. (These extremum points
are denoted by P , Q, R, S and T ). As we seek a minimax approximation
of degree 3 the error should have 3+2 alternating extrema of the same mag-
nitude. From figure 3.7 we can see that the error function does have five
extrema which have alternating sign but they are of different magnitude.
If the extrema were of the same magnitude then E would be the minimax
error ǫ3 for exp(x). We could now substitute these five points into (3.10)
to determine another approximation and hence iteratively refine our cubic
3.3. MINIMAX POLYNOMIALS 63
0.004
0.002
-0.002
-0.004
Not available
not been plotted prior to this point then pressing RETURN will display it
in the graphics window, otherwise, change the prompt to Plot: approxi-
mation and compare the computed approximation with the function. It is
likely that the function and the computed approximation are very close; the
error between them can be examined by using the option Plot: error. For
this example you should obtain figure 3.7 together with a dotted line which
denotes the value for E in equations (3.10). The coefficients of the computed
approximation can be examined by using prompt Option: tabulate, which
in this case gives the cubic (3.11). Notice that the error associated with this
approximation has maximum values at the points P , Q, R, S and T . We can
select these points to be used in the next stage of the Remes algorithm by us-
ing the prompt Option: edit/inspect points and then return to Option:
calculate coeffs to determine the next approximation. (Only the x coordi-
nates are required, therefore, it is unnecessary to enter the y coordinates.)
This process can then be repeated until convergence is obtained.
Exercise 3.3.2 (Computational) Use the program APPROX to carry out
the next iteration of the Remes algorithm using the minima/maxima of the
error function associated with the cubic approximation (3.11).
Exercise 3.3.3 (Computational) Use the program APPROX with the op-
tion Remes/minimax to determine the quartic minimax approximation
for exp(x), |x| ≤ 1.
Exercise 3.3.4 (Computational) Use the program APPROX with the op-
tion Remes/minimax to determine the quartic minimax approximation
for log(1 + x), |x| ≤ 21 . Try different starting polynomial approximations to
examine the speed at which this algorithm converges to the required minimax
approximation.
At each stage of the Remes algorithm it is to be expected that the maxi-
mum value of the associated error function will be reduced but it will certainly
be an upper bound on the minimax error ǫn for polynomial approximations
of order n. In fact we can also produce a lower bound for the minimax error
ǫn .
Theorem 3.3.2. (de la Vallee Poussin).
Given that qn is an nth degree polynomial approximation for a function
f (x), x ∈ [a, b], and xi , i = 0, . . . , n+ 1, are any n+ 2 points in [a, b] such that
a ≤ x0 < x1 < . . . < xn+1 ≤ b where the error function en (x) = f (x) − qn (x)
3.3. MINIMAX POLYNOMIALS 65
min
x
|en (xi )| ≤ ǫn ≤ max |en (x)|,
i x∈[a,b]
0.0053526 ≤ ǫn ≤ 0.0059120.
(The lower bound is taken over the points −1, −0.7, 0, 0.8 and 1.0 and occurs
at x = −0.7. The upper bound is over the whole of the interval and occurs at
x ≈ 0.7275.) If these bounds are sufficiently close to each other then there is
little point in carrying out another iteration of the Remes algorithm. What
is more, the lower bound tells us that if we wish to have a minimax error
less than 0.0053526 then we must construct a polynomial approximation of
higher order.
The Remes algorithm is based upon the selection of exactly n + 2 al-
ternating minima/maxima from a given error function, but it is possible to
obtain an error curve for a polynomial approximation of degree n which has
more than n + 2 such points. (Although pn (x) cannot have more than n − 1
turning points f (x) − pn (x) could have any number.) In this case we sim-
ply select n + 2 values where the error function has alternating minima and
maxima, the remainder are discarded, the only proviso is that we must take
the largest minima/maxima amongst the points we select. We will not give
details of how to find the relevant minima/maxima but in general this is
usually accomplished by a linear search along the error curve, not by differ-
entiating. However, the location of suitable points by hand is a relatively
simple procedure as the following example demonstrates.
Example 3.3.4 (Analytical)
Let us suppose that we have constructed a quadratic approximation for some
function and the error curve looks like figure 3.9. The minimax approxima-
tion should have four alternating minima and maxima, this curve has five.
We need to select four of the values shown in order to proceed with the
Remes algorithm; in this case we take x1 , x2 , x3 and x4 as these are alter-
nating minima and maxima and the maximum error is at x4 . The point x0
will no longer be used.
66 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
x x
1 3
x x x
0 2 4
T1
0.5
T2
-0.5
T3
-1.0
If this is the case then the dominant term in the error when this series is
truncated after n + 1 terms will be cn+1 Tn+1 and as Tn+1 has exactly n + 2
equal and opposite minima and maxima we should obtain an approximation
close to the minimax! We must now justify the expansion (3.16) of any
function in terms of Chebyshev polynomials. First of all, if the series (3.12)
converges for x ∈ [−1, 1] then so will any re-arrangement of its terms, but this
is just what the Chebyshev expansion is. Therefore, if (3.12) converges then
so will (3.16). The next stage is to find an expression for the coefficients
cj , j = 0, 1, . . .. This turns out to be quite straightforward because the
Chebyshev polynomials possess an orthogonality property, i.e.
π, i = j = 0
1 Ti (x)Tj (x)
Z
q dx = π2 , i = j > 0 .
−1 2
(1 − x )
0, i=6 j
3.4. CHEBYSHEV APPROXIMATION 69
where the symbol denotes that the first coefficient is 21 c0 . All the coefficients
′
and so on. The function given by c1 T1 (x) + c3 T3 (x) is compared with f (x) =
3x(1 − x2 )1/2 in figure 3.11 and the associated error is shown in figure 3.12.
Notice that the error function has six alternating minima/maxima, but of
unequal size. Although we have approximated f by a cubic, the six min-
ima/maxima cause no problems because the coefficient c4 is zero and there-
fore the quartic approximation for f is given by a cubic.
1.5
1.0
0.5
-0.5
f HxL -1.0
-1.5
0.4
0.2
-0.2
-0.4
2.5
2.0
1.5
Linear 1.0
Quadratic 0.5
Finally, we use the recurrence relation (3.13), in which case all the terms
except the last on the right-hand side vanish; this last term is u0 since T0 = 1.
This technique would not be used to produce a explicit expression for a
Chebyshev series as a power series but to evaluate the Chebyshev series at a
particular point.
Example 3.4.3 (Calculator)
Evaluate the Chebyshev series
cn Tn + cn+1 Tn+1 + . . .
is closely bounded above by the single term |cn Tn |, provided the coefficients
tend to zero sufficiently rapidly. (See Fox and Parker (1972).) However,
|Tn (x)| ≤ 1 and so we can bound the truncation error by the single term |cn |.
1
Strictly speaking amongst all expansions in terms of ultra-spherical polynomials for
which the associated weight function is w(x) = (1 − x)−p , p = 21 gives Chebyshev polyno-
mials, p = 0 gives Legendre polynomials.
74 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
which has minimax error ǫ3 = 0.0055216. From this we can see that c4 is a
reasonable estimate for ǫ3 .
differs from Qn by a term an 2(1−n) Tn (x) which has exactly n + 1 equal and
opposite minima/maxima of size an 2(1−n) and is therefore the minimax ap-
proximation of this degree.
Example 3.4.5 (Analytical)
Construct a quadratic minimax approximation for the polynomial
Q3 (x) = 1 + x + x2 + x3 .
and
This form of expressing the minimax polynomial has several advantages over
an expansion in simple powers of x, not the least of which is that the coef-
ficients will be numerically smaller which means that the evaluation of this
expression will be less prone to rounding errors. Any other linear combination
of Chebyshev polynomials will have a larger maximum error bound than that
given by the minimax error ǫn = max |en (x)|. Let us assume that we have
obtained an approximation for the minimax polynomial in terms of a Cheby-
shev series and that we have determined (n+2) points at which the associated
error function has alternating minima and maxima, x0 ≤ x1 ≤ . . . ≤ xn+1 .
Now we determine a better polynomial approximation, qn (x), as
e3 (x) = exp(x) − c0 T0 − c1 T1 − c2 T2 − c3 T3 .
3.4. CHEBYSHEV APPROXIMATION 79
0.004
0.002
-0.002
-0.004
We use the
extrema
of the Chebyshev polynomial T4 (x) which are given by
1
xi = cos 4 iπ , i = 0, 1, 2, 3, 4. (See page 75.) This gives the points x0 = −1,
√ √
x1 = − 12 2, x2 = 0, x3 = 12 2 and x4 = 1. (Compare these values with
those used in example 3.3.3). We now solve the five linear equations
exp(xi ) − c0 T0 (xi ) − c1 T1 (xi ) − c2 T2 (xi ) − c3 T3 (xi ) = (−1)i E,
i = 0, 1, 2, 3, 4.
These equations can be rewritten as
1 −1
√ 1 −1 √ 1 c0 exp(−1)
√
1 12 2 0 − 12 2 −1 c1 exp(− 12 2)
1 0√ −1 √0 c2 =
1 exp(0)
√
1 1 1
1 −2 2 0 2
2 −1
c 3
exp( 2
2)
1 1 1 1 1 E exp(1)
and produce the cubic Chebyshev polynomial
Q3 (x) = 1.266066 + 1.130321T1 + 0.271540T2 + 0.044880T3 (3.24)
which has the error function shown in figure 3.14. This function has maxi-
mum absolute value 0.00583 but the corresponding value of E is 0.005474.
We see that this cubic is not minimax but we can repeat this process to
improve it. We can also compare this cubic with the first four terms of the
Chebyshev series for exp(x) given by
exp(x) ≈ 1.266066 + 1.130318T1 + 0.271495T2 + 0.044337T3
which has a maximum error of 0.00607.
80 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
Exercise 3.4.6 (Computational) Write out the equations in the next step of
the Remes algorithm for determining the cubic Chebyshev minimax approx-
imation for exp(x). Solve the corresponding linear equations and investigate
whether the resulting cubic is minimax.
Exercise 3.5.1 (Analytical) Show that the sets of functions given in examples
3.5.1 and 3.5.2 are orthogonal. In each case, assuming that there exists an
expansion of the form,
n=∞
X
f (x) = cn φn (x), (3.25)
n=0
For the moment let us ignore the problem of whether this infinite series
converges and try instead to plot it. Of course we cannot add in all the
terms but for the moment let us see what happens if we include the first
four, five or perhaps six terms. Now we have a finite expression which we
can plot. The result is shown in figure 3.15.
1.0
0.5
-0.5
-1.0
At first sight it appears that as we include more and more terms the sum
of this series of continuous functions appears to be a function which is not
differentiable at various points. Conversely, we seem to be able to write the
sawtooth waveform as a sum of eminently smooth functions. We can now
ask whether this is always the case. However, before we answer this question
let us take a closer look at the graph drawn in figure 3.15, in particular near
the peaks. By plotting in more detail we see that the graph in fact does
not change direction sharply but does so in a smooth way (see figure 3.16).
However as we include more and more terms the magnification required to see
this smooth change becomes greater and greater and to all practical purposes
the sawtooth wave is generated.
Let us now turn to a general function f (x), |x| ≤ 1, and examine the
conditions under which it is possible to write this function as an expansion
of the form
a0 n=∞
X
f (x) = + (an cos(nπx) + bn sin(nπx)) , |x| ≤ 1, (3.27)
2 n=1
where the ′ denotes that the first coefficient is given by 12 a0 . The expan-
sion (3.27) is called the Fourier series expansion of f (x). If we are given a
3.6. FOURIER SERIES EXPANSIONS 83
-0.95
-1.00
-1.05
-1.10
-1.15
-1.20
function f (x) for a ≤ x ≤ b then we can always map the function to the
interval |x| ≤ 1 by a suitable linear transformation. Alternatively, if the
function is defined on an infinite interval then since the sine and cosine func-
tions are periodic, i.e. sin(x + 2π) = sin(x) and cos(x + 2π) = cos(x), we
shall require that the function f (x) is also periodic. Therefore, without loss
of generality we shall only consider functions which are defined for |x| ≤ 1.
Next we consider the notion of sectional continuity.
Definition 3.6.1. Let f (x) be a function which is continuous at all points
of a finite interval a ≤ x ≤ b except possibly at a set of points a ≤ x1 <
. . . < xp ≤ b. If f has a finite limit as x approaches the ends of each interval
(xi , xi+1 ), i = 1, . . . , p − 1, from its interior then f is said to be sectionally
continuous.
Definition 3.6.2. A function is said to have a right- (left-) hand derivative at
a point if
f (x + h) − f (x)
lim
h→0 h
exists, where h tends to zero through negative (positive) values.
Example 3.6.1
The functions shown in figure 3.17 are simple examples of sectionally contin-
uous functions.
1.5
1.0
0.5
-0.5
-1.0
-1.5
where
Z 1
an = f (x) cos(nπx) dx, n = 0, 1, 2, . . .
−1
Z 1
bn = f (x) sin(nπx) dx, n = 1, 2, . . .
−1
The function editor can be used to input this function piece by piece. To
return to the function editor press ESCAPE and then when the prompt
3.6. FOURIER SERIES EXPANSIONS 85
shows Action: Continue press RETURN which should produce the option
Function: as set. (Notice that the current function and range is shown in
the bottom window.) By pressing any key except RETURN cycle through
the options available at this time until it reads Function: inspect/edit and
then press RETURN again. This will display another prompt which you will
need to alter to Change f(x) before pressing RETURN. A flashing cursor
will appear in the bottom window and we can type in the value 1 which
now becomes the current function. The next stage is to split the range using
the prompt Split section, recall that we need to split the range at x = 0.
The bottom window will now show that we have the function f (x) = 1
for negative values of x as the first of two sections. Next we shall amend
the second section using the prompt Next section and then cycling until
the prompt reads Change f(x), in which case we can set the function to
f (x) = 0. Finally, we can plot the current function using the option Plot
function. (There are several other options available at this level which
can be used to move between the various sections of the function, edit or
delete sections, or add other sections if required.) At this point the required
function should be plotted; notice in particular the form of the curve near the
discontinuous point x = 0. This is caused by using only a finite number of
points when plotting. Now quit the function editor and return to the prompt
Method: Fourier and then press RETURN again. Again at this point
there are various options available which include supplying the coefficients
manually, reading them from file, storing the current coefficients in a file
and calculating the coefficients corresponding to the current function. This
last option requires the evaluation of equation (3.27) and in general this is
carried out numerically. Therefore, accept the option calculate coeffs and
then set the upper limit on the number of terms to four. After a short pause,
whilst the coefficients are being calculated, the option will return to Option:
calculate coeffs. Again cycle through the possibilities available at this point
and plot the function, approximation and error. Increase the number of terms
included in the series and compare the approximations which are determined.
Notice that each approximation takes the value 21 at the origin which agrees
with the value given by theorem 3.6.1. How do you account for the behaviour
of the Fourier series at ±1?
2 f HxL
-4
-6
2.5
2.0
1.5
Rational approximation
1.0
0.5
0.01
-0.02
-0.03
-0.04
-0.05
Exercise 3.7.1 (Computational) Use the program APPROX with the option
Method: Rational to determine the R2,2 (x) approximation for exp(x),
|x| ≤ 1, at equally spaced points. Compare the results obtained by using
other points. Also compare the results with R3,1 and R1,3 approximations
for this function.
Exercise 3.7.2 (Computational) Use the program APPROX to construct
rational approximations, Rmn (x), for exp(x), |x| ≤ 2, for which m and n are
less than 4. Compare them with the cubic minimax approximation.
As with polynomial approximation of functions based on interpolation
at a set of points, rational approximation can suffer from induced ill condi-
tioning. This can be overcome to some extent by using rational Chebyshev
approximations and further details are given by Fox and Parker (1972). How-
ever, there are other problems which can occur.
(i) The equations (3.28) may turn out to be singular.
Example 3.7.3 (Analytical)
Let us consider a rational approximation, R1,1 (x), for the cubic function
f (x) = x3 − 3x2 + 4x,
which is determined by interpolation at x = 0, x = 1 and x = 2. The
equations (3.28) become
1 0 0 a0 0
1 1 −2 a1 = 2
1 2 −4 b0 8
90 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
for which
f (1) = 1, f (2) = 3, f (3) = 3, f (4) = 4.
The rational function R2,1 determined from equation (3.28) is
x2 − 2x x(x − 2)
R2,1 (x) = =
x−2 x−2
= x, if x 6= 2.
Example 3.7.6
We shall construct a Padé approximation for exp(x) which is of the form
R1,1 , i.e.
a0 + a1 x
exp(x) ≈ ,
b0 + x
where the coefficients a0 , a1 and b0 are selected so that the function and
the approximation have as many derivatives as possible equal when x = 0.
Firstly, we re-arrange this expression to give
(b0 + x) exp(x) = a0 + a1 x (3.29)
then when x = 0, i.e.
b0 exp(0) = b0 = a0 . (3.30)
Next we differentiate equation (3.29) to obtain
(b0 + x) exp(x) + exp(x) = a1
and then set x = 0 to produce
b0 + 1 = a1 . (3.31)
As we have three parameters at our disposal we can repeat this procedure
once more to give
(b0 + x) exp(x) + exp(x) + exp(x) = 0
at x = 0 which gives b0 = −2. Substituting back into equation (3.31) gives
a1 = −1 and into equation (3.30) to get a0 = −2. Therefore, we have the
Padé approximation
−2 − x
exp(x) ≈ .
−2 + x
This approximation can be compared with the rational approximation ob-
tained by interpolation at x = −1, x = 0 and x = 1 in example 3.7.2 which
was
−2.1639534 − x
R1,1 (x) = .
−2.1639534 + x
The errors associated with these two rational approximations is shown in
figure 3.21.
Exercise 3.7.5 (Analytical and Computational) Compare the rational approx-
imation R1,3 , R2,2 and R3,1 determined by interpolation at equally spaced
points in (−1, 1) with the corresponding Padé approximation.
3.8. APPLICATIONS AND CONCLUSIONS 93
0.06
0.04
0.02
-0.04
-0.06
-0.08
n=∞
Bn Tn∗ (t2 ),
X
cos(x) =
n=0
where Tn∗ is the nth modified Chebyshev polynomial and the coefficients
An and Bn are given in table 3.2.
n An Bn
0 1.276278962 0.472001216
1 −0.285261569 −0.499403258
2 0.009118016 0.027992080
3 −0.000136587 −0.000596695
4 0.000001185 0.000006704
5 −0.000000007 −0.000000047
Accuracy. For |x| ≤ 12 π the absolute error in the evaluation of sin(x) does
not exceed 0.25 × 10−8 and for cos(x) it does not exceed 0.42 × 10−7 .
Example 3.8.2 (Analytical)
Evaluate sin(1.4). The required argument lies within (− 12 π, 21 π) therefore we
set t = (2 × 1.4)/π ≈ 0.891267681. Next we use the recurrence relations
Then
T0∗ (t2 ) = 1, T1∗ (t2 ) = 0.588716160,
T2∗ (t2 ) = −0.306826567, T3∗ (t2 ) = −0.949983676,
T4∗ (t2 ) = −0.811714915, T5∗ (t2 ) = −0.005755699.
from which we obtain sin(1.4) ≈ 0.985449729 which has absolute error 0.78×
10−9 . Similarly, cos(1.4) ≈ 0.169967143 which has absolute error 0.36×10−10 .
Exercise 3.8.1 (Calculator) Evaluate sin(1.0) using the algorithm described
in example 3.8.1.
Example 3.8.3 (Analytical)
The evaluation of exp(x).
3.8. APPLICATIONS AND CONCLUSIONS 95
Accuracy. If −1 < x < 1 then the maximum relative error in exp(x) is less
than 0.21 × 10−15 , otherwise it is less than 0.43 × 10−15 .
Example 3.8.4 (Analytical)
The natural logarithm is evaluated using a rational approximation.
2. Determine an integer n such√ that 2n−1 ≤√x ≤ 2n and then put r = 2−n x
( 21 ≤ r < 1). Set u = (r − 12 2)/(r + 12 2) and find
1+u
v = loge
1−u
20790 − 21545.27u2 + 4223.9187u4
!
≈ u
10395 − 14237.635u2 + 4778.8377u4 − 230.41913u6
then
1
loge (x) ≈ n − 2
loge 2 + v.
Accuracy. The maximum absolute error in loge (x) is less than 1.02 × 10−10 .
Exercise 3.8.2 (Calculator/Computational) Use the algorithms given in ex-
amples 3.8.3 and 3.8.4 to evaluate exp(3.456) and loge (3.456).
96 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS
1. If x = 0 then return 0.
1
2. Let x = 162p−q f , where p is an integer, q = 0 or 1 and 16
< f < 1 then
√ q
x = 16p 4−q f.
√
3. Take as a first approximation for f
(0.14605 + 1.8342f )
y0 = 16p 4−q .
(0.98026 + f )
Exercise 3.8.3
√ (Calculator) Use the algorithm outlined in example 3.8.5 to
determine 1.76. Square the result and hence estimate the error. Compare
the error with the bound which is given.
3.8. APPLICATIONS AND CONCLUSIONS 97
Of course the first thing to do was to make a grand survey of the country she
was going to travel through. “It’s something like learning geography”, thought
Alice, as she stood on tiptoe in hopes of being able to see a little farther.
Lewis Carroll.
4.1 Introduction
In Chapter 2 the problem of fitting a function through a set of data points was
considered. It was shown that as the number of points increases then poly-
nomial approximation becomes more oscillatory. In order to overcome this
problem the concept of spline interpolation was introduced whereby lower
order polynomials were employed. In this chapter we shall consider an alter-
native approach; to do this consider the following example.
Example 4.1.1 (Analytical)
Newton’s law of cooling states that the rate at which a body loses heat is
proportional to the difference between the temperature of the body and the
surrounding ambient temperature T0 . Let T be the temperature at time t;
then we can write
dT
= −K(T − T0 ),
dt
where K is some constant, which can be integrated to give
99
100 CHAPTER 4. LEAST SQUARES APPROXIMATION
100
80
60 A=95, k=0.4
40
A=90, k=0.5
20
0 1 2 3
0 1 2 3
where y(ti) is the value determined from the particular choice of the param-
eters and yi is the observed value at ti . In order to obtain the ‘best possible’
fit we could attempt to select the parameters B and K to minimize the sum
of squares, S, of the errors. In this case
This function has a turning point where ∂S/∂B = ∂S/∂K = 0 which gives
two linear equations for K and B. Solving these equations produces the least
squares approximation for the given data as
or equivalently
y = c0 + c1 x, (4.6)
which minimizes some overall measure of the difference between the tabular
values yj and the corresponding y(xj ) as provided by the approximating
function. There is no unique way of providing a measure of the discrepancy
between yj and y(xj ). For example, we could use the sum of the magnitudes
of the errors to compare different values of c0 and c1 , i.e.
j=m
X j=m
X
|y(xj ) − yj | = |c0 + c1 xj − yj |. (4.7)
j=0 j=0
of your own which is not write protected.) Exit from this set of options by
using the prompt Data: quit and when the option shows Method: Linear
press RETURN. Select the prompt Option: interactive fitting and a de-
fault line will appear on the screen together with the current sum of squares
of deviations (SSD) as given by equation (4.8). The position and slope of the
current line can be changed by using the cursor keys.
1. ↑ ↓ shift the current line with respect to the axis y = 0.
3. < > increase or decrease the increment by which the line is changed.
As the line is moved the sum of squares of deviations (SSD) is changed
and displayed in the top window. It is also possible to examine the current
values of the coefficients in equation (4.8), c0 and c1 , by selecting the prompt
Option: edit/inspect coeff. Try to adjust the line to minimize the sum
of squares of deviations.
Exercise 4.2.1 illustrates some of the problems in finding a least squares
approximation by trial and error; therefore, we will now consider a more di-
rect approach. The functional S(c0 , c1 ), given by equation (4.8), has turning
points whenever
∂S ∂S
= = 0, (4.9)
∂c1 ∂c0
therefore, necessary conditions for a minimum are
j=m
X
xj (c0 + c1 xj − yj ) = 0,
j=0
j=m
X
(c0 + c1 xj − yj ) = 0.
j=0
For the example in section 4.1 these equations reduce to the linear equations
! ! !
6 14 c0 20.269701
= .
3 6 c1 10.640651
y(x) = c0 + c1 x + c2 x2 + . . . + cn xn
j=m
and those of the vector b by bk = j=0 φk (xj )yj . Notice that A is indepen-
P
1.5
Linear
Quadratic
1.0
0.5
then all the off-diagonal entries of A vanish. If this is the case then the
functions φi (x), i = 0, . . . , n, are said to be orthogonal with respect to the
points xj , j = 0, . . . , m. Under this condition the normal equations reduce
to a diagonal system and the coefficients of (4.11) are given by
Pj=m
φi (xj )yj
ci = Pj=0
j=m 2
, i = 0, . . . , n. (4.18)
j=0 φi (xj )
i=n
!2
Z 1 X
S(c0 , . . . , cn ) = w(x) f (x) − ci φi (x) dx, (4.21)
−1 i=0
and Z 1
bk = w(x)φk (x)f (x) dx.
−1
then the normal equations are particularly simple and the coefficients ci ,
i = 0, . . . , n, are given by
R1
−1 w(x)φi (x)f (x) dx
ci = R1
2
. (4.23)
−1 w(x)φi (x) dx
Then from equation (4.23) the least squares coefficients are given by
Exercise 4.3.1 (Analytical) Show that for the coefficients given in example
4.3.1 the functional S(c0 , c1 , . . . , cn ) given in equation (4.21), has minimum
value
1 f 2 (x)
Z
q dx − 12 π(2c20 + c21 + . . . + c2n ).
−1 (1 − x2 )
a0 k=n
X
f (x) ≈ + (ak cos kx + bk sin kx)
2 k=1
is a least squares approximation for f (x), with unit weight, in |x| ≤ π. (The
question of the convergence of the Fourier series as n → ∞ will not be
discussed here. For a full discussion see Churchill (1963).)
equations given by
i=n
X j=m
X j=m
X
φk (xj )φi (xj ) ci = φk (xj )yj , k = 0, . . . , n, (4.24)
i=0 j=0 j=0
but if the basis functions are orthogonal with respect to the tabular points,
i.e.
j=n
X
φk (xj )φi (xj ) = 0, i 6= k, (4.25)
j=0
110 CHAPTER 4. LEAST SQUARES APPROXIMATION
then the coefficients in the least squares approximation are given by the
simple form
Pj=m
φi(xj )yj
ci = Pj=0
j=m 2
, i = 0, . . . , n. (4.26)
j=0 φi (xj )
Therefore, given any function f (x) we can construct the least squares ap-
proximation to it if (m + 1) points, (xj , f (xj )), j = 0, . . . , m, are known such
that equation (4.25) is satisfied. Conversely, if we have m + 1 points which
satisfy this condition then the interpolating polynomial constructed in this
way will be the least squares approximation.
In order to illustrate this approach consider the Chebyshev approximation
given by
i=n
X ′
f (x) ≈ ai Ti (x), −1 ≤ x ≤ 1, (4.27)
i=0
′
where the denotes the fact that the first coefficient is halved. Then if the
tabulation points xj , j = 0, . . . , m, are selected to be the zeros of Tm+1 , i.e.
!
(2j + 1) π
xj = cos , j = 0, . . . , m, (4.28)
(m + 1) m
′′
where the denotes that both the first and last terms in the summation, for
any r or s, are to be halved. In this case the coefficients in equation (4.27)
are given by
2 j=m
X ′′
ai = f (xj )Ti (xj ). (4.30)
m j=0
This is the discrete Chebyshev least squares approximation. If n = m, i.e.
the number of tabulation points is equal to the number of coefficients, then
′ ′′
the in equation (4.27) is replaced by for an exact fit. Notice that the
tabulation points xj are not equally spaced.
1
See Cheney (1966).
4.4. DISCRETE LEAST SQUARES APPROXIMATION 111
The maximum difference between these functions is 5.045 × 10−2 and the
sum of squares of deviations is 3.835 × 10−3 .
We can compare the coefficients of a Chebyshev series and those of the
discrete Chebyshev least squares as follows. Recall that the coeffcients of the
Chebyshev series, ci , are given by
2Zπ
ci = f (cos θ) cos iθ dθ
π 0
and if we apply the composite trapezium rule to this integral with m + 1
points we find
2 k=m
X ′′ kπ
ci ≈ f (cos θk ) cos iθk , θk = ,
m k=0 m
2 k=m
X ′′
= f (xk )Ti (xk ) = ai ,
m k=0
from (4.30), i.e. the Chebyshev series of f (x) is the Fourier series of f (cos(x)).
Exercise 4.4.1 (Computational) Load the program LSQ and change the
prompt to Select function. When the current option shows Function:
disabled change it to enabled and press RETURN. Now change the option
to Function: inspect/edit and change the function to ex , |x| ≤ 1. Quit
this section of the program and change the prompt to Select data. Use
the option Data: standard grid to select a uniform grid of four points and
then quit. The program should now return to the prompt Method: Linear;
change the option to Polynomial and fit a polynomial of degree 2. Com-
pare the result with a Chebyshev least squares fit of the same degree. What
112 CHAPTER 4. LEAST SQUARES APPROXIMATION
do you deduce? Increase the number of points and repeat the comparison.
Return to the option Select data and use the zeros of T4 (x) as data points,
construct a least squares fit for ex , |x| ≤ 1, based on these points and then
compare it with your results for equally spaced points.
Exercise 4.4.2 (Computational) Construct an interpolating polynomial ap-
proximation for ex , |x| ≤ 1, which passes through six uniformly spaced points.
(Use INTERP). Compare the result with least squares polynomial fits for
polynomials of degree 3, 4 and 5. Repeat this exercise using the zeros of
T6 (x). What do you conclude?
Exercise 4.4.3 (Computational) Construct the minimax cubic polynomial ap-
proximation for ex , |x| ≤ 1, using the Remes algorithm in APPROX. Com-
pare it with least squares Chebyshev approximations of order 3,4 and 5.
Estimate the relative efficiency of determining these approximations.
Chapter 5
Integration
113
114 CHAPTER 5. INTEGRATION
j=n
X
= αj f (xj ) + En , (5.6)
j=0
where
Z b
αj = Lj (x) dx, (5.7)
a
1
Z b j=n
(x − xj ) f (n+1) (θ) dx.
Y
En = (5.8)
(n + 1)! a j=0
The approach now is to select the points xj in order to minimize the error En .
Notice that the quadrature formula (5.6) involves (2n + 2) parameters; the
interpolation points xj and the coefficients αj , j = 0, . . . , n, but that these
values are not independent. For any arbitrary choice of interpolation points,
usually called the abscissa, the coefficients, which are called the weights,
are determined from equation (5.7). As a result we should be able to make
the quadrature formula exact for polynomials of degree n since n + 1 points
5.1. SIMPLE QUADRATURE 115
Z b j=n
X
f (x) dx = αj f (xj ) + En (5.9)
a j=0
and then select values for all the xj ’s and αj ’s to make this a method of order
higher than n + 1. Such formulae are called Gaussian quadrature methods
and they will be considered in section 5.3.
Accept the prompts Function: as set and Select data by pressing RE-
TURN. The prompt will now change to Option: integrate. Notice that in
the graphical window three equally spaced points are placed on the default
integrand x5 . This is confirmed in the bottom window where N = 3 is dis-
played. Furthermore, as three points are available it is possible to construct
an interpolating polynomial of degree 2 which is confirmed by n = 2 in the
top window. Now press RETURN. The bottom screen will display the esti-
mate for the integral which has been determined as the Current Estimate
together with an estimate of the quadrature error as determined by approxi-
mating equation (5.8). It is possible to examine the interpolating polynomial
which has been used to approximate the integrand by changing the prompt
to Option: plot, pressing RETURN and then accepting the option Plot:
approximation. In addition, the difference between the integrand and the
approximating polynomial can be highlighted using the option Plot: shade
and the error can be displayed using the option Plot: error.
116 CHAPTER 5. INTEGRATION
Exercise 5.1.1 (Computational) Load the program QUAD with the default
problem
Z 1
x5 dx
0
using a uniform grid of five points1 . (Hint: Use the option Select function
to change the integrand.) Return to the option Select data and then select
Data: plot &/or edit and change the interpolation points to be at x =
0, ±0.5, ±1. Quit the data editor and select the prompt Option: integrate.
An estimate for the value of the integral will now be determined based on
these points together with an estimate of the quadrature error. Notice that
the previous estimate remains visible in order that you can compare it.
Exercise 5.1.2 (Computational) Repeat example 5.1.2 for other sets of five
interpolation points and try to determine the best possible choice, i.e. mini-
mize the computed error estimate.
b−x x−a
f (x) ≈ p1 (x) = f (a) + f (b), (5.10)
b−a b−a
1
Some computers treat the expression EXP(−X 2 ) as EXP((−X)2 ) whereas we require
EXP(−(X)2 ).
5.2. NEWTON–COTES METHODS 117
which is the Lagrange polynomial through (a, f (a)) and (b, f (b)). Therefore,
Z b Z b
f (x) dx = p1 (x) dx + E1
a a
f (a) Z b f (b) Z b
= (b − x) dx + (x − a) dx + E1
(b − a) a (b − a) a
= 12 (b − a)[f (a) + f (b)] + E1 .
This is the simple trapezium rule. We may use equation (5.3) to determine
the error, E1 , in this approximation as
b b f ′′ (θ(x)) f ′′ (θ) b
Z Z Z
e1 (x) dx = (x − a)(x − b) dx = (x − a)(x − b) dx
a a 2! 2! a
(5.11)
where the mean value theorem for integration has been used to simplify the
integral. Integrating the last term gives
(b − a)3 ′′
E1 = − f (θ), (5.12)
12
where a ≤ θ ≤ b. The accuracy of the trapezium rule is proportional to
the cube of the interval width, provided the integrand has a bounded second
derivative, and if we require higher accuracy then it is necessary to include
further interpolation points.
Exercise 5.2.1 (Analytical) Show that by sub-dividing the interval (a, b) into
two sub-intervals such that x0 = a, x1 = 21 (a + b), x2 = b and then replacing
the integrand by a Lagrangian polynomial approximation of degree 2 we
obtain
Z b Z x2
f (x) dx = p2 (x)dx + E2
a x0
1
= 6
(b − a) [f (x0 ) + 4f (x1 ) + f (x2 )] + E2 ,
h5 iv
E2 = − f (θ), a ≤ θ ≤ b.
90
where h = 21 (b − a).
118 CHAPTER 5. INTEGRATION
The trapezium rule will integrate any polynomial of degree ≤ 1 exactly since
the error is proportional to f ′′ , whereas Simpson’s rule will integrate any
cubic without error. In general a quadrature formula is said to have degree
of precision p if it will integrate all polynomials of degree ≤ p without error.
The trapezium rule has degree of precision 1, Simpson’s rule has degree of
precision 3. By introducing further points we can increase the degree of
precision further.
Example 5.2.1
The Newton–Cotes closed formulae for the integral ab f (x) dx are given by
R
the following. Divide the interval (a, b) into n sub-intervals such that a = x0 ,
b = xn , xj = a + jh, j = 0, . . . , n, h = (b − a)/n then xx0n f (x) dx is given
R
in table 5.1. Notice that for n even the degree of precision is n + 1, but for
n odd it is n and this is generally the case (see Isaacson and Keller (1966)).
Accordingly, even formulae are usually preferred.
1
n=1 2
h[f (x0 )
+ f (x1 )]
1 3 ii
2 point The trapezium rule: p = 1 : E1 = − 12 h f (θ)
1
n=2 3
h[f (x0 )
+ 4f (x1 ) + f (x2 )]
3 point Simpson’s 13 rd rule: p = 3: E2 = − 90
1 5 iv
h f (θ)
3
n=3 8
h[f (x0 )
+ 3f (x1 ) + 3f (x2 ) + f (x3 )]
4 point Simpson’s 38 th rule: p = 3 : E3 = − 80 3 5 iv
h f (θ)
2
n=4 45
h[7f (x0 )
+ 32f (x1 ) + 12f (x2 ) + 32f (x3 ) + 7f (x4 )]
8
5 point Milne’s rule: p = 5 : E4 = − 945 h7 f vi (θ)
The formulae given in example 5.2.1 are termed closed since they use
the end points of the interval of integration; however, it is useful to define
formulae which do not have this property.
Example 5.2.2
The Newton–Cotes open formulae are given as follows. We divide the interval
(a, b) into n + 2 intervals so that a = x−1 and b = xn+1 , i.e. xj = a + (j + 1)h,
5.3. GAUSS QUADRATURE FORMULAE 119
3
n=1 2
h[f (x0 ) + f (x1 )]
2 point p = 1 : E1 = 43 h3 f ′′ (θ)
4
n=2 3
h[2f (x0 ) − f (x1 ) + 2f (x2 )]
14 5 iv
3 point p = 3 : E2 = 45 h f (θ)
Newton–Cotes formulae to this integral even though the integral is well de-
fined because the integrand is undefined at x = 0. However, there is no such
difficulty in applying open formulae which do not require the integrand at
x = 0.
As the number of points increases we obtain formulae with higher preci-
sion but unfortunately the resulting methods become unsuitable. For exam-
ple, the nine-point closed Newton–Cotes formula is given by
Z x9
4h
f (x) dx ≈ 14175 [989f (x0 ) + 5888f (x1 ) − 928f (x2 ) + 10496f (x3 )
x0
−4540f (x4 ) + 10496f (x5 ) − 928f (x6 ) + 5888f (x7 ) + 989f (x8 )].
This formula has large coefficients which alternate in sign and this can lead
to large cancellation errors unless special care is taken.
which have degree of precision > n + 1. Such formulae are not restricted
to the interval (−1, 1), since given any other interval we can simply map it
to this range. (The reason for using this particular range will become clear
later.) We will now select the (2n + 2) parameters, i.e. the weights, αj , and
the abscissae xj , j = 0, . . . , n, to make the formula as accurate as possible.
Example 5.3.1 (Analytical)
For n = 1 equation (5.13) becomes
Z 1
f (x) dx = α0 f (x0 ) + α1 f (x1 ) + E1 . (5.14)
−1
As we are looking for a method which has degree of precision > 2 the error
E1 must vanish if f (x) = 1. Therefore,
Z 1
1 dx = 2 = α0 + α1 . (5.15)
−1
We will now show that if we use the (n + 1) zeros of φn+1 (x) as the abscissa
in equation (5.13) then we can obtain degree of precision 2n + 1. To do this
it is necessary to show that φn (x) has exactly n real zeros in the interval
(−1, 1). Firstly, φ0 is a constant C 6= 0, therefore,
Z 1 Z 1
0= w(x)φn (x)φ0 (x) dx = C w(x)φn (x) dx
−1 −1
and since w(x) ≥ 0 this implies that φn (x) has at least one change of sign
in (−1, 1) and hence has at least one zero. Recall that φn is a polynomial
of degree n and by the Fundamental Theorem of Algebra has at most n real
zeros. Let us assume that the number of real zeros of φn in (−1, 1) is j < n,
and that these zeros are at zi , i = 1, . . . , j, where −1 < z1 < z2 < . . . <
zj < 1. With no loss in generality we may assume that φn > 0 in (−1, z1 ),
φn < 0 in (z1 , z2 ), and so on. Now define P (x) = (−1)j i=j i=1 (x − zi ); then
Q
which contradicts (5.19). Hence all n zeros of φn (x) lie within (−1, 1).
We have already seen examples of orthogonal polynomials in Chapter 3.
In particular the Legendre polynomials are given by P0 (x) = 1, P1 (x) = x,
and
which have weight w(x) = 1. From above we see that Pn+1 (x) has n + 1 real
zeros in the interval (−1, 1), and we will now show that if we select these
zeros as the abscissa we obtain a quadrature formula of the form (5.13) which
has degree of precision 2n + 1. To show this let P (x) be any polynomial of
degree ≤ 2n + 1, then there are polynomials Q(x) and R(x) of degree ≤ n
such that
P (x) = Q(x)Pn+1 (x) + R(x).
Furthermore, we can express Q(x) as a linear combination of Legendre poly-
nomials of degree ≤ n, i.e.
i=n
X
Q(x) = di Pi (x)
i=0
hence
Z 1 i=n
X Z 1
Q(x)Pn+1 (x) dx = di Pi (x)Pn+1 (x) dx = 0
−1 i=0 −1
and so
Z 1 Z 1 Z 1 Z 1
P (x) dx = Q(x)Pn (x) dx + R(x) dx = R(x) dx. (5.21)
−1 −1 −1 −1
where the integration is exact since R(x) is a polynomial of degree less than
n. Finally, notice that if the interpolation points are selected to be the zeros
of Pn+1 (x) then
and so
Z 1 j=n
X
P (x) dx = αj P (xj )
−1 j=0
using three uniformly spaced points. (This is the default problem for the
program QUAD.) Press ESCAPE and change the prompt to Select data
and then press return. Now use a standard grid of three points which are
the zeros of the required Legendre polynomial. This produces an estimate
for the integral of 0.1666669 compared with the exact value of 16 . Recall that
in example 5.1.1 it takes six equally spaced points to evaluate this integral
exactly; here we have used only three. Notice also that the function which
is used to approximate the integrand differs from x5 by as much as 0.207
and yet the estimate for the integral is very good. The reason for this is
given by equation (5.23). Using three points we have n = 2 and so the error
term will involve f vi (θ) which is identically zero for this integrand. (Notice
that the program automatically deals with the problem of mapping the zeros
of Legendre polynomials, usually defined on the interval ±1, to a suitable
range.)
Example 5.3.2 (Analytical)
Let us find the Gauss–Legendre quadrature method based on two points, i.e.
n = 1. The second Legendre polynomial is
P2 (x) = 12 (3x2 − 1)
2
See Froberg (1987).
124 CHAPTER 5. INTEGRATION
q q
which has zeros at x0 = − 13 and x1 = 1
3
; these points are used as the
abscissa. The weight α0 is given by
1 x − x1
Z
α0 = dx
−1 x0 − x1
q
1
Z 1 (x − 3
)
= q dx
1
−1 −2 3
s 1
1 x2 1
= − q −x
2 1 2 3
3 −1
= 1
n xj αj
1 ±0.5773502692 1.0000000000
2 0 0.8888888889
±0.7745966692 0.5555555556
3 ±0.3399810436 0.6521451549
±0.8611363116 0.3478548451
4 0 0.5688888889
±0.5384693101 0.4786286705
±0.9061798459 0.2369268851
rather disappointing but the reason for the low accuracy is clear if we sketch
the integrand. From figure 5.1 the integrand has a relatively large peak at
x = 0 which is ignored by Gaussian formulae which use an even number
of points, i.e. n is odd. However, if we use the Gaussian formula with
n = 4, i.e. five points we obtain the estimate 0.746832, which is correct
to four decimal places. Using the program QUAD applied to this integral
directly, i.e. without changing the range of integration, and using the zeros
of the second Legendre polynomial as abscissa produces an estimate for the
integral of 0.7465947. Using the zeros of P4 produces an estimate of 0.7468245
whereas using four equally spaced points gives 0.7469923.
Exercise 5.3.1 (Computational) Load the program QUAD and estimate the
integral
Z 1
exp(−x2 ) dx
0
using two, three, and four equally spaced points. In each case examine the
interpolating polynomial which is constructed and compare it with the inte-
grand. Notice that the program computes an error bound between the inte-
grand and the interpolating polynomial and also an estimate of the quadra-
ture formula. Repeat this exercise using the zeros of the corresponding Leg-
endre polynomials.
126 CHAPTER 5. INTEGRATION
1.0
0.8
0.6
0.4
0.2
-2 -1 0 1 2
w(x) = exp(−x2 ): −∞ ≤ x ≤ ∞.
Hn (x) = (−1)n exp(x2 )(dn /dxn )(exp(−x2 )).
5.3. GAUSS QUADRATURE FORMULAE 127
n xj αj
1 0.585786 0.853553
3.414213 0.146447
2 0.415775 0.711093
2.294280 0.278518
6.289945 0.010389
3 0.322547 0.603154
1.745746 0.357419
4.536620 0.038888
9.395071 0.000539
4 0.263560 0.521756
1.413403 0.398667
3.596426 0.075942
7.085810 0.003612
12.640801 0.000023
n xj αj
1 ±0.707107 0.886227
2 0 1.181636
±1.224745 0.295409
3 ±0.524648 0.804914
±1.650680 0.081313
4 0 0.945309
±0.958572 0.393619
±2.0201829 0.019953
128 CHAPTER 5. INTEGRATION
1 3 ′′
where h = (xi − xi+1 ) and E1i = − 12 h f (θi ), xi ≤ θi ≤ xi+1 . If we set
xi = a + ih, with h = (b − a)/N, then equation (5.24) becomes
Z b 1
f (x) dx = h[f (a) + f (a + h)] + E10
a 2
1
+ h[f (a + h) + f (a + 2h)] + E11 +
2
..
.
1
+ h[f (b − h) + f (b)] + E1N −1
2
1
= h[f (a)+2f (a+h)+2f (a+2h)+. . .+2f (b−h)+f (b)]
2
+ECT ,
(The mean value theorem for integrals has been used to replace θi , i =
0, . . . , N − 1, by θ with a ≤ θ ≤ b. See Appendix A.) However, Nh = (b − a)
and so
1 2
ECT = − 12 h (b − a)f ′′ (θ). (5.25)
5.4. COMPOSITE QUADRATURE 129
Notice that the error of the composite trapezium rule is O(h2 ) compared with
O(h3 ) of the simple trapezium rule, but that the h in the composite rule can
be made small by introducing more sub-intervals whereas with the latter it
is the full interval of integration. By systematically increasing N we should
be able to reduce the quadrature error.
Example 5.4.2 (Computational)
Consider the simple trapezium rule for the following integral:
Z 1
exp(x2 ) dx = 1
2
[f (0) + f (1)] + E1
0
= 12 [1 + 2.7182818] + E1
= 1.8591409 + E1 .
We can improve upon this estimate for 01 exp(x2 ) dx by using the composite
R
trapezium rule. For example, loading the program INTEGR, for which
the default problem is this inegral, we obtain the results given in table 5.6.
Notice that the program gives an estimated error bound which is determined
by estimating an upper bound for |f ′′ | using finite differences3 . In all cases
this appears to be an overestimate of the quadrature error which is also given
in table 5.6. The actual error in determining this integral is given in the final
column of this table.
Notice that the errors in table 5.6 decrease by a factor of four whenever the
step size is halved, thus confirming that the error in the composite trapezium
rule is proportional to h2 . Clearly, as h tends to zero the value produced by
the quadrature formula appears to converge and by systematically reducing
h we should obtain an accurate result. Alternatively, we can estimate the
3
See Appendix B.
130 CHAPTER 5. INTEGRATION
R1
Table 5.6: Composite trapezium rule for 0 exp(x2 ) dx
or
1
h2 ≤ × 10−6
e
h ≤ 0.6065 × 10−3 .
From this we conclude that N = 1/h ≥ 1649 intervals. Using this value for
N gives
Z 1
exp(x2 ) dx = 1.462651912 ± 0.00000017.
0
1
The error of this composite Simpson’s rule is ECS = − 180 h4 (b − a)f iv (θ),
a ≤ θ ≤ b.
Exercise 5.4.2 (Computational) Load the program INTEGR and estimate
the integral 01 exp(−x2 ) dx using the option Trapezium. Use the error term
R
where
T (h) = 21 h[f (a) + 2f (a + h) + . . . + f (b)].
If we halve h then we have
I =T 1
2
h − ( h)2 (b
1 1
12 2
− a)f ′′ (θ′ ). (5.28)
5.5. ROMBERG INTEGRATION 133
Now multiply equation (5.28) by four and subtract (5.27) from the result.
We obtain
1 2
3I = 4T ( 12 h) − T (h) − 12
h (b − a)[f ′′ (θ′ ) − f ′′ (θ)]. (5.29)
If θ′ ≈ θ then
1 1 1 1 1
3
4T 2
h − T (h) = T 2
h + 3
T 2
h − T (h)
values for the trapezium rule in table 5.7. Let us now apply Richardson’s
method to the results in the second column. For example, applying equa-
tion (5.29) with h = 0.25 we have
h i
T ( 21 h) + T ( 12 h) − T (h)
1
3
1.469712276 − 1.490678861
= 1.46971276 + = 1.462723415.
3
Likewise, we can apply this technique to the remaining entries in the second
column of table 5.7. Notice that we can achieve 6 correct decimal places
using only 32 points instead of the 1649 predicted in example 5.3.1.
R1
Table 5.7: Richardson’s method applied to 0 exp(x2 ) dx
h4
I − S(h) = (b − a) f iv (θ), a ≤ θ ≤ b. (5.30)
180
134 CHAPTER 5. INTEGRATION
Show that h i
16S( 21 h) − S(h) S( 21 h) − S(h)
= S( 21 h) + (5.31)
15 15
gives a better approximation for I.
Richardson’s method can be applied in a similar way to any other quadra-
ture rule but it can be developed to produce a systematic extrapolation pro-
cedure. Let us assume that I(h) is a result produced by some quadrature
rule when applied to an integral I and that the error associated with this
approximation is given by
Now we multiply (5.33) by 2p and then subtract (5.32) from the result. This
produces
2p I( 21 h) − I(h) 1 I( 12 h) − I(h)
= I( 2
h) + (5.36)
2p − 1 2p − 1
has degree of precision ≥ p. This process can be repeated and is called
Romberg extrapolation.
Example 5.5.2 (Analytical)
It can be shown that if T (h) is the result of applying the trapezium rule to
estimate an integral I = ab f (x) dx then
R
R1
Table 5.8: Romberg extrapolation applied to 0 exp(x2 ) dx
provided f has a bounded second derivative we can eliminate the term Ah2
to obtain equation (5.44) with p = 2, i.e.
h i
T (h, 12 h) = T ( 21 h) + 1
3
T ( 12 h) − T (h) ,
I = T (h, 21 h) + B ′ h4 + C ′ h6 + . . .
-0.2
-0.3
-0.4
-0.5
-0.6
-0.7
√
Figure 5.2: The integrand x log(x)
where g(x) is sufficiently smooth, the error in the trapezium rule, T (h), is
3 3 5 5
I − T (h) = Ah 2 log(h) + Bh 2 + Ch2 + Dh 2 log(h) + Eh 2 + . . . .
exact answer?
Exercise 5.5.3 (Analytical) If T (h) and S(h) are results produced by the
trapezium and Simpson’s method show that
h i
S( 21 h) = T ( 12 h) + 1
3
T ( 12 h) − T (h) .
Furthermore, show that the first extrapolation of Simpson’s rule, and there-
fore, the second extrapolation of the trapezium rule, produces the closed
Newton–Cotes rule for four points given in table 5.1. (The resulting method
is called Simpson’s 83 th rule.)
5.6. ADAPTIVE INTEGRATION 137
the prompts Simpson’s 1/3rd and Simpson’s 3/8th. Confirm that these
values are the first, second and third columns of the corresponding Romberg
table.
10
2 4 6 8 10
i.e. !1/4
180ǫ
h≤
|f iv |max
in which case we will be forced to use a small value for h even though the
fourth derivative is very small except near x = 5. In order to overcome this
difficulty we will now permit the sub-division of the range of integration and
use non-uniformly spaced abscissa. Let Iab (h) be an approximation for the
integral I = ab f (x) dx which has degree of precision p, i.e.
R
but in most cases |f (p+1) |max is unknown. In order to overcome this we sub-
divide the range of integration (a, b) into (a, c) and (c, b), where c = 21 (a + b),
then
p+1
Iac − Iac ( 21 h) = A 1
2
h f (p+1) (θ1 )
p+1
Icb − Ibc ( 12 h) = A 1
2
h f (p+1) (θ2 ),
hp+1 (p+1) ′
I − Iac ( 21 h) − Icb ( 21 h) = Af (θ ).
2p
If we subtract equation (5.38) from this then
However,
Z Z
T0 dx = 1 dx = x + C0 = T1 (x) + C0 ,
Z Z
T1 dx = x dx = 21 x2 + C1 = 14 T2 (x) + C1′ ,
and if we knew the Chebyshev coefficients of the function f (x) we could find
the required integral. Notice that the above series will converge much faster
than the Chebyshev series for the integrand because of the term r 2 − 1 in the
denominator. Unfortunately, the determination of the Chebyshev coefficients
is time consuming and in general will involve integrae, if
then
|I − (Iac ( 12 h) + Icb ( 21 h))| ≤ ǫ
as required. If not we reconsider each sub-interval independently and use a
criterion of 12 ǫ in each sub-interval.
Example 5.6.2 (Computational)
If we use the program INTEGR with the option Simpson 1/3rd to eval-
uate the integral
1
Z 10
dx
0 (x − 5)2 + 0.1
then 512 intervals are required to ensure that two successive estimates agree
to eight decimal places. Using the option Gaussian 4 point Rule 128 panels
of four points are needed to achieve the same accuracy and so there is little to
be gained in using this method. However, using the adaptive procedure with
a relative error tolerance of 10−8 only 161 function evaluations are required.
Now we multiply (5.33) by 2p and then subtract (5.32) from the result.
This produces
2p I( 12 h) − I(h) 1 I( 21 h) − I(h)
= I( 2
h) + (5.44)
2p − 1 2p − 1
R1
Table 5.9: Romberg extrapolation applied to 0 exp(x2 ) dx
which has error proportionarect to four decimal places using the method
of Clenshaw and Curtis? If the trapezium rule were applied directly to this
integral how many intervals are required to determine a result which is correct
to four decimal places? Which method is the most efficient and why?