Polynomial Interpolation through a Set of Points

Dr. Kevin G. TeBeest
Assoc. Prof. of Mathematics
Kettering University


First load the library of commands called CurveFitting as it contains the command PolynomialInterpolation that we need.

> with( CurveFitting ) :


List a set of points that we want the polynomial to contain. Notice the square brackets [ ].

> points := [ [ –2, –11 ] , [ 0, –3 ] , [ 1, –5 ] , [ 3, 9] ] ;    ( the structure is:   [ [x0, y0] , [x1, y1] , [x2, y2] , . . . , [xn, yn] ] )

points := [[-2, -11], [0, -3], [1, -5], [3, 9]]


We now use the PolynomialInterpolation command to create the polynomial containing the points.
We will simultaneously use the unapply command to turn it into a function P of variable x.

> P := unapply( PolynomialInterpolation( points, x ), x ) ;

P := proc (x) options operator, arrow; x^3-x^2-2*x-3 end proc


To show that the polynomial contains the prescribed points, let's evaluate it at each abscissa.

> P( –2 ) ;

-11

> P( 0 ) ;

-3

> P( 1 ) ;

-5

> P( 3 ) ;

9


We may convert the polynomial to nested form using Horner's method.

> convert( P(x) , horner ) ;

-3+(-2+(x-1)*x)*x


Let's plot the polynomial between x = –3 and x = 4.

> plot( P(x) , x = –3.0 .. 4.0 , thickness = 3 , color = blue ) ;

[Plot]


Return to course web site