Polynomial Interpolation

Download Report

Transcript Polynomial Interpolation

Polynomial Interpolation
Lagrange Interpolation
40
Interpolation
30
An Interpolating Function
for a set of data:
{(x1,y1),(x2,y2),(x3,y3)…(xm,ym)}
is a function f(x) that
satisfies:
f(x1) = y1
f(x2) = y2
f(x3) = y3
.
.
.
f(xm) = ym
20
10
-2
-1
1
2
-10
-20
-30
-40
{(2,-39), (-1,-4), (0,5), (1,6), (2,17), (2.5,31.875)}
40
30
20
The graphs to the right show a
set of data plotted at the top.
The interpolating function along
with the data is graphed below
to the right.
10
-2
-1
1
-10
-20
-30
-40
2
3
Interpolating Data with a Function
The problem we will be discussing is how if you are given a set of data points
{(x1,y1),(x2,y2),(x3,y3)…(xm,ym)} , can an interpolating function f(x) be constructed to
fit the data.
The requirement that f(x) be a function restricts the data that can be interpolated.
In the definition of a function we have if xi = xj then f(xi) = f(xj), requiring if two
pairs of data points (xi,yi) and (xj,yj) have equal x-coordinates the y-coordinates
must also be equal. For implementation of many algorithms for interpolation we
require the data set {(x1,y1),(x2,y2),(x3,y3)…(xm,ym)} satisfy xi  xj if i  j.
Polynomial Interpolation
A Polynomial Interpolation for a set of data is an interpolating function f(x) such
that f(x) is a polynomial. (i.e. f(x) = anxn + an-1xn-1 + an-2xn-2 + … + a1x + a0)
Degree of Polynomial Interpolation
The degree of a polynomial p(x) = anxn + an-1xn-1 + an-2xn-2 + … + a1x + a0 is the
largest exponent with a non-zero coefficient. For the given p(x) its degree is n. In
general, as your data set gets larger the number of terms you need in your
polynomial (i.e. its degree) will also need to get larger. We usually insist on the
degree of the polynomial being as small as possible for a given data set.
The degree of the polynomial required is less than the number of data points. In
general a data set of m points will require a polynomial of degree m-1 or less.
Lagrange Interpolating Polynomial
The Lagrange Form of an interpolating polynomial makes use of elimination of
terms and cancellation to fit the data set.
Data Set
( x1 , y1 )
Polynomial
p( x)  y1
( x1, y1 ), ( x2 , y2 )
p( x)  y1
( x1, y1 ), ( x2 , y2 ), ( x3 , y3 )
p( x)  y1
( x  x2 )
( x  x1 )
 y2
( x1  x2 )
( x2  x1 )
( x  x2 )(x  x3 )
( x  x1 )(x  x3 )
( x  x1 )(x  x2 )
 y2
 y3
( x1  x2 )(x1  x3 )
( x2  x1 )(x2  x3 )
( x3  x1 )(x3  x2 )
p( x)  y1
( x  x2 )(x  x3 )  ( x  xm )
( x  x1 )(x  x3 )  ( x  xm )
 y2

( x1  x2 )(x1  x3 ) ( x1  xm )
( x2  x1 )(x2  x3 )  ( x2  xm )
( x1, y1 ),( x2 , y2 ),, ( xm , ym )
  ym
( x  x1 )(x  x2 )  ( x  xm1 )
( xm  x1 )(xm  x2 )  ( xm  xm1 )
m
m
(x  x j )
i 1
j 1
( xi  x j )
p( x)   yi 
j i
Example:
Let the data set {(-1,-4),(0,-5),(1,-2)} be the data set we want to interpolate.
( x  0)(x  1)
( x  1)(x  1)
( x  1)(x  0)
p( x)  4
 5
 2
(1  0)(1  1)
(0  1)(0  1)
(1  1)(1  0)
4 2
5 2
2 2

x x 
x 1 
x x
2
1
2
 2 x 2  2 x  5 x 2  5  x 2  x




 2x2  x  5
Plugging in the values of x we get:
p(-1) = 2(-1)2 + -1 -5 = 2-1-5 = -4
p(0) = 2(0)2 + 0 -5 = 0 + 0 - 5 = -5
p(1) = 2(1)2 + 1 -5 = 2 + 1 - 5 = -2


Lagrange Interpolating Polynomial Algorithm
To implement the Lagrange Polynomial
Interpolating Polynomial Algorithm to a set of
data it is a matter of following the formula to the
right for the set of data:
m
m
(x  x j )
i 1
j 1
( xi  x j )
p( x)   yi 
{(x1,y1),(x2,y2),(x3,y3)…(xm,ym)}
alldiffx ← True
For[ i=1, i  m , i++
For[ j=1, j<i, j++,
alldiffx=alldiffx and (xi xj)]]
If alldiffx
psum=0
For[i=1, i  m , i++
pprod=yi
For[ j=1, j<i, j++,
If ij then pprod=pprod*(x –xj)/(xi – xj)]
psum=psum+pprod]
(* else *)
Print[“Data set can not be interpolated by a function”]
i j