Lagrange Interpolation
Interpolation
40
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
-10
-20
-30
-40
40
30
20
10
-2
-1
1
-10
-20
-30
-40
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
( x1 , y1 ), ( x2 , y2 ),, ( xm , ym )
( 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 )
ym
( x x1 )( x x2 ) ( x xm 1 )
( xm x1 )( xm x2 ) ( xm xm 1 )
(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)
5
2
p ( x) 4
(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
2
1
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
(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 ij then pprod=pprod*(x xj)/(xi xj)]
psum=psum+pprod]
(* else *)
Print[Data set can not be interpolated by a function]
i j