You are on page 1of 11

Interpolation – Polynomial

Interpolation
Lecture 6
Interpolation
• Definition: Given a set of (x,y) data points,
Interpolation is the process of finding a function
(usually a polynomial) that passes through these data
points.
Polynomial Interpolation
• Definition: In polynomial interpolation, we find a
polynomial (or set of polynomials) that passes
through each data point.
• Simplest case: Linear Interpolation: Given two
(different) data points (x0, y0) and (x1, y1) there is a
unique line through these points.
Lagrange’s Formula
• For (n) data points
Lagrange Interpolating polynomial pn-1(x) is defined
n
by:
pn 1 ( x)   yi li ( x)
i 1
where
x  x1 x  x2 x  xi 1 x  xi 1 x  xn
li ( x)  . ....... . .....
xi  x1 xi  x2 xi  x i1 xi  x i1 xi  xn
n xx

j

j 1, xi  x j
j i
Lagrange’s Method
• Example: If n = 2, the interpolant is the straight line

P1(x)  y1l1(x)  y2l2(x), where

(x  x 2 )
l1(x) 
(x1  x 2 )

(x  x1 )
l2(x) 
(x2  x1 )
Lagrange’s Method
• Example: If n = 3, the interpolant is parabolic:

p2 ( x)  y1l1 ( x)  y2l2 ( x)  y3l3 ( x), where

(x  x2 )(x  x3 )
l1(x) 
(x1  x2 )(x1  x3 )
( x  x1 )( x  x3 )
l2 ( x ) 
( x2  x1 )( x2  x3 )
(x  x1 )(x  x2 )
l3(x) 
(x3  x1 )(x3  x2 )
Lagrange’s Method – Example 1
• Example: Given the data points

use Lagrange’s method to determine y at x = 1.


( x  x2 )( x  x3 ) (1  2)(1  3) 1
l1 ( x)   
( x1  x2 )( x1  x3 ) (0  2)(0  3) 3
( x  x1 )( x  x3 ) (1  0)(1  3)
l2 ( x )   1
( x2  x1 )( x2  x3 ) (2  0)( 2  3)
( x  x1 )( x  x2 ) (1  0)(1  2) 1
l3 ( x)   
( x3  x1 )( x3  x2 ) (3  0)(3  2) 3
Lagrange’s Method – Example 1
• The Lagrange Interpolating polynomial is then
p2 ( x)  y1l1  y2l2  y3l3
p2 ( x)  7l1 ( x)  11l2 ( x)  28l3 ( x)
at x=1
7 28
y   11  4
3 3
Lagrange’s Method – Example 2
• Example: Consider the data (1,3), (1/2, -10), (3,2).
There should be a quadratic polynomial passing
through these three points. To find this polynomial,
construct the three Lagrange terms:
( x  1 / 2)( x  3)
l1 ( x)   ( x  1 / 2)( x  3)
(1  1 / 2)(1  3)
( x  1)( x  3) 4
l2 ( x )   ( x  1)( x  3)
(1 / 2  1)(1 / 2  3) 5
( x  1)( x  1 / 2) 1
l3 ( x)   ( x  1)( x  1 / 2)
(3  1)(3  1 / 2) 5
Lagrange’s Method – Example 2
The Lagrange Interpolating polynomial is then
p2 ( x)  y1l1  y2l2  y3l3
p2 ( x)  3l1 ( x)  (10)l2 ( x)  2l3 ( x)
Or,
2
p2 ( x)  3( x  1 / 2)( x  3)  8( x  1)( x  3)  ( x  1)( x  1 / 2)
5
Lagrange Method
function p = lagrange_intr2(x,y,xn)
% p = polyinterp (x,y,xn) computes p = p(xn) where p is the
% polynomial of degree d = length(x)-1 with p(x(i)) = y(i).
n=length(x);
p=0;
for i=1:n % create term by term from the polynomial
l=1;
for j=[1:n] % create the l part for each term
if j~=i
l=l*(xn-x(j))/(x(i)-x(j));
end
end
p=p+y(i)*l;
end

n n x  xj
pn 1 ( x)   yi li ( x) li ( x)  
i 1 j 1, xi  x j
j i

You might also like