5 Polynomial approximations - splines

We complete this Section by briefly describing another approach that can be used in the case where the data are exact.

Why are splines needed?

Fitting a polynomial to the data (using Lagrange polynomials, for example) works very well when there are a small number of data points. But if there were 100 data points it would be silly to try to fit a polynomial of degree 99 through all of them. It would be a great deal of work and anyway polynomials of high degree can be very oscillatory giving poor approximations between the data points to the underlying function.

What are splines?

Instead of using a polynomial valid for all x , we use one polynomial for x 1 < x < x 2 , then a different polynomial for x 2 < x < x 3 then a different one again for x 3 < x < x 4 , and so on.

We have already seen one instance of this approach in this Section. The “dot to dot" interpolation that we abandoned earlier (Figure 1(a)) is an example of a linear spline . There is a different straight line between each pair of data points.

The most commonly used splines are cubic splines . We use a different polynomial of degree three between each pair of data points. Let s = s ( x ) denote a cubic spline, then

s ( x ) = a 1 ( x x 1 ) 3 + b 1 ( x x 1 ) 2 + c 1 ( x x 1 ) + d 1 ( x 1 < x < x 2 ) s ( x ) = a 2 ( x x 2 ) 3 + b 2 ( x x 2 ) 2 + c 2 ( x x 2 ) + d 2 ( x 2 < x < x 3 ) s ( x ) = a 3 ( x x 3 ) 3 + b 3 ( x x 3 ) 2 + c 3 ( x x 3 ) + d 3 ( x 3 < x < x 4 ) &vellip;

And we need to find a 1 , b 1 , c 1 , d 1 , a 2 , …to determine the full form for the spline s ( x ) . Given the large number of quantities that have to be assigned (four for every pair of adjacent data points) it is possible to give s some very nice properties:

Even with all of these requirements there are still two more properties we can assign to s . A natural cubic spline is one for which s is zero at the two end points. The natural cubic spline is, in some sense, the smoothest possible spline, for it minimises a measure of the curvature.

How is a spline found?

Now that we have described what a natural cubic spline is, we briefly describe how it is found. Suppose that there are N data points. For a natural cubic spline we require s ( x 1 ) = s ( x N ) = 0 and values of s taken at the other data points are found from the system of equations in Key Point 4.

Key Point 4

Cubic Spline Equations

k 2 h 2 h 2 k 3 h 3 &dtdot; &dtdot; &dtdot; h N 3 k N 2 h N 2 h N 2 k N 1 s ( x 2 ) s ( x 3 ) &vellip; s ( x N 2 ) s ( x N 1 ) = r 2 r 3 &vellip; r N 2 r N 1

in which

h 1 = x 2 x 1 , h 2 = x 3 x 2 , h 3 = x 4 x 3 , h 4 = x 5 x 4 ,

k 2 = 2 ( h 1 + h 2 ) , k 3 = 2 ( h 2 + h 3 ) , k 4 = 2 ( h 3 + h 4 ) ,

r 2 = 6 f 3 f 2 h 2 f 2 f 1 h 1 , r 3 = 6 f 4 f 3 h 3 f 3 f 2 h 2 ,

Admittedly the system of equations in Key Point 4 looks unappealing, but this is a “nice" system of equations. It was pointed out at the end of HELM booklet  30 that some applications lead to systems of equations involving matrices which are strictly diagonally dominant . The matrix above is of that type since the diagonal entry is always twice as big as the sum of off-diagonal entries.

Once the system of equations is solved for the second derivatives s , the spline s can be found as follows:

a i = s ( x i + 1 ) s ( x i ) 6 h i , b i = s ( x i ) 2 , c i = f i + 1 f i h i s ( x i + 1 ) + 2 s ( x i ) 6 h i , d i = f i

We now present an Example illustrating this approach.

Example 9

Find the natural cubic spline which interpolates the data

x j 1 3 5 8 ̲ ̲ ̲ ̲ ̲ f j 0.85 0.72 0.34 0.67

Solution

