Chapter 1 Polynomial Interpolation When you are wrestling for possession of a sword, the man with the handle always wins. Neal Stephenson, Snow Crash The goal of interpolation is to fit a function exactly through a series of points. The main idea is the interpolating function goes through some required collection of points exactly. Usually we build interpolating functions using a collection of basis functions and multiply the given basis functions by a collection of coefficients such that the required set of points is satisfied. Consider the set of points: {(x 1, y 1 ), (x 2, y 2 ),..., (x n, y n )} The goal here is to find an n th order polynomial that will fit through these points. One such function we could arrive at would have the form: f n (x) = c 1 + c 2 (x x 1 ) + c 3 (x x 1 )(x x 2 ) + + c n (x x 1 )(x x 2 ) (x x n ) This expression is known as the Newton form of the interpolating polynomial. How do we go about finding the coefficients c i? Newton Interpolating Polynomial Consider fitting a polynomial to the following set of points. {( 1, ), (3, 1), (5, 3), (7, 3)} We will build up our function by finding a function that satisfies one of the points, then two, and so on until all four of the points in the set are satisfied. The coefficients c i in the 1
interpolating polynomial above may be found using divided differences. Specifically: c 1 = f(x 1 ) c 2 = f[x 2, x 1 ] = f(x 2) f(x 1 ) x 2 x 1 c 3 = f[x 3, x 2, x 1 ] = f[x 3, x 2 ] f[x 2, x 1 ]) x 3 x 1 c = f[x, x 3, x 2, x 1 ] = f[x, x 3, x 2 ] f[x 3, x 2, x 1 ] x x 1.. c n = f[x n, x n 1,..., x 1 ] = f[x n, x n 1,..., x 2 ] f[x n 1, x n 2,..., x 1 ] x n x 1 The function we aim to find that interpolates the data set given in this example is: f(x) = c 1 + c 2 (x 1) + c 3 (x ( 1))(x (5)) + c (x ( 1))(x (3))(x (5)) Note when f(x) is evaluated at each of the x-values in the data set to be interpolated that many of the additive terms become zero. Finding the coefficients c i above: c 1 = c 2 = f[x 2, x 1 ] = f(x 2) f(x 1 ) = 1 () x 2 x 1 3 ( 1) = 3 f[x 3, x 2 ] = f(x 3) f(x 2 ) = 3 (1) x 3 x 2 5 (3) = 1 f[x, x 3 ] = f(x ) f(x 3 ) x x 3 = 3 (3) 7 (5) = 3 c 3 = f[x 3, x 2, x 1 ] = f[x 3, x 2 ] f[x 2, x 1 ]) = 1 ( 3) x 3 x 1 5 ( 1) = 7 2 f[x, x 3, x 2 ] = f[x, x 3 ] f[x 3, x 2 ]) x x 2 = 3 (1) 7 (3) = 1 c = f[x, x 3, x 2, x 1 ] = f[x, x 3, x 2 ] f[x 3, x 2, x 1 ] = 1 ( 7 x x 1 7 ( 1) = 31 192 2 ) This yields the function: ( f(x) = + 3 ) ( ) ( 7 (x 1)+ (x ( 1))(x (5))+ 31 ) (x ( 1))(x (3))(x (5)) 2 192 The interpolating function can now be plotted along with its defining points: 2
2-2 - -6-8 -10 2 6 8 Some CODE A listing of code that can be used in SAGE to produce the function s interpolation is given by: Listing 1.1: ]Code to Create 5 Lagrange Cardinal Polynomials on [-1,1] def F2( i, j, xe, ye ) : return ( ye [ i ] ye [ j ] ) / ( xe [ i ] xe [ j ] ) def F3( i, j, k, xe, ye ) : return (F2( i, j, xe, ye ) F2( j, k, xe, ye ) ) / ( xe [ i ] xe [ k ] ) def F( i, j, k, l, xe, ye ) : return (F3( i, j, k, xe, ye ) F3( j, k, l, xe, ye ) ) / ( xe [ i ] xe [ l ] ) xe = [ 1,3, 5, 7 ] ; ye = [, 1, 3, 3]; c1 = ye [ 0 ] c2 = F2 ( 1, 0, xe, ye ) show ( c2 ) c3 = F3 ( 2, 1, 0, xe, ye ) c = F ( 3, 2, 1, 0, xe, ye ) newt ( x ) = c1 + c2 (x xe [ 0 ] ) + c3 (x xe [ 0 ] ) ( x xe [ 1 ] ) + c (x xe [ 0 ] ) ( x xe [ 1 ] ) NewtPlot = p l o t ( newt, 1,8, c o l o r = [ 1, 0, 0 ] ) ; NewtPlot += point ( ( xe [ 0 ], ye [ 0 ] ), s i z e =30, f i g s i z e =3) NewtPlot += point ( ( xe [ 1 ], ye [ 1 ] ), s i z e =30, f i g s i z e =3) NewtPlot += point ( ( xe [ 2 ], ye [ 2 ] ), s i z e =30, f i g s i z e =3) NewtPlot += point ( ( xe [ 3 ], ye [ 3 ] ), s i z e =30, f i g s i z e =3) 3
Lagrange Interpolation Polynomial A second method for generating the interpolating function may be presented in the following manner. Lets take advantage of some basis functions that are zero or one depending on the data point we are considering in the given collection of points. The idea of our collection of basis functions was to allow them to have a Kronecker Delta property: { 0 if i j δ i,j = 1 if i = j For a given set of data points we have seen that if l i (x) is a polynomial with the Kronecker Delta property at the given data set: The interpolating polynomial of the set is: which can be seen by observing P (x j ) = x x 0 x 1 x n y y 0 y 1 y n P (x) = n l i (x)y i, (1.0.1) i=0 n l i (x j )y i = l j (x j )y j = y j i=0 We can built an set of basis functions l i (x) for our specified data set using a product of factors. Consider ( ) ( ) ( ) ( ) ( ) x x0 x x1 x xi 1 x xi+1 x xn l i (x) = x i x 0 x i x 1 x i x i 1 x i x i+1 x i x n Notice that the i th term in the sequence is skipped and that the l i (x) expressions have the Kronecker Delta Property. Then n ( ) x xj l i (x) = i {0, 1,..., n}. x i x j j=0,j i here P (x) in (1.0.1) is the Lagrange Form of the interpolating polynomial, and the basis functions l i (x) are often called cardinal polynomials. Class Activity Using sage find the first five Lagrange Interpolating Polynomials evenly spaced on the interval [ 1, 1] then modify your code to find the Lagrange Interpolating polynomial for the data set listed below:
x 0 2 3 y 7 11 28 63 The following sage code is used: Listing 1.2: ]Code to Create 5 Lagrange Cardinal Polynomials on [-1,1] xnodes = [ 1.0, 0.5, 0. 0, 0. 5, 1. 0 ] ; ynodes = [ 0. 0, 0. 0, 0. 0, 0. 0, 0. 0 ] ; L0 ( x ) = 1. 0 ; L1 ( x ) = 1. 0 ; L2 ( x ) = 1. 0 ; L3 ( x ) = 1. 0 ; L ( x ) = 1. 0 ; f o r i in range ( l e n ( xnodes ) ) : i f ( i!= 0 ) : L0 ( x ) = L0 ( x ) ( ( x xnodes [ i ] ) / ( xnodes [0] xnodes [ i ] ) ) ; i f ( i!= 1 ) : L1 ( x ) = L1 ( x ) ( ( x xnodes [ i ] ) / ( xnodes [1] xnodes [ i ] ) ) ; i f ( i!= 2 ) : L2 ( x ) = L2 ( x ) ( ( x xnodes [ i ] ) / ( xnodes [2] xnodes [ i ] ) ) ; i f ( i!= 3 ) : L3 ( x ) = L3 ( x ) ( ( x xnodes [ i ] ) / ( xnodes [3] xnodes [ i ] ) ) ; i f ( i!= ) : L ( x ) = L ( x ) ( ( x xnodes [ i ] ) / ( xnodes [] xnodes [ i ] ) ) ; 1 0.8 0.6 0. 0.2-1 -0.5 0.5 1-0.2-0. Figure 1.0.1: Plot of the first five Lagrange cardinal polynomials on [ 1, 1]. 5
8e5 6e5 e5 2e5-1 1 2 3 5-2e5 Figure 1.0.2: The Lagrange Interpolating polynomial on [0, ]. To modify the code for the second portion of the activity note that we need to change the nodes vectors. 1.0.1 Error in Polynomial Interpolation Lets consider the error in polynomial interpolation. Given the following sets of points find a polynomial using SAGE that interpolates the data: Two Points: Three Points: Four Points: Five Points: x 0 10 y 10 0 x 0 10 y 10 5 0 x 0 7 10 y 10 5 2 0 x 0 7 9 10 y 10 5 2 3 0 6
Typically the thought is: The larger the number of nodes used the better the interpolating is between the node for a data set. Is this correct? Consider the Runge function on the interval [ 5, 5]. R(x) = 1 x 2 + 1 What would the interpolating polynomial look like if we used 11 equally spaced points to create a polynomial interpolating function that approximates the Runge function. 7