alternate num analysis notes

Upload: ian-waffy-gambo-martin

Post on 08-Apr-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Alternate Num Analysis Notes

    1/142

    Chapter 1

    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 NumericalAnalysis. A Computer Illustrated Text (CIT) consists of a software packagewhich is integrated with a textbook. It is intended that the reader should,ideally, use the software frequently whilst working through the book, as thetextbook 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 canbe used on its own, for example, to generate demonstration programs or tosolve 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 areeither included in the text or supplied on the disc. However, the nature ofthe subject means that no short introductory textbook can include all thematerial required and so explicit references are given to other sources thatmay 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 performedmore easily if the disc associated with A Simple Introduction to NumericalAnalysis 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 amicrocomputer but no knowledge of programming languages is needed, only

    1

  • 8/7/2019 Alternate Num Analysis Notes

    2/142

    2 CHAPTER 1. GETTING STARTED

    an ability to enter data when required.

    1.2 The software: an example

    The software associated with this book was originally intended for the BBCmicrocomputer, but, other versions of the software will be available, and allinstructions in the main part of the book are machine independent. However,in this section the features of the software will be introduced using the BBCversion of the program INTERP. You may prefer to skip now to Chapter 2as it is always possible to refer back to this chapter.

    Users of machines other than the BBC microcomputer can usefully follow

    this section through, making only minor obvious variations. They will alsofind that their disc contains some introductory remarks which point out themost important of such variations.

    Figure no longer available

    Figure 1.1: Initial screen setting of INTERP

    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 shouldput up a menu on the screen giving a list of all the programs which areavailable. (On a network system it will be necessary to ask for advice re-garding the appropriate loading instructions.) On some screens you may findthat either the top line or the bottom line is obscured; this can be overcomeby selecting the menu option Screen adjustment and then following thescreen instructions to obtain the best setting. Once the menu is visible usethe 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 likefigure 1.1. The screen has been split into three windows. The top windowis used for dialogue, the bottom window contains current settings and the

    middle window is used either for graphic or tabular display. Initially, theoption prompt should read

    Select data options

    where the data option is in inverse colours and a flashing cursor appearsunder the dof data. The data option enables you to input, edit, plot

  • 8/7/2019 Alternate Num Analysis Notes

    3/142

    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, thekey marked can be used to cycle forwards and the key marked to cyclebackwards through the options available. An option is selected by pressingRETURN, but do not press RETURN just yet.

    Whenever the program is loaded a default set of data is supplied andplotted; 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 describedlater. In the bottom window the current ranges of plotting are given togetherwith the number of data points (N). It is also possible to input data usingthe 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 whichmay be changed by the user will have its existing setting left unchanged if theuser presses RETURN or ENTER. Where options need to be selected, thealternative may be viewed by pressing the SPACE bar repeatedly until thedesired option is showing, then selected by pressing RETURN or ENTER.

    The purpose of the program INTERP is to construct smooth curvesthrough given data points. However, in this chapter we will only be interestedin how data can be input, examined, edited, plotted and stored. Therefore,ensure that the Select option reads data options and then press RETURNto select this option. A new prompt should appear:

    Data: from keysCycle through the options available at this point by pressing the SPACE barrepeatedly. If at any time you wish to quit press ESCAPE which will takeyou back to the following prompt:

    Action: Continue

    Try it and see. Since we wish to continue, accept the default setting bypressing RETURN; the program should then advance to the Select dataoptions prompt as above. Press RETURN again and we arrive back at theData prompt.

    Select the option Data: from keys by pressing RETURN. Next wehave 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 pressingRETURN. Additional points can either be input in tabular or graphical form.Pressing RETURN again will select the option

    Data input format: tabular

  • 8/7/2019 Alternate Num Analysis Notes

    4/142

    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 aregiven in the top window. Try adding the point (0.95, 0.95) by typing ineach coordinate followed by RETURN. If you make a mistake you can deletecharacters using the DELETE key before correcting them but each coordinateis terminated by RETURN. To quit press Q. This process will return theprogram to the option Data: from keys after sorting the tabular pointsinto ascending order. Now press RETURN to accept the current option ofsupplying data from the keyboard and then press RETURN again to retainthe existing points. The program now advances to the option Data inputformat: tabular. Press the SPACE bar to change this to Data input

    format: graphical and then press RETURN. All the current data pointsare displayed on the default graphical settings. These can be changed at thispoint using the Graph data option. Cycle through the options available,superimpose, clear - same axes and clear - new axes. For example, thelast of these options allows the user to set up different sets of axes. Whenthis option is shown press RETURN. The flashing cursor now appears in thebottom window and it is possible to alter the range of each axis in turn. Forthe moment accept the default settings by pressing RETURN each time theflashing cursor moves to a new position in the bottom window. When all therequired 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 pressX 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. Nowpress Y and input a y coordinate of 0.0 followed by RETURN. The flashingcursor in the middle window is now at the position (0.05, 0.0). In order toadd this point to the table press RETURN again, this will be confirmed byan increase in N in the bottom window. To try out method (ii), first selectthe Add point option again by pressing RETURN. Additional points cannow be added by moving the cursor with the arrow keys. The increment by

    which the cursor moves is controlled by the (decrease)keys and is displayed in the top window. Note that the two methods canbe combined; for example, you may set the x coordinate and then adjust itusing the cursor control keys. The x and y values are open to change up tothe moment when you press RETURN.

    The other graphical editing options are Change point, Delete point

  • 8/7/2019 Alternate Num Analysis Notes

    5/142

    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 cursorjump to the next point in ascending order (right or up arrow), or descendingorder (left or down arrow). When the cursor flashes on the point you wish tochange press RETURN, and the situation is exactly as it was with the Addpoint option. The Delete point option also begins by asking you to selecta point; once you have selected it you are asked to confirm that you wish todelete the current point. The Quit editor option takes the program backto the option level from which the editor was invoked.

    At any stage of data input it is possible to view the current set of datapoints by escaping from the current option and selecting the option

    Data: tabulateAn option to send any tabulation to a connected printer is available whichreminds 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 fileWherever possible data files created by one program can be used as input forany other when it is appropriate, but if an inappropriate data file is requestedthen the program will display a suitable error message. Five simple data filesare provided on the program disc1, as follows:

    DATASIN

    SPLINERAMP

    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. Youwill 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

    1With BBC discs data files have a prefix D.; MS-DOS files will have a .DAT extension.

  • 8/7/2019 Alternate Num Analysis Notes

    6/142

    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.

    1.3 The software: general remarks

    The previous section demonstrated how to supply simple numerical data andalso the use of cyclical prompts. Although the actual prompts and optionswill vary from program to program the repeated use of the RETURN keywill always accept the current default setting and consequently the first time

    a program is run results from the default parameters should agree with thosegiven in the text. Throughout the programs the use of ESCAPE will alwaysreturn the program to the Action prompt from which the program can berestarted or terminated as required. The ultimate panic button on the BBCmodel B is the BREAK key; this should only be pressed in emergencies. ForMS-DOS versions BREAK and CTRL/C have the same effect as ESC.

    An alternative to numeric input is to supply data by means of expressions.For example, at any point where the exponential number e is required it ispossible to type the string EXP(1). However, if the string supplied cannot beevaluated then a message such as bad input or error evaluating functionwill be given. Such an error will not necessarily be fatal to the program: a

    suitable error message will be given and usually the user will be invited totype in the item again. Some errors cannot be detected until later in thecalculation: these will also give rise to a suitable message, but it will act likean ESC in that the program will jump to the Action prompt.

    1.4 Screen dumps

    It is frequently useful to obtain a permanent copy of the screen display forlater examination. Programs running under MS-DOS may use the key la-

    belled Print Screen, or an equivalent such as Prnt Sc, to obtain hardcopies of the screen, provided that a suitable printer has been attached andhas been selected by using the GRAPHICS command (consult your manual).For BBC microcomputer users, there is, unfortunately, no universal standardfor printers or the software to drive them. Therefore, rather than supply aprogram which gives a direct screen-to-printer dump we have provided a fa-

  • 8/7/2019 Alternate Num Analysis Notes

    7/142

    1.5. FINAL REMARKS 7

    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 providetheir own software to make a hardcopy on any printer available. The detailsof this process will depend on the hardware available and the system beingused. For the BBC microcomputer to which a disc drive is connected it ispossible to obtain a screen dump as follows. Whenever a dump option isshown 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 ina 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 theprogram PRNTDMP which is available from the main menu. Selectingthis program gives a self-explanatory dialogue for the user to follow.

    One final advantage to this method of obtaining screen dumps is that itis possible to keep a permanent copy of screen images and recall them to thescreen for future demonstration. For BBC users this can be carried out fromwithin the program or else in intermediate command mode. In the lattercase if the file DMPF were the name given to a dumpfile created in mode 4then it can be recalled to the screen, but not printed, using the command

    MODE 4:*LOAD DMPF

    1.5 Final remarks

    If you want to use numerical methods in more complicated programs, asopposed to learning about them, and you wish to write programs in BBCBASIC, then A Mathematical Toolkit: Numerical Routines with Applicationsin Engineering, Mathematics and the Sciences (Harding 1986) contains sub-routines which can be built into your own programs. For graphical output,

    Graphs and Charts on the BBC Microcomputer (Harding 1982) contains alibrary of subroutines for this purpose. It is intended that in the near fu-ture the CIT series will contain a Mathematical and Graphical Toolkit forMS-DOS machines.

  • 8/7/2019 Alternate Num Analysis Notes

    8/142

    8 CHAPTER 1. GETTING STARTED

  • 8/7/2019 Alternate Num Analysis Notes

    9/142

    Chapter 2

    Interpolation

    Interpolation - the art of reading between the lines.

    2.1 Polynomial interpolation

    We shall begin our discussion of interpolation by considering the followingproblem.

    Example 2.1.1

    In an experiment the yield of a chemical species is recorded as a functionof the concentration of another reagent which is present. As it is impossibleto vary the concentration of the reagent continuously, only a finite set ofdifferent values can be tabulated. Let us assume that the following resultshave been obtained.

    Table 2.1: Data for example 2.1.1

    Concentration of reagent Yield0.10 0.099560.30 0.396460.50 0.588130.70 0.772100.90 0.89608

    9

  • 8/7/2019 Alternate Num Analysis Notes

    10/142

    10 CHAPTER 2. INTERPOLATION

    We can now ask questions like:

    1. Is it possible to estimate the yield when the reagent has a concentrationof 0.51?

    2. How accurate is such an approximation going to be?

    3. Are the results which are produced sensitive to perturbations or errorsin the tabular values? Clearly, we would like small changes in the datato produce small changes in the results. If this is the case then theproblem is said to be well-conditioned.

    4. Is it possible to determine a reagent concentration which gives a pre-scribed yield, for example, find a concentration such that the yield is0.5? (This is the inverse problem to (1)).

    The problem of attempting to estimate intermediate values from a giventable is called interpolationand is the basis for the following sections.

    In order to provide a background for understanding the methods describedin this chapter we shall begin by considering the problem of obtaining non-tabular values in elementary ways. We assume that we are given a tableof values (xi, yi), i = 0, . . . , n, and that we need to determine a non-tabular

    point (x, y). For example, let us suppose that we wish to find an approximatevalue which corresponds to x = 0.51 in table 2.1. Perhaps the simplest wayis to join together successive points as shown in figure 2.1. In particular,between x = 0.5 and x = 0.7 we have the straight line shown in figure 2.2and we can find the coordinates of the point C by linear interpolation.

    From figure 2.2 the point C has as its y coordinate y(0.5)+CD. However,by similar triangles,

    CD

    AD=

    BE

    AE

    therefore,

    CD = AD BEAE

    = 0.01 (0.77210 0.58813)(0.7 0.5) = 0.00920,

    to five significant figures. (Only five significant figures are quoted here sincethe original tabular values are only given to this accuracy.) Hence, y(0.51)is approximately 0.58813 + 0.00920 = 0.59733.

  • 8/7/2019 Alternate Num Analysis Notes

    11/142

    2.1. POLYNOMIAL INTERPOLATION 11

    0.5 0.5 1.0 1.5

    0.5

    0.5

    1.0

    1.5

    Figure 2.1: A simple linear interpolant for table 2.1.1

    A

    B

    C

    x

    ED

    0.5 0.7

    Figure 2.2: Linear interpolation between two points

  • 8/7/2019 Alternate Num Analysis Notes

    12/142

    12 CHAPTER 2. INTERPOLATION

    Figure not available

    Figure 2.3: The derived function for figure 2.1.1

    Instead of using the similar triangle argument above we could have de-termined an explicit expression for the equation of the straight line joiningthe points A and B in figure 2.2. This line will be of the form

    y = c0 + c1x,

    and passes through the points (0.5, 0.58813) and (0.7, 0.77210). Therefore,

    0.58813 = c0 + 0.5c1

    and0.77210 = c0 + 0.7c1.

    Eliminating c0 gives c1 = (0.77210 0.58813)/(0.7 0.5) = 0.91985, whichis 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 issimple 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 fittedfunction has a strange derived function. Between each pair of consecutivedata points the fitted function is linear and therefore has constant slope. Thederivative of the piecewise linear function shown in figure 2.1 will therefore bepiecewise constant and look like the function shown in figure 2.3. In order toovercome this problem we could use higher order functions rather than linearones. 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 generalparabolic function is y = a + bx + cx2, and the three coefficients can bedetermined by substituting the three points into this equation to producethree 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

  • 8/7/2019 Alternate Num Analysis Notes

    13/142

    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 arbitrarypolynomials, 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 uniquepolynomial 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 , andtry to fit such a polynomial. Let Pn be the interpolating polynomial

    Pn(x) = c0 + c1x + c2x2 + . . . + cnx

    n.

    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 + 1unknown coefficients cj , j = 0, . . . , n. These linear equations may then besolved using, for example, Gaussian elimination with partial pivoting. (SeeHarding and Quinney (1986).)

    Example 2.1.2For the five values in table 2.1 we can fit a unique polynomial of degree 4,i.e.

    P4(x) = c0 + c1x + c2x2 + c3x

    3 + c4x4.

    Evaluating this polynomial at the five data points in table 2.1 gives the

    following system of linear equations:

    1 0.1 0.12 0.13 0.14

    1 0.3 0.32 0.33 0.34

    1 0.5 0.52 0.53 0.54

    1 0.7 0.72 0.73 0.74

    1 0.9 0.92 0.93 0.94

    c0c1c2c3c4

    =

    0.099560.396460.588130.772100.89608

    . (2.2)

    Using Gaussian elimination, the solution of this system of equations is

    [0.159796, 3.164656, 6.499406, 8.274375, 3.901563]T

    which produces the interpolating quartic

    P4(x) =0.159796 + 3.164656x 6.499406x2 + 8.274375x3 3.901563x4.(You can easily check these results using the program GAUSS from Hardingand Quinney (1986).) Evaluating P4 at the given points produces the valuesin table 2.2. (Later we shall provide an alternative simpler method.)

  • 8/7/2019 Alternate Num Analysis Notes

    14/142

    14 CHAPTER 2. INTERPOLATION

    Table 2.2: Polynomial interpolation applied to table 2.1.1

    x y P4(x) P4(x) y0.1 0.09956 0.0995598 2.4 1070.3 0.39646 0.3964597 2.8 1070.5 0.58813 0.5881297 3.1 1070.7 0.77210 0.7720996 3.9 1070.9 0.89608 0.8960794 5.7 107

    0.5 0.5 1.0 1.5

    0.5

    0.5

    1.0

    1.5

    Figure 2.4: Quartic polynomial for table 2.1.1

    Notice that the values in the third column of table 2.2 are displayed toseven decimal places even though the data are only given to five. This isto emphasize the fact that whenever this process is carried out it will beprone 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 isalways the case will be examined later. The function obtained, P4(x), isshown 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) byP4(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 beunwise 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 excessof 0.9 where one might expect a monotonic increasing function.

  • 8/7/2019 Alternate Num Analysis Notes

    15/142

    2.1. POLYNOMIAL INTERPOLATION 15

    Example 2.1.3

    The interpolating polynomial which passes through the points (2, e4

    ),(1, e1), (0, 1), (1, e1), and (2, e4) is shown in figure 2.5. These val-ues are obtained from the function exp(x2) which is always positive butas figure 2.5 shows the same is not true of the interpolating polynomial forvalues of x in the intervals (2, 1) and (1, 2)! Furthermore, as the numberof points increases the interpolating polynomial behaves less like the func-tion exp(x2). This is called Runges problemand will be discussed in moredetail in the next chapter. (See also exercises 2.1.4 and 3.4.4.)

    2 1 1 2

    0.5

    0.5

    1.0

    1.5

    Figure 2.5: Runges problem: see example 2.1.3

    Exercise 2.1.2 (Computational) The program INTERP is an interactiveprogram which can be used to construct interpolating polynomials through aset of data points. The values in table 2.1 are set up as the default tabulatedpoints. Therefore, load the program INTERP and when the screen shows

    Select data options

    press the space bar which will change the option to Select method. PressRETURN and the option prompt will change to

    Method: Construct interpolating polyn.

    You can cycle through the various methods by repeatedly pressing any char-acter key except RETURN; now select the option above by pressing RE-TURN, which will calculate the required interpolating polynomial passingthrough the points in table 2.1. First of all, you are allowed the option of

  • 8/7/2019 Alternate Num Analysis Notes

    16/142

    16 CHAPTER 2. INTERPOLATION

    selecting the graphics parameters which are used to plot the resulting poly-

    nomial. For the moment select the optionGraph data: superimpose

    The interpolating polynomial is now drawn in the graphics window and theactual polynomial is given in the bottom window. (The coefficients are lim-ited to five significant figures by the space available to display them.) Wecan 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 example2.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 fourvalues 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 byquitting the current option by pressing Q and then selecting the option Editdata. Press RETURN in order to accept the current plotting parametersand then cycle through the edit options available by pressing any key butRETURN. (Recall that you can cycle backwards using the key marked .)When the current option is Delete point press RETURN and use the cursorkeys 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 andthen press RETURN. Once again cycle through the options available untilthe 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 andplotted. 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 Addpoint. If this is the case press RETURN, if not cycle until it is and thenpress RETURN. The cursor in the graphics window should now be flashing

    at the point which was previously deleted; this point can be added back tothe table simply by pressing RETURN. Other points can then be deleted toconsider the effect of fewer points in the table. How does the selection of thefour points influence the interpolated value?

    Exercise 2.1.4 (Computational) Use the program INTERP to obtain fiveequally spaced points in the interval (5, 5) from y = exp(x2) and then

  • 8/7/2019 Alternate Num Analysis Notes

    17/142

    2.1. POLYNOMIAL INTERPOLATION 17

    determine a suitable interpolating polynomial (see example 2.1.3). You will

    need to take the default prompt Select data option and then Data: fromkeys remembering to clear the existing data before using the Data inputformat: tabular option. For example, the point (5, exp(25)) can beinput as the tabular values X(1) = 5 and Y(1) =EXP(25). When youhave constructed the interpolating polynomial through the points you haveselected, try adding other points and see how the results compare. Whathappens as the number of points increases/decreases? Why is it better tohave an even number of points? Investigate what happens with non-equallyspaced points.

    In general, given n+1 tabular points, (xi, yi), i = 0, . . . , n, we can proceed

    as above and determine the coefficients of the interpolating polynomial Pn(x)by solving a system of linear equations given by equation (2.1), or equivalently

    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 Aare aij = x

    ji , 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. (Seeequations (2.2) for a simple example with n = 4.) This system of equationswill 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 todo this we consider the determinant ofA; this matrix is called a Vandermondematrix and it is possible to show that it has determinant

    i=1,...,n, j

  • 8/7/2019 Alternate Num Analysis Notes

    18/142

    18 CHAPTER 2. INTERPOLATION

    determinant may be small, i.e. the equations are nearly singular, and hence

    the solution may be inaccurate. This type of inaccuracy is usually calledinherent ill-conditioning and is a fundamental part of the problem, i.e. in-dependent of the method of solution. In order to demonstrate the problemswhich 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 thepoints in table 2.3. Using the program INTERP produces the interpolatingpolynomial 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 quarticpolynomial is shown in figure 2.7. Compared with the original interpolationquartic it is clear that this problem is inherently ill-conditioned.

    Table 2.3:

    x y0.00 2.000.95 1.001.00 1.05

    1.05 1.002.00 0.00

    Example 2.1.4 gave an illustration of a problem which was inherentlyill-conditioned, i.e. a small change in the tabular values leads to a muchlarger change in the interpolating polynomial. This was caused by severalof the tabular values being close together, resulting in a system of linearequations which were nearly singular. We can also investigate the possibility

    of errors being introduced in the interpolating polynomial by the method wehave selected to solve this problem. Such perturbations are called inducederrors. Ideally we would like small changes in the tabular values to producesmall changes in the interpolating polynomial and if this is the case then theproblem is said to be well conditioned. In order to demonstrate this ideaconsider the following example.

  • 8/7/2019 Alternate Num Analysis Notes

    19/142

    2.1. POLYNOMIAL INTERPOLATION 19

    0.5 1.0 1.5 2.0

    6

    5

    4

    3

    2

    1

    0

    1

    Figure 2.6: The quartic interpolant for table 2.1.3

    0.5 1.0 1.5 2.0

    2

    0

    2

    4

    6

    8

    Figure 2.7: The effect of perturbing entry 3 in table 2.1.3

  • 8/7/2019 Alternate Num Analysis Notes

    20/142

    20 CHAPTER 2. INTERPOLATION

    Example 2.1.5 (Computational)

    Applying the program INTERP to construct an interpolating polynomialthrough the points in table 2.1 produces the polynomial

    P4(x) =0.159796 + 3.164656x 6.499406x2 + 8.274375x3 3.901563x4.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

    0.1597 + 3.1652x 6.5044x2 + 8.2833x3 3.9063x4.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 theinterpolating polynomial through the tabular values in the file SIN. Investi-gate the sensitivity of the data provided by examining the effect of perturbingone or more of the values given. Is this problem inherently well conditioned?Is it susceptible to induced ill-conditioning?

    2.2 Lagrangian Polynomials

    In order to construct a polynomial of degree n through n + 1 distinct points

    using equation (2.1) it is necessary to solve a system of linear equations. Wewill now derive an alternative way of producing such a polynomial which doesnot require the solution of a system of possibly ill-conditioned equations. Asthere is only one polynomial of degree n which passes through n + 1 pointswe would obtain the same polynomial as that obtained from equation (2.1)if exact arithmetic were used. (See exercise 2.2.4.)

    Let us begin by assuming that we have been given a set of data points,(xi, yi), i = 0, ..., n, and then examine the function

    (x x0)(x x1)...(x xi1)(x xi+1) . . . (x xn).Notice that there is no factor (x xi). This function can also be written asthe product

    j=i(x xj ).and is a polynomial of degree n which vanishes at each data point with theexception x = xi. We now dene the Lagrangian polynomial functions, Li(x),

  • 8/7/2019 Alternate Num Analysis Notes

    21/142

    2.2. LAGRANGIAN POLYNOMIALS 21

    i = 0,...,n, as

    Li(x) = j=i(x xj)j=i(xi xj )

    We see that each of these polynomials has degree n and that Li(xk) = 0ifk = ibut is equal to 1 when k = i. Now consider the function

    P(x) =i=ni=0

    yiLi(x).(2.5)

    Since Li(x) is a polynomial of degree n for each i, so is P(x) and by virtue

    of the way in which each of the functions Li are dened P(x) will take thevalues yi when x = xi, i = 0,...,n. Therefore, P(x) and the interpolatingpolynomial Pn(x) are identical since they are both polynomials of degree nwhich agree at n + 1 points.

    Example 2.2.1 (Analytical)

    Let us consider the data points shown in table 2.1. The Lagrangian polyno-mial L0 is given as follows:

    L0(x) =(x 0.3)(x 0.5)(x 0.7)(x 0.9)

    (0.1

    0.3)(0.1

    0.5)(0.1

    0.7)(0.1

    0.9)

    = 26.04167x4 62.5x3 + 53.64583x2 19.375x + 2.460937.

    We stress that in practice an explicit expression of such a polynomial wouldnot be determined; it is easier to evaluate it in the form of equation (2.5).You should check that L0(x0) = 1, i.e. L0(0.1) = 1, and that L0(xi) = 0,i = 1, 2, 3, 4, i.e. L0(0.3) = L0(0.5) = L0(0.7) = L0(0.9) = 0. However,because of the form of equation (2.5) it is beter to consider yiLi(x), forexample, y0L0(x) is plotted in figure 2.8.

    Similarly, we can construct the polynomials L1(x), L2(x), L3(x) and L4(x).The required interpolating quartic polynomial is then given by

    P4(x) = 0.09956L0(x)+0.39646L1(x)+0.58813L2(x)+0.77210L3(x)+0.89608L4(x).

    To evaluate P4(0.51) we rstly nd L0(0.51) = 0.004052 from equation (2.4) andthen, similarly, we have that L1(0.51) = 0.03165, L2(0.51) = 0.99688, L3(0.51) =0.03498 and L4(0.51) = 0.00426, hence P4(0.51) = 0.59734 as before.

  • 8/7/2019 Alternate Num Analysis Notes

    22/142

    22 CHAPTER 2. INTERPOLATION

    0.5 0.5 1.0 1.5

    0.4

    0.2

    0.2

    0.4

    0.6

    0.8

    1.0

    Figure 2.8: The Lagrangian polynomial y0L0(x)

    Exercise 2.2.1 (Computational) The program INTERP may be used to con-struct a suitable interpolating polynomial through the points given in table2.1. Load INTERP, cycle through the options available with the Se- lectprompt until it reads method and then press RETURN. Cycle again untilthe Method prompt is Lagrangian polynomials and press RETURN again.Now use the default Graph option which is superimpose and a ashing cursorwill appear in the graphics window. Di?erent points can be selected usingthe cursor keys and then pressing RETURN once again. For example, the

    Lagrangian polynomial L0(x) can be drawn by simply pressing RETURNwhen the ashing cursor is positioned over the rst tabular point. However, inorder to make use of the form of equation (2.5) it is more conve- nient to usethe functions y0L0(x) and it is this function which is plotted in the graphicswindow and displayed in the bottom window. In a similar way the other fourLagrangian polynomials can be drawn.

    Exercise 2.2.2 (Computational) Use the program INTERP to construct theLagrangian polynomials through the data in le DATA. Sum these poly- no-mials as in equation (2.5) and show that the result is equivalent to the poly-nomial given by direct construction of the interpolating polynomial.

    Exercise 2.2.3 (Computational) Use the program INTERP to determine suit-able third- and fourth-order polynomial interpolants for the data given intable 2.1. (Hint: use the editor to delete points one at a time.)

    Exercise 2.2.4 (Analytical) Show that there is a unique polynomial of degreen which passes through the (n +1) points (xi, yi), i = 0,...,n. (Hint: consider

  • 8/7/2019 Alternate Num Analysis Notes

    23/142

    2.3. DIVIDED DIFFERENCES 23

    two polynomials pn(x) = a0+a1x+ ...+anxn and qn(x) = b0+b1x+ ...+bnxn,

    with ai = bi for at least one i, each of which interpolates the points given.Now consider the non-trivial polynomial pn(x) qn(x) at the points xi andhence show that ai = bi, i = 0,...,n.)

    Exercise 2.2.5 (Analytical) Hermite Interpolation. Lagrangian interpolationis based upon tabular values (xi, yi), i = 0,...,n; if in addition the gradientsy?i are supplied then higher order polynomials can be tted to the data. Showthat it is possible to t a polynomial of degree 2n + 1 in the form

    P2n+1(x) =i=ni=0

    i(x)yi +i=ni=0

    i(x)yi

    where

    i(x) = [1 2Li(xi)(x xi)]L2i (x),i(x) = (x xi)L2i (x).

    The result is called a Hermite interpolation polynomial.

    2.3 Divided Differences

    As another alternative to the construction of an interpolating polynomialthrough the points (xi, yi), i = 0,...,n, using Lagrangian polynomials we candetermine the interpolating polynomial of degree n as follows. If we denethe function p0(x) = y0 then, trivially, p0(x0) = y0. Now consider the linearpolynomial

    p1(x) = y0 + a1(x x0),which satises p1(x0) = y0 and then select a1 = (y1 y0)/(x1 x0) so that

    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 andp2(x1) = y1. Furthermore,

    p2(x) = p1(x) + a2(x x0)(x x1).

  • 8/7/2019 Alternate Num Analysis Notes

    24/142

    24 CHAPTER 2. INTERPOLATION

    We still have a2 at our disposal, but if

    a2 =(p2(x2) p1(x2))

    (x2 x0)(x2 x1)then p2(x2) = y2, i.e. p2(x) passes through (x0, y0), (x1, y1) and (x2, y2). Wecan repeat this process by dening

    pj(x) = pj1(x) + aj (x x0)(x x1)(x x2) . . . (x xj1), j = 1,...,n,

    and then selecting aj so that pj(xj ) = yj. The resulting polynomial, pn(x),passes through (xi, yi), i = 0,...,n, and is identical with that obtained by

    using the Lagrangian polynomials.Example 2.3.1 (Computational)The interpolating polynomial through the rst three values in table 2.1 maybe constructed as follows. Using the above method gives

    p0(x) = y0 = 0.09956,

    p1(x) = p0(x) + a1(x x0) = 0.09956 + a1(x 0.1).

    Select a1 so that p1(x1) = 0.39646, i.e. a1 =(0.396460.09956)

    (0.30.1)which gives

    p1(x) = 0.09956 + 1.4845(x 0.1).

    Next we dene p2(x) by

    p2(x) = p1(x) + a2(x 0.1)(x 0.3)

    and select a2 so that p2(x2) = y2, i.e. 2(0.5) = 0.58813,

    a2 =(p2(x2) p(x2))

    (x2

    x0)(x

    2 x1)

    =(0.58813 0.69336)

    (0.5

    0.1)(0.5

    0.3)=

    1.315375.

    This gives the polynomial

    p2(x) = 0.09956 + 1.4845(x 0.1) 1.315375(x 0.1)(x 0.3)

    which passes through the first three entries in table 2.1.

  • 8/7/2019 Alternate Num Analysis Notes

    25/142

    2.3. DIVIDED DIFFERENCES 25

    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 differencesassociated with these values by

    f[xi, xi+1] =(yi+1 yi)(xi+1 xi) .

    Next we compute second divided di?erences as

    f[xi, xi+1, xi+2] =(f[xi+1, xi+2] f[xi, xi+1])

    (xi+2 xi)and so on. When the (k 1)th divided di?erences have been obtained,i.e. f[xi, xi+1,...,xi+k1] and f[xi+1, xi+2,...,xi+k] we dene the kth divideddi?erence as

    f[xi, xi+1,...,xi+k] =(f[xi+1,...,xi+k] f[xi,...,xi+k?1])

    (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 tothe 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 interpolatingpolynomial 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. Therequired 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),

  • 8/7/2019 Alternate Num Analysis Notes

    26/142

    26 CHAPTER 2. INTERPOLATION

    Table 2.4: Table of divided differences

    x y First divided Second divided Third divideddifference difference difference

    x0 y0f[x0, x1] =

    (y1y0)x1x0)

    x1 y1 f[x0, x1, x2] =f[x1,x2]f[x0,x1]

    x2x0

    f[x1, x2] =(y2y1)x2x1)

    f[x1, x2, x3, x4]

    x2 y2 f[x1, x2, x3] = f[x2,x3]f[x1,x2]x3x1f[x2, x3] =

    (y3y2)x3x2)

    x3 y3

    Table 2.5: Table of divided differences

    x y First divided Second divided Third divided Fourth divideddifference difference difference difference

    0.1 0.099561.48450

    0.3 0.39646 -1.315380.95835 2.031875

    0.5 0.58813 -0.09625 -3.90156250.91985 -1.089375

    0.7 0.77210 -0.749880.619900.9 0.89608

  • 8/7/2019 Alternate Num Analysis Notes

    27/142

    2.4. NEVILLES ALGORITHM 27

    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

    P4(x) = 0.159796 + 3.164656x 6.499406x2 + 8.274375x3 3.901563x4,

    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 determinean 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

    3L0(x) + 6L1(x) + 11L2(x)

    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 andhence 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 oftabular 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.

    2.4 Nevilles algorithm

    Although the previous sections demonstrated how it was possible to constructa suitable interpolating polynomial explicitly it is clear that a considerableamount of effort is required in order to interpolate from the values given ina table. Furthermore, neither the method outlined in section 2.1 nor theLagrangian method gives any indication of the order of polynomial required.

    What we seek is some means of using a subset of the tabulated points, msay, to construct a suitable interpolant and then by adding an additionalpoint construct a higher order polynomial. In this way if we can show thatthe interpolants produced using subsets of m points and m + 1 points agreethen there is no point in investigating higher order polynomials. Nevillesalgorithm does precisely this.

  • 8/7/2019 Alternate Num Analysis Notes

    28/142

    28 CHAPTER 2. INTERPOLATION

    Let us suppose we select a subset of m points from a table of values,

    (x0, y0), (x1, y1), . . . , (xm1, ym1). Next we construct the linear functions

    p01(x) =(x x0)y1 (x x1)y0

    (x1 x0) ,

    p12(x) =(x x1)y2 (x x2)y1

    (x2 x1) ,...

    pm2,m1(x) =(x xm2)ym1 (x xm1)ym2

    (xm1

    xm2).

    Notice that pj,j+1(x) passes through the points (xj,yj) and (xj+1,yj+1), j =0, . . . , m 1. (These terms are sometimes called linear cross means.) Nextwe construct the linear cross means between successive linear terms, e.g.between p01(x) and p12(x), and then evaluate the quadratic function

    (x x0)p12(x) (x x2)p01(x)(x2 x0) .

    This function passes through (x0, y0), (x1, y1) and (x2, y2) and is denoted byp02(x). In this way we can recursively define a sequence of polynomials of

    increasing order by

    pjk (x) =(x xj)pj+1,k(x)(x xk)pj,k1(x)

    xk xj , k > j, k = 1,..,m. (2.4)

    This polynomial is of degree (k j) and passes through the points (xi, yi)for i = j , . . . , k, and is therefore equivalent to the Lagrangian polynomial ofthe same degree (see exercise 2.2.4).

    Exercise 2.4.1 (Analytical) Show that the quadratic polynomial p03(x) satis-fies the following: p03(x0) = y0, p03(x1) = y1, p03(x2) = y2.

    In practice if we are given a set of data and require an estimate at anon-tabular point x then, rather than evaluating the general polynomial,we only evaluate (2.4) at the point x. Furthermore, it is usual to take thetabular points beginning at the point closest to x and taking subsequentpoints in increasing distance from x so that x is near the middle of thevalues used.

  • 8/7/2019 Alternate Num Analysis Notes

    29/142

    2.4. NEVILLES ALGORITHM 29

    Example 2.4.1 (Computational)

    Use Nevilles algorithm to find an estimate for y(0.51) in table 2.1 on page 9.Load INTERP and cycle on the Select method prompt to select NevillesAlgorithm. We shall use the option Direct so press RETURN again, andthen enter the value x = 0.51. The values in table 2.1 are set as default valuesand should appear in a window on the right of the screen. We can now selectthe entries from this table in order of closeness to the point x = 0.51. Thetabular value x = 0.5 is the closest one to x = 0.51, so that is the first one wewish to select. To do so, use the up/down cursor keys to position the inversevideo block over the required value and then press RETURN. Another inversevideo block will now appear under the heading x, y selected, and you can

    copy your chosen values into this just by pressing RETURN. The next tabularvalues needed are those at x = 0.7, which should be selected and copied in asimilar way. At this point type Q to stop selecting values and the program willthen display a tableau based on the two values x = 0.5 and x = 0.7. Furtherpoints can be added by typing Q and selecting the Select/edit data option.Add further values until you obtain the tableau shown in table 2.6. Noticethat some editing of the selected values is allowed (should it be needed).For example, you can delete an entry (the entries below then move up oneplace), or copy one of the data points on top of another already selectedentry which then replaces that entry. (Only three columns of the table ofcross means are visible on the screen at any one time; other columns can be

    viewed using the left/right cursor keys.) Notice that by taking the tabulationpoints in such a way that the values |x xi| are in increasing order of sizethe top entry in each column gives the interpolated value required. Whenthe entries in successive columns are sufficiently close we can terminate theprocess. Additional values can be added to the bottom of the table in orderto improve the current interpolated value. In this example the second andthird entries agree to three decimal places and so it is sensible to quote theresult as y(0.51) 0.598. (In fact the value of p03 is much better than this;from section 2.1, P4(0.51) = 0.59734.)

    Exercise 2.4.2 (Computational) Use the program INTERP with the op-tion Nevilles algorithm to estimate y(0.51) by adding the final entry totable 2.6 from table 2.1.

    Unfortunately, Nevilles algorithm does not always work as well as shownin example 2.4.1. If the tabulated data points are sufficiently smooth thenall is well but consider the following example.

  • 8/7/2019 Alternate Num Analysis Notes

    30/142

    30 CHAPTER 2. INTERPOLATION

    Table 2.6: Nevilles algorithm applied to table 2.1.1

    xi (0.51 xi) yi Linear Quadratic Cubic0.5 +0.01 0.58813

    p01= 0.597330.7 0.19 0.77210 p02 = 0.59751

    p12= 0.59367 p03 = 0.597950.3 +0.21 0.39646 p13 = 0.6149

    p23= 0.571330.9 0.35 0.89608

    Example 2.4.2 (Computational)Table 2.7 illustrates the application of the program INTERP, with optionNevilles algorithm, to estimate y(0.15), from the values given. The resultis poor because the tabulated values are obtained from the function y(x) =1/x which changes very rapidly near x = 0. (The correct value of y(0.15) =6.666666, illustrating the difficulties which may appear if the data pointsvary greatly.)

    Table 2.7: Results produced by Nevilles algorithm

    x y Linear Quadratic Cubic Quartic0.1 10.000000

    7.5000000.2 5.000000 7.083333

    5.833333 6.9270830.3 3.333333 6.145833 6.848958

    4.583333 6.3020830.4 2.500000 5.208333

    3.7500000.5 2.000000

    Exercise 2.4.3 (Computational) Use the program INTERP to retrieve datafrom file SIN and use Nevilles algorithm to estimate y(1

    3). The data in

  • 8/7/2019 Alternate Num Analysis Notes

    31/142

    2.4. NEVILLES ALGORITHM 31

    this file is obtained from the function y = sin x. Insert additional points

    and investigate how the accuracy of the interpolated point depends on thespacing and number of points.

    2.4.1 Inverse interpolation

    Thus far we have concentrated upon the problem of interpolating non-tabularvalues. In this section we will look briefly at the problem of inverse interpola-tion which was mentioned on page 10. The simplest solution to this problemis to reverse the roles played by the dependent and independent variables; forexample, we simply rewrite table 2.1 on page 9 as table 2.8. This techniquemust be used with care because if there are two x values with the same yvalue then we will not get a single-valued interpolating function. This isequivalent to obtaining a singular matrix for equation (2.1). Furthermore,we need the original tabular values to be monotonic otherwise the order ofthe points will change when the roles of dependent and independent variablesare interchanged.

    Table 2.8: Interchanging variables in table 2.1.1

    Yield, y Concentration of reagent, x0.09956 0.100.39646 0.300.58813 0.500.77210 0.700.89608 0.90

    Exercise 2.4.4 (Computational) Use interpolation applied to table 2.1 onpage 9 to determine x(0.4) using Nevilles algorithm and the option In-

    verse. (Notice that applying inverse interpolation to this table is equivalentto applying interpolation to table 2.8. The program INTERP retains theoriginal order of each (x, y) pair on the screen although their roles are re-versed.) Check the result by using the option Construct interpolatingpolyn. and evaluating it at the point you have determined. How would youaccount for any discrepancy?

  • 8/7/2019 Alternate Num Analysis Notes

    32/142

    32 CHAPTER 2. INTERPOLATION

    The procedure of interchanging the dependent and independent variable

    can be very successful but must be used with care. It is clear that interpo-lation works best when the xi values are not too close and the yi values donot change too quickly. If this is the case then we can expect a reasonablyaccurate interpolation, but if these conditions are not satisfied then inverseinterpolation may be difficult. However, in order to illustrate the usefulnessof inverse interpolation consider the following simple problem.

    Table 2.9: Inverse interpolation applied to x2 3x + 1 = 0

    x y

    0.4 0.0400.38261

    0.3 0.190 0.381890.38636 0.38195

    0.5 0.250 0.38261 0.381960.39130 0.38213 0.38196

    0.2 0.440 0.38392 0.382020.36296 0.38258

    0.1 0.710 0.377210.34483

    0.0 1.000

    Example 2.4.3 (Computational)Use inverse interpolation to determine the solutions of the quadratic equation

    x2 3x + 1 = 0.

    Tabulating this function between x = 0 and x = 4 shows that the solutionslie in the intervals (0, 0.5) and (2.5, 3). Now load the program INTERPand enter values for f(x) = x2

    3x + 1 for values of x between 0 and 0.5.

    Using Nevilles algortihm and the option Inverse produces the resultsin table 2.9. Notice that even though the roles of the dependent variable xand the independent variable y have been interchanged they are displayedin the same order on the screen. From this table the required solution is atx = 0.38196. (The solutions of the given quadratic are at x = 1

    2(3 5), the

    smallest of which is 0.381966011.)

  • 8/7/2019 Alternate Num Analysis Notes

    33/142

    2.5. SPLINE INTERPOLATION 33

    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 inverseinterpolation to determine a value ofx such that y = 0.5. The data in this fileare obtained from the function y = sin x; investigate the effect of additionalpoints and different orderings.

    2.5 Spline interpolation

    Example 2.1.2 showed how it was possible to fit a polynomial of degree 4through five points, but the resulting function was quite oscillatory. We willnow investigate how it is possible to fit lower order interpolants which areglobally smoother. For example, through each pair of points (xi, yi) and(xi+1, yi+1) there is a unique straight line, but such a function is unsatisfac-tory since it will in general have kinks at each data point. (See figure 2.9.)Mathematically speaking, the interpolating function will not be differentiableat the points xi, i = 1, . . . , n 1. As an alternative, we could fit a quadraticfunction through (xi, yi) and (xi+1, yi+1). This problem does not have aunique solution, but we can take advantage of this non-uniqueness to selectthe quadratic curves whose derivatives match at each of the data points.

    0.2 0.2 0.4 0.6 0.8 1.0 1.2

    0.2

    0.4

    0.6

    0.8

    1.0

    Figure 2.9: Local linear interpolation

    Let us suppose that we attempt to fit the quadratic function

    Qi(x) = ai + bix + cix2, i = 1, . . . , n , (2.5)

  • 8/7/2019 Alternate Num Analysis Notes

    34/142

    34 CHAPTER 2. INTERPOLATION

    in the interval (xi1, xi); then as there are n intervals we shall have 3n coeffi-

    cients to find. First of all, we require that the resulting functions interpolatethe points (xi, yi), i = 0, . . . , n , i.e.

    Qi(xi1) = yi1 and Qi(xi) = yi, i = 1, . . . , n , (2.6)

    which gives 2n equations. (This condition will ensure that the resultingfunctions are continuous at the internal points x1, . . . , xn1.) Furthermore,at each internal point, xi, we require that the derivatives of Qi and Qi+1agree, i.e.

    Qi(xi) = Qi+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 coefficientarbitrarily. Combining together the resulting quadratic functions gives aquadratic spline.

    0.5 0.5 1.0 1.5

    0.5

    1.0

    1.5

    Figure 2.10: A quadratic spline through the data in table 2.1.1

    The amount of effort in determining a quadratic spline can be reducedby making use of the following procedure. Let us assume that in the interval(xi1, xi) the required spline component is Qi(x), as shown in figure 2.5.3.We now assume that at xi1 the slopes of both Qi1(x) and Qi(x) are di1and similarly at xi, Q

    i(x) = Q

    i+1(x) = di. Since the derivative of a quadratic

    function is linear, Qi(x) is the linear cross mean of di and di1, i.e. we havethat

    Qi(x) =(x xi1)di (x xi)di1

    xi xi1 ,

  • 8/7/2019 Alternate Num Analysis Notes

    35/142

    2.5. SPLINE INTERPOLATION 35

    x xi1 i

    Q xid

    i1

    di1

    Figure 2.11: A quadratic spline component Qi(x) in (xi1, xi)

    therefore, Qi(xi) = Qi+1(xi) = di, which will ensure that the conditions (2.7)

    are satisfied. Next we integrate this expression to get

    Qi(x) =(x xi1)2di (x xi)2di1

    2(xi xi1) + ci,

    where ci is a constant produced by the integration. Finally, we select theconstants ci to ensure that the combined spline is continuous across eachmesh node x = xi, i = 1, . . . , n

    1. (This ensures that equations (2.6) are

    satisfied.) Notice that

    Qi(xi) =12

    (xi xi1)di + ci = yiand

    Qi(xi1) =12

    (xi1 xi)di1 + ci = yi1.We then eliminate ci between these equations to give

    di =2(yi1 yi)(xi1 xi) di1. (2.8)

    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 tospecify 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

  • 8/7/2019 Alternate Num Analysis Notes

    36/142

    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 thespline at its left end, i.e. the value d0. For the moment accept the defaultvalue d0 = 1.4845 and then observe the corresponding quadratic spline beingplotted. (See figure 2.12.) Alternatively, we could take d0 = 0 which gives thequadratic spline shown in figure 2.10. The value d0 = (y1 y0)/(x1 x0) isobtained by using a finite difference approximation for the slope at x0 whichexplains why a better result is produced. (This is the default value whichthe program adopts.)

    Exercise 2.5.1 (Computational) Use the program INTERP to determine aquadratic 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 isgiven by figure 2.12.)

    0.5 0.5 1.0 1.5

    0.5

    1.0

    1.5

    Figure 2.12: Quadratic spline for table 2.1.1 with d0 = 1.4845

    From figure 2.12 we see that a quadratic spline and its derivative arecontinuous at each node. However, the curvature is not smooth since

    limxx1

    Q0(x) =(d1 d0)(x1

    x0)

    but

    limxx1

    Q1(x) =(d2 d1)(x2 x1)

    and these may not be the same. A further problem with quadratic splinesis that they tend to produce oscillatory functions as is also demonstrated

  • 8/7/2019 Alternate Num Analysis Notes

    37/142

    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-intervaland then attempt to select the coefficients so that both the slope and thecurvature are continuous across internal tabular points.

    x xi1 i

    S xi

    S'' xiy i

    yi1

    Mi

    Mi1

    Figure 2.13: Cubic polynomial through (xi, yi) and (xi+1, yi+1)

    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 + bix + cix2 + dix3. (2.9)

    In each sub-interval there are four coefficients to be determined, and sincethere are n such intervals this will give a total of 4n unknown values. Clearly,

    Si(xi) = yi and Si(xi+1) = yi+1, i = 0, . . . , n 1,

    which gives 2n conditions. Similarly, at each internal point we require

    Si1(xi) = Si(xi), i = 1, . . . , n 1,

    and

    Si1(xi) = Si (xi), i = 1, . . . , n 1,

    which gives a further 2n 2 conditions (see figure 2.13). It would appearthat we can specify any two values arbitrarily. Once all 4n parameters aredetermined we shall have a unique cubic in each subinterval. This collection

  • 8/7/2019 Alternate Num Analysis Notes

    38/142

    38 CHAPTER 2. INTERPOLATION

    of functions is called a cubic spline. Even for a moderate number of tabu-

    lation points this procedure will result in a large system of linear equationsbut, fortunately, the total amount of effort can be considerably reduced in amanner analogous to that used for quadratic splines.

    Notice that in the interval (xi, xi+1) we have that

    Si (x) = 2ci + 6dix. (2.10)

    Let us assume that the second derivative of Si at xi is given by some valueMi, then

    Si (xi) = 2ci + 6dixi = Mi,

    Si (xi+1) = 2ci + 6dixi+1 = Mi+1.

    Solving these equations for ci and di gives

    6di =Mi+1 Mixi+1 xi , 2ci =

    Mixi+1 Mi+1xixi+1 xi .

    Therefore,

    Si (x) =(x xi)Mi+1 (x xi+1)Mi

    xi+1 xi .

    (This is just a linear cross mean.) Integrating this expression twice gives

    Si(x) =Mi+1(x xi)3 Mi(x xi+1)3

    6hi+ ix + i, (2.11)

    where hi = xi+1 xi. Now we fit this expression to the data points (xi, yi)and (xi+1, yi+1), i.e.

    Mi(xi xi+1)2 + 6ixi + 6i = 6yi,Mi+1(xi+1 xi)2 + 6ixi+1 + 6i = 6yi+1,

    from which we eliminate i

    to produce

    i =(yi+1 yi)(xi+1 xi)

    16

    (xi+1 xi)(Mi+1 Mi) (2.12)

    andi = yi ixi 16Mi(xi+1 xi)2. (2.13)

  • 8/7/2019 Alternate Num Analysis Notes

    39/142

    2.5. SPLINE INTERPOLATION 39

    However, Si(x) is required to be continuous across xi, therefore

    Si1(xi) = Si(xi),

    i.e.Mi(xi xi1) + 2i1 = Mi(xi xi+1) + 2i

    ori i1 = 12Mi(xi+1 xi1). (2.14)

    Finally, we use equation (2.12) to eliminate i and i1 from (2.14) to give

    hi1Mi1 + 2(hi1 + hi)Mi + hiMi+1 =6(yi+1 yi)

    hi

    6(yi yi1)

    hi1

    . (2.15)

    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 unknownsM0, M1, . . . , M n. In particular this system of equations has a special formsince in a matrix notation we obtain entries only on the main diagonal andthe diagonals directly above and below this diagonal. These equations aretherefore called tridiagonal and special methods have been developed to solvethem which take advantage of their structure. (For an introduction to second-order recurrence relations and the solution of tridiagonal systems of linearequations see Harding and Quinney (1986).) The general solution of this re-

    currence relation will involve two arbitrary values which can be determinedif two additional conditions are supplied. There are two particularly popularways they can be specified: (i) free splines and (ii) clamped splines.

    (i) Free splines (natural splines). The simplest way of imposing additionalconditions is to set both M0 and Mn equal to zero. (This is equivalent toassuming that the interpolating function is approximately linear at x0 andxn since Mi is the second derivative at xi.)

    Example 2.5.2Use 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 secondderivative values to be determined. Let these values be M0, M1, M2, M3 andM4, but because the spline is to be natural we have M0 = M4 = 0. Next wewrite down the equation (2.15) at the internal points, i.e.

    0.2M0+0.8M1+0.2M2 =6

    0.2(0.588130.39646) 6

    0.2(0.396460.09956)

  • 8/7/2019 Alternate Num Analysis Notes

    40/142

    40 CHAPTER 2. INTERPOLATION

    0.2M1+0.8M2+0.2M3 =6

    0.2(0.772100.58813) 6

    0.2(0.588130.39646)

    0.2M2+0.8M3+0.2M4 =6

    0.2(0.896080.77210) 6

    0.2(0.772100.58813)

    or 0.8 0.2 00.2 0.8 0.2

    0 0.2 0.8

    M1M2

    M3

    =

    3.1568990.231000

    1.799699

    .

    These equations have the solution M1 = 4.306179, M2 = 1.440214 andM3 = 2.609679. These values provide all that is necessary to construct therequired natural spline. The resulting function is shown in figure 2.14. If

    we wish to evaluate the spline at a particular point it is first necessary todecide in which sub-interval the required point lies. For example, to evaluatethis spline at x = 0.51 we need to evaluate the component of the splinewhich is defined on the interval (0.5, 0.7) or (x2, x3). The required functionis therefore

    S2(x) =M3(x x2)3 M2(x x3)3

    6(x3 x2) + 2x + 2,

    where

    2 =(0.7721 0.58813)

    0.2 1

    6 0.2(2.660967 1.440214)

    and

    2 = 0.58813 0.52 16

    1.440214(0.2)2

    from (2.12) and (2.13). Evaluating these expressions gives the componentof the spline in the interval (0.5, 0.7) and hence S2(0.51) = 0.59731 to fivedecimal places.

    Exercise 2.5.2 (Analytical) Determine an explicit expression for the naturalcubic spline through the data points of table 2.1. By direct evaluation showthat the resulting spline is continuous and has continuous first and secondderivatives at the internal points x1,...,xn1.

    Exercise 2.5.3 (Computational) Use the program INTERP with the optionMethod: Cubic spline - free to confirm the results of example 2.5.2.

  • 8/7/2019 Alternate Num Analysis Notes

    41/142

    2.5. SPLINE INTERPOLATION 41

    0.5 0.5 1.0 1.5

    0.5

    1.0

    1.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 theinterpolating function at x0 and xn then we can use equation (2.11) to providethe additional equations required. Let us suppose that we are given thatS0(x0) = d0 and S

    n(xn) = dn then differentiating (2.11) and substituting we

    have

    d0 =(y1 y0)

    h0 h0

    6(M1 + 2M0)

    or

    2h0M0 + h0M1 =

    6(y1

    y0)

    h0 6d0. (2.16)and

    dn =(yn yn1)

    hn1+

    hn16

    (Mn1 + 2Mn)

    or

    hn1Mn1 + 2hn1Mn = 6dn 6 (yn yn1)hn1

    . (2.17)

    Next we combine equations (2.16) and (2.17) with the linear equations givenby (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 tridiagonaland diagonally dominant and can be solved in a relatively straightforwardway by Gaussian elimination without partial pivoting. (See Harding andQuinney (1986).)

    Example 2.5.3 (Computational)

  • 8/7/2019 Alternate Num Analysis Notes

    42/142

    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.1and 0.6199 at x = 0.9. (These values are default settings.) This clampedcubic spline is shown in figure 2.15 and can be compared with the free splinein figure 2.14.

    0.5 0.5 1.0 1.5

    0.5

    1.0

    1.5

    Figure 2.15: The clamped cubic spline in example 2.5.3

    Exercise 2.5.4 (Computational) Use the program INTERP to determine theclamped cubic spline which passes through the points given in table 2.1 and

    has zero slope at both ends. Compare the result with the free spline and theinterpolating polynomial through the same points.

    We can now compare the quadratic spline which passes through the pointsin table 2.1, on page 9, which is shown in figure 2.12, the clamped cubic splineshown in figure 2.15 and the corresponding free cubic spline which is shownin figure 2.14. Clearly, the cubic spline is less prone to oscillations and wecan show that this is generally the case.

    Theorem 2.1. Let C2[x0, xn] be the set of all twice differentiable functionswhich pass through the tabulation points, (xi, yi), i = 0, . . . , n. The naturalcubic spline, S(x), which is a member of C

    2[x

    0, x

    n], minimizes the average

    curvature: 1

    xn x0xn

    x0(f(x))2 dx

    .

    Proof. Let S(x) be the required natural spline given by the solution of (2.15)subject to M0 = Mn = 0 and let f(x) be any other twice differentiable

  • 8/7/2019 Alternate Num Analysis Notes

    43/142

    2.5. SPLINE INTERPOLATION 43

    function over [x0, xn]. Now considerxnx0

    (f(x))2 dx =xn

    x0[S(x) + (f(x) S(x))]2 dx

    =xn

    x0S(x)2 dx + 2

    xnx0

    S(x)[f(x) S(x)]2 dx

    +xn

    x0[f(x) S(x)]2 dx

    and then look at the second of these terms, i.e.

    I = xn

    x0S[f S] dx.

    Integrating by parts gives

    I = S(xn)[f(xn) S(xn)] S(x0)[f(x0) S(x0)]

    xn

    x0[f(x) S(x)]S(x) dx.

    However, for a natural spline S(x0) = M0 = 0 and S(xn) = Mn = 0

    and therefore the first two terms vanish. Furthermore, in each sub-interval(xi, xi+1) the cubic spline has constant third derivative which we shall callKi and so

    I = i=n1

    i=0

    xi+1xi

    [f(x) S(x)]Ki dx = i=n1

    i=0

    Ki[f(xi) S(xi)] = 0.

    From this we conclude thatxnx0

    [f(x)]2 xn

    x0[S(x)]2 dx

    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 forthe data in table 2.10. (These data points are stored in the file SPLINE).Now construct the natural cubic spline which passes through these pointsand compare the results obtained.

  • 8/7/2019 Alternate Num Analysis Notes

    44/142

    44 CHAPTER 2. INTERPOLATION

    Table 2.10: Data for exercise 2.5.4

    x 1 0.960 0.860 0.690 0.220 0.500 0.930y 1 0.151 0.594 0.986 0.895 0.500 0.306

    Exercise 2.5.5 (Computational) Use the program INTERP to determine aquadratic spline through the data in the data file SPLINE which has zeroslope at its left-hand end, i.e. d0 = 0. Vary d0 and investigate the behaviourof the resulting spline. Now fit a natural cubic spline through these datapoints and compare the results. Which curve is the smoothest? Investigate

    the behaviour of clamped splines for a variety of endpoint conditions. Isit possible to improve upon the natural cubic spline? To see that usinga higher order interpolating function does not improve the behaviour, tryfitting a high order polynomial using the option Construct interpolatingpolyn. (Hint: the quadratic spline is determined by a first order recurrencerelation for which an initial condition is supplied. Is it stable? Why is thetwo-point boundary value problem formulation involved with cubic splines amore stable process?)

    2.6 Summary and conclusion

    We have seen in this chapter how it is possible to produce a continuous func-tion which passes through a given set of tabular values. The solution to thisproblem is not unique. We can aim to fit a function which is composed ofa linear combination of simple powers of x, i.e. a polynomial, but this maylead to an interpolating polynomial which is highly oscilllatory. Alterna-tively, we can aim for a more local approximation and fit a spline which willgive a resulting function which is less likely to suffer from dramatic oscilla-tions between tabular values. However, whichever method is used we cannotsay anything definite about non-tabular values. To illustrate this point see

    figure 2.16. The interpolating function passes through all the tabular valuesbut is likely to be of little use in interpolation.

    An underlying assumption with any interpolation problem is that the datapoints have been determined from some unknown but continuous function.If the underlying function is not continuous then no amount of continuousfunctions can produce satisfactory interpolation near any singularity. Chap-

  • 8/7/2019 Alternate Num Analysis Notes

    45/142

    2.6. SUMMARY AND CONCLUSION 45

    3 2 1 1 2 3

    0.2

    0.4

    0.6

    0.8

    1.0

    Figure 2.16: An example of poor interpolation

    ter 3 will consider this further, but for the moment we conclude this chapterwith the following general remarks.

    1. Interpolation is usually more reliable than extrapolation; the lattershould be avoided if at all possible.

    2. Except in all but the very simplest cases it is unwise to determine aninterpolating polynomial by considering expressions of the form a0 +

    a1x + a2x2

    + . . . + anxn

    . This problem is possibly ill-conditioned andis likely to become more so as the number of tabular points increases.However, the construction of a polynomial interpolant can be carriedout in a stable way using either Lagrangian polynomials or divideddifferences. If the value of the interpolating polynomial is only requiredat one or two points then it is better to use Nevilles algorithm.

    3. Interpolation is a process whereby given a table of values (xi, y(xi)) anda non-tabular value x we attempt to find y(x). Inverse interpolationis where we are given a value y and are asked to determine a value xwhich would produce y.

    4. The curve which has minimum curvature through a set of points andyet 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 eachtabular interval, which are continuous and have continuous first andsecond derivatives at each internal tabular point.

  • 8/7/2019 Alternate Num Analysis Notes

    46/142

    46 CHAPTER 2. INTERPOLATION

    We have not considered the idea of rational interpolation, however, we

    shall consider the rational approximation functions in Chapter 3. Given aset of points and a rational function which passes through them it is clearthat rational interpolation can be carried out at non-tabular points.

  • 8/7/2019 Alternate Num Analysis Notes

    47/142

  • 8/7/2019 Alternate Num Analysis Notes

    48/142

    48 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS

    series expansion of the function f about the point x = a. An alternative

    form is

    f(x) = f(a) + (x a)f(a) + (x a)2

    2!f(a) + . . .

    . . . +(x a)n

    n!f(n)(a) + Rn, (3.1)

    where the remainder term Rn is given by

    Rn =(x a)(n+1)

    (n + 1)!f(n+1)(), (3.2)

    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 bymax|Rn| for all values of between x and a.Example 3.1.1We can use a Taylor series with a = 0, which is sometimes called a Maclaurinseries, to estimate exp(0.1). We can then consider questions such as thefollowing. If five terms of this series are used what is the maximum possibleerror? 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 givenby

    exp(x) = 1 + x +x2

    2!+

    x3

    3!+

    x4

    4!+ . . . +

    xn

    n!+ . . . .

    Taking the first five terms gives

    exp(0.1) 1 + 0.1 + 0.12

    2+

    0.13

    6+

    0.14

    24,

    therefore, exp(0.1) 1.105170831 which can be compared with the correctvalue of exp(0.1) = 1.10517092 . . . . The remainder term R4 associated withthe above Taylor series approximation may be used to estimate the errorinvolved with this approximate value. From equation (3.2) with x = 0 anda = 0.1 we have that

    |R4| max0x0.1

    0.15 exp()

    120

    0.15 exp(0.1)120 9.2 108,

  • 8/7/2019 Alternate Num Analysis Notes

    49/142

    3.1. TAYLOR SERIES APPROXIMATION 49

    compared with the actual error of 9.0 108. Suppose we now wanted tofind exp(0.5) using the same quartic polynomial expression then

    exp(0.5) 1 + 0.5 + 0.52

    2+

    0.53

    6+

    0.54

    24= 1.6484374

    but this compares less favourably with exp(0.5) = 1.6487213 . . .. For thisvalue ofx, max |R4| = 4.29 104. Clearly, the range of values for which wecan use this polynomial approximation is limited, but one way around thisproblem would appear to be to include further terms. Alternatively, we canuse the remainder term, Rn, to see just how many terms are required. Forexample, in order to ensure that the approximation has a maximum error,

    for all |x| 12 , which is less than 1 part in 106 we need to select an n suchthat

    |Rn| 0.5 107, for all |x| 12 .Therefore, from (3.2) we need to find an integer n such that

    max|x| 1

    2

    0.5n+1 exp(x)

    (n + 1)!

    0.5 107

    which can be achieved if n 9. This result implies that if we require anaccuracy of six decimal places each time we evaluate the exponential function

    for |x| and

  • 8/7/2019 Alternate Num Analysis Notes

    57/142

    3.2. POLYNOMIAL APPROXIMATION 57

    the polynomial through these points, display the resulting polynomial in the

    bottom window and then display the prompt Plot: function. By changingthe prompt you can plot the approximation or the error between the functionand the computed polynomial. Use the editor to change the interpolationpoints and investigate how the approximation and its error change. Nowreturn to the editor and add another two points and then determine quarticpolynomial approximations for exp(x), x [1, 1].

    Exercise 3.2.4 (Computational) Use the program APPROX with the optionMethod: Interpolation to determine the cubic polynomial approximationsfor the function exp(x), x in [1, 1], by interpolation at 1, 0.5, 0.5 and1. Investigate how the error between the interpolating polynomial and thefunction changes as the tabular points change. Investigate how the errorchanges as the number of tabular points increases. Find the polynomialof smallest degree which approximates this function to an accuracy of atworst 0.001 throughout this interval for interpolation points which are equallyspaced. Investigate how the error function behaves for different interpolationpoints.

    We have assumed that it is always possible to construct a suitable poly-nomial approximation, but is this always the case? Fortunately, provided the

    function f satisfies certain minimal requirements then there is always such apolynomial. We state, without proof, the following theorem.

    Theorem 3.2.1. Weierstrasss approximation theorem. If f is a continuousfunction on the finite interval [a, b], then for any > 0 there exists an nthdegree polynomial pn(x), for some n, such that

    |f(x) pn(x)| < for all x [a, b].

    In other words, if we are given a continuous function f, defined on the interval[a, b], then there is always a polynomial function which will approximate fto within any prescribed error . Unfortunately, what Weierstrasss theoremdoes not tell us is how large n should be, nor how to find the associatedpolynomial. Furthermore, this theorem assumes that we can carry out allarithmetic exactly, which is not the case either.

  • 8/7/2019 Alternate Num Analysis Notes

    58/142

    58 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS

    3.3 Minimax polynomials

    In the last section we saw that there are many polynomial approximationsof a given degree for any given function. For example,

    exp(x) 1 + x + 12

    x2 + 16

    x3, (3.8)

    andexp(x) 0.99520 + 0.99905x + 0.54788x2 + 0.17615x3, (3.9)

    are both cubic approximations. The first is a truncated Taylor series, thesecond is an interpolating polynomial which agrees with exp(x) at the points

    1, 1

    3 ,

    1

    3 and 1. We can compare these functions as shown in figure 3.2but it is more informative to look at their respective error functions shownin figure 3.3. If we were to obtain another interpolating cubic approximationby adjusting the tabular points we could plot the associated error functionin 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 anyother 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].

    The resulting polynomial is called the minimax polynomial of degree n. By

    adjusting the tabular points at which a polynomial qn(x) agrees with f(x) wecan look for the minimax polynomial, but this is likely to be a long process.Instead we can use a very powerful result due to Chebyschev.

    Theorem 3.3.1. Chebyshevs equi-oscillation theorem. Let f(x) be a con-tinuous function defined on the interval [a, b] and pn(x) be a polynomialapproximation, of degree n, for f on [a, b] with associated error functionen(x) = f(x) pn(x). If there exists a set of at least n + 2 points, a x0 1. We will now consider an alternative iterativeapproach. Consider the cubic approximation for exp(x) given by (3.6), i.e.

    exp(x)

    0.99520 + 0.99905x + 0.54788x2 + 0.17615x3,

    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 differentmagnitude. The internal stationary points of the error function occur atapproximately 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 11 0.7 0.72 0.73 11 0 0 0 1

    1 0.8 0.82

    0.83

    11 1 1 1 1

    a0a1a2

    a3E

    =

    exp(1)exp(0.7)

    exp(0)

    exp(0.8)exp(1)

    and in turn the solution of these equations gives the cubic

    q3(x) = 0.99465 + 0.99643x + 0.54308x2 + 0.17877x3. (3.11)

    The error e3(x) = exp(x) q3(x) is shown in figure 3.7, together with thecomputed value for E, and has turning points at 0.687312, 0.045814 and0.727528 in addition to the maxima at 1 and +1. (These extremum pointsare 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 fiveextrema which have alternating sign but they are of different magnitude.If the extrema were of the same magnitude then E would be the minimaxerror 3 for exp(x). We could now substitute these five points into (3.10)to determine another approximation and hence iteratively refine our cubic

  • 8/7/2019 Alternate Num Analysis Notes

    63/142

    3.3. MINIMAX POLYNOMIALS 63

    approximation. (Notice that only the x co-ordinate is required to deter-

    mine the next approximation.) This is the basis of the Remes algorithmfor determining minimax polynomial approximations which can be describedschematically as in figure 3.8.

    1.0 0.5 0.5 1.0

    0.004

    0.002

    0.002

    0.004

    0.006

    Figure 3.7: Error curve associated with the cubic (3.3.4)

    Not available

    Figure 3.8: The Remes algorithm

    Example 3.3.3 (Computational)We demonstrate the Remes algorithm by considering a cubic minimax ap-proximation for exp(x), 1 x 1. Load the program APPROX, forwhich this is the default function. When the prompt shows Function: asset press RETURN and select the option Method: Minimax/Remes.As we seek the minimax approximation of order 3, we will need to supplyfive points at which the required approximation for exp(x) has alternatingminima and maxima. For the moment let us use the values x = 1, 0.7,0, 0.8 and 1 which can be input using the prompt Option: edit/inspect

    points. When you are satisfied that suitable points have been entered quitthis option and change the prompt to Option: calculate coeffs. (It is alsopossible to supply a first approximation for the minimax polynomial usingthe option Taylor Series). Now press RETURN and the computer will de-termine the solution of the equations in step 2 of the Remes flowchart, shownin figure 3.8, and display the prompt Plot: function. If the function has

  • 8/7/2019 Alternate Num Analysis Notes

    64/142

    64 CHAPTER 3. THE APPROXIMATION OF FUNCTIONS

    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 islikely that the function and the computed approximation are very close; theerror between them can be examined by using the option Plot: error. Forthis example you should obtain figure 3.7 together with a dotted line whichdenotes the value for E in equations (3.10). The coefficients of the computedapproximation can be examined by using prompt Option: tabulate, whichin this case gives the cubic (3.11). Notice that the error associated with thisapproximation has maximum values at the points P, Q, R, S and T. We canselect 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 outthe next iteration of the Remes algorithm using the minima/maxima of theerror 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 approximationfor exp(x),

    |x|

    1.

    Exercise 3.3.4 (Computational) Use the program APPROX with the op-tion Remes/minimax to determine the quartic minimax approximationfor log(1 + x), |x| 1

    2. Try different starting polynomial approximations to

    examine the speed at which this algorithm converges to the required minimaxapproximation.

    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 certainlybe an upper bound on the minimax error n for polynomial approximationsof order n. In fact we can also produce a lower bound for the minimax errorn.

    Theorem 3.3.2. (de la Vallee Poussin).

    Given that qn is an nth degree polynomial approximation for a functionf(x), x [a, b], and xi, i = 0, . . . , n+1, are any n+2 points in [a, b] such thata x0 < x1 < .. . < xn+1 b where the error function en(x) = f(x) qn(x)

  • 8/7/2019 Alternate Num Analysis Notes

    65/142

    3.3. MINIMAX POLYNOMIALS 65

    alternates in sign at successive points, then

    minxi

    |en(xi)| n maxx[a,b]