In the notation now established we have h 1 = 2 , h 2 = 2 and h 3 = 3 . For a natural cubic spline we require s to be zero at x 1 and x 4 . Values of s at the other data points are found from the system of equations given in Key Point 4. In this case the matrix is just 2 × 2 and the pair of equations are:

h 1 s ( x 1 ) &UnderBrace; = 0 + 2 ( h 1 + h 2 ) s ( x 2 ) + h 2 s ( x 3 ) = 6 f 3 f 2 h 2 f 2 f 1 h 1 h 2 s ( x 2 ) + 2 ( h 2 + h 3 ) s ( x 3 ) + h 3 s ( x 4 ) &UnderBrace; = 0 = 6 f 4 f 3 h 3 f 3 f 2 h 2

In this case the equations become

8 2 2 10 s ( x 2 ) s ( x 3 ) = 0.75 1.8

Solving the coupled pair of equations leads to

s ( x 2 ) = 0.146053 s ( x 3 ) = 0.209211

We now find the coefficients a 1 , b 1 , etc. from the formulae and deduce that the spline is given by

s ( x ) = 0.01217 ( x 1 ) 3 0.016316 ( x 1 ) + 0.85 ( 1 < x < 3 ) s ( x ) = 0.029605 ( x 3 ) 3 0.073026 ( x 3 ) 2 0.162368 ( x 3 ) + 0.72 ( 3 < x < 5 ) s ( x ) = 0.01162 ( x 5 ) 3 + 0.104605 ( x 5 ) 2 0.099211 ( x 5 ) + 0.34 ( 5 < x < 8 )

Figure 5 shows how the spline interpolates the data.

Figure 5 No alt text was set. Please request alt text from the person who provided you with this resource.

Task!

Find the natural cubic spline which interpolates the data

x j 1 2 3 5 ̲ ̲ ̲ ̲ ̲ f j 0.1 0.24 0.67 0.91

In the notation now established we have h 1 = 1 , h 2 = 1 and h 3 = 2 . For a natural cubic spline we require s to be zero at x 1 and x 4 . Values of s at the other data points are found from the system of equations

h 1 s ( x 1 ) &UnderBrace; = 0 + 2 ( h 1 + h 2 ) s ( x 2 ) + h 2 s ( x 3 ) = 6 f 3 f 2 h 2 f 2 f 1 h 1 h 2 s ( x 2 ) + 2 ( h 2 + h 3 ) s ( x 3 ) + h 3 s ( x 4 ) &UnderBrace; = 0 = 6 f 4 f 3 h 3 f 3 f 2 h 2

In this case the equations become

4 1 1 6 s ( x 2 ) s ( x 3 ) = 1.74 1.86

Solving the coupled pair of equations leads to s ( x 2 ) = 0.534783 s ( x 3 ) = 0.399130

We now find the coefficients a 1 , b 1 , etc. from the formulae and deduce that the spline is

s ( x ) = 0.08913 ( x 1 ) 3 + 0.05087 ( x 1 ) + 0.1 ( 1 < x < 2 ) s ( x ) = 0.15565 ( x 2 ) 3 + 0.267391 ( x 2 ) 2 + 0.318261 ( x 2 ) + 0.24 ( 2 < x < 3 ) s ( x ) = 0.033261 ( x 3 ) 3 0.199565 ( x 3 ) 2 + 0.386087 ( x 3 ) + 0.67 ( 3 < x < 5 )
Exercises
  1. A political analyst is preparing a dossier involving the following data

    x 10 15 20 25 ̲ ̲ ̲ ̲ ̲ f ( x ) 9.23 8.41 7.12 4.13

    She interpolates the data with a polynomial p ( x ) of degree 3 in order to find an approximation p ( 22 ) to f ( 22 ) . What value does she find for p ( 22 ) ?

  2. Estimate f ( 2 ) to an appropriate accuracy from the table of values below by means of an appropriate quadratic interpolating polynomial.

    x 1 3 3.5 6
    f ( x ) 99.8 295.5 342.9 564.6
  3. An experiment is carried out and the data obtained as follows

    x n 2 3 5 7 ̲ ̲ ̲ ̲ ̲ f n 2.2 5.4 6.5 13.2

    Obtain the least squares best fit straight line, y = m x + c , to these data. (Give c and m to 2 decimal places.)

  4. Find the natural cubic spline which interpolates the data

    x j 2 4 5 7 ̲ ̲ ̲ ̲ ̲ f j 1.34 1.84 1.12 0.02

  1. We are interested in the Lagrange polynomials at the point x = 22 so we consider

    L 1 ( 22 ) = ( 22 x 2 ) ( 22 x 3 ) ( 22 x 4 ) ( x 1 x 2 ) ( x 1 x 3 ) ( x 1 x 4 ) = ( 22 15 ) ( 22 20 ) ( 22 25 ) ( 10 15 ) ( 10 20 ) ( 10 25 ) = 0 . 056 .

    Similar calculations for the other Lagrange polynomials give

    L 2 ( 22 ) = 0.288 , L 3 ( 22 ) = 1.008 , L 4 ( 22 ) = 0.224 ,

    and we find that our interpolated polynomial, evaluated at x = 22 is

    p ( 22 ) = f 1 L 1 ( 22 ) + f 2 L 2 ( 22 ) + f 3 L 3 ( 22 ) + f 4 L 4 ( 22 ) = 9.23 × 0.056 + 8.41 × 0.288 + 7.12 × 1.008 + 4.13 × 0.224 = 6.197 = 6.20 , to 2 decimal places,

    which serves as the approximation to f ( 22 ) .

  2. f ( 2 ) = ( 2 1 ) ( 2 3 ) ( 3.5 1 ) ( 3.5 3 ) × 342.9 + ( 2 1 ) ( 2 3.5 ) ( 3 1 ) ( 3 3.5 ) × 295.5 + ( 2 3 ) ( 2 3.5 ) ( 1 3 ) ( 1 3.5 ) × 99.8 = 274.32 + 443.25 + 29.94 = 198.87

    Estimate is 199 (to 3 sig. fig.)

  3. We tabulate the data for convenience:

    x n f n x n 2 x n f n ̲ ̲ ̲ ̲ ̲ 2 2.2 4 4.4 3 5.4 9 16.2 5 6.5 25 32.5 7 13.2 49 92.4 ̲ ̲ ̲ ̲ ̲ 17 27.3 87 145.5

    The quantity 1 counts the number of data points and in this case is equal to 4.
    It follows that the pair of equations for m and c are as follows:

    4 c + 17 m = 27.3 17 c + 87 m = 145.5

    Solving these gives c = 1.67 and m = 2.00 , to 2 decimal places, and we see that the least squares best fit straight line to the given data is

    y = 1.67 + 2.00 x

  4. In the notation now established we have h 1 = 2 , h 2 = 1 and h 3 = 2 . For a natural cubic spline we require s to be zero at x 1 and x 4 . Values of s at the other data points are found from the system of equations h 1 s ( x 1 ) &UnderBrace; = 0 + 2 ( h 1 + h 2 ) s ( x 2 ) + h 2 s ( x 3 ) = 6 f 3 f 2 h 2 f 2 f 1 h 1 h 2 s ( x 2 ) + 2 ( h 2 + h 3 ) s ( x 3 ) + h 3 s ( x 4 ) &UnderBrace; = 0 = 6 f 4 f 3 h 3 f 3 f 2 h 2

    In this case the equations become

    6 1 1 6 s ( x 2 ) s ( x 3 ) = 5.82 1.02

    Solving the coupled pair of equations leads to

    s ( x 2 ) = 1.026857 s ( x 3 ) = 0.341143

    We now find the coefficients a 1 , b 1 , etc. from the formulae and deduce that the spline is given by

    s ( x ) = 0.08557 ( x 2 ) 3 + 0.592286 ( x 2 ) + 1.34 ( 2 < x < 4 ) s ( x ) = 0.228 ( x 4 ) 3 0.513429 ( x 4 ) 2 0.434571 ( x 4 ) + 1.84 ( 4 < x < 5 ) s ( x ) = 0.02843 ( x 5 ) 3 + 0.170571 ( x 5 ) 2 0.777429 ( x 5 ) + 1.12 ( 5 < x < 7 )