5-Interpolation and Polynomial Approximation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

INTERPOLATION AND POLYNOMIAL

APPROXIMATION
Interpolation Methods

 Why would we be interested in interpolation methods?

• Interpolation method are the basis for other procedures that we will deal with:
– Numerical differentiation
– Numerical integration
– Solution of ODE (ordinary differential equations) and PDE (partial differential
equations)

 Why would we be interested in interpolation methods?

• These methods demonstrate some important theory about polynomials and the
accuracy of numerical methods.
• The interpolation of polynomials serve as an excellent introduction to some techniques
for drawing smooth curves.

Interpolation uses the data to approximate a function, which will fit all of the data points. All
of the data is used to approximate the values of the function inside the bounds of the data.

Interpolation is a process of finding a formula (often a polynomial) whose graph will pass
through a given set of points (x, y).

Interpolation: Problem Specification

2
Input: A set S of data f( x0 , y0 )( x1 , y1 )( xn , yn )g( xi , yi ) 2
Output: A function () which interpolates the given set of data,
i.e., ( xi ) = yi , for 0  i  n .

Note. In general, the interpolating function () is NOT unique.

1
LAGRANGE INTERPOLATION

Linear interpolation uses a line segment that passes two points

( x1 , y1 )

( x0 , y0 )

The slope between ( x0 , y0 ) and ( x1 , y1 ) is

y1  y0
m
x1  x0

from the point slope formula y  y0  m( x  x0 ) can be rearranged as

 x  x0 
y  y0   y1  y0    .......................(1)
 x1  x0 

When formula (1) is expanded , the result is a polynomial of degree  1 . Evaluating P ( x ) at


x0 and x1 produces y0 and y1 respectively.

P ( x0 )  y0
………………….(2)
P ( x1 )  y1

Lagrange used slightly different method to find this polynomial as follows

( x  x1 ) ( x  x0 )
y  P1 ( x )  y0  y1 ………..(3)
( x0  x1 ) ( x1  x0 )

Each term on the right hand side of (3) involves linear factor . Hence the sum is a polynomial of
degree  1 . The quotients in (3) are denoted by

( x  x1 ) ( x  x0 )
L1,0 ( x )  , L1,1 ( x )  ……(4)
( x0  x1 ) ( x1  x0 )

2
which are called the Lagrange coefficients polynomials based on the nodes x0 and x1 . Using this
notation , (3) can be written in summation form

1
P1 ( x )   yk L1,k  y0 L1,0  y1 L1,1 ……………..(5)
k 0
The generalization of (5) is the construction of a polynomial PN ( x ) of degree at most N that passes
through the N  1 points ( x0 , y0 ),( x1 , y1 ),...,( x N , y N ) and has the form

N
PN ( x )   yk LN ,k ( x) ……………..(6)
k 0

where

 x  xj 
N

j 0
jk
LN ,k ( x )  …………..(7)
  xk  x j 
N

j 0
jk

Using (6) and (7) , find 1st , 2nd, and 3rd Lagrange Interpolation polynomial.

 1st order Lagrange interpolation polynomial

1
P1 ( x )   yk L1,k  y0 L1,0  y1 L1,1
k 0
where

( x  x1 ) ( x  x0 )
L1,0 ( x )  , L1,1 ( x ) 
( x0  x1 ) ( x1  x0 )

3
 2nd order Lagrange interpolation polynomial

2
P2 ( x )   yk L2,k  y0 L2,0  y1 L2,1  y2 L2,2
k 0
where

( x  x1 )( x  x2 ) ( x  x0 )( x  x2 ) ( x  x0 )( x  x1 )
L2,0 ( x )  , L2,1 ( x )  , L2,2 ( x ) 
( x0  x1 )( x0  x2 ) ( x1  x0 )( x1  x2 ) ( x2  x0 )( x2  x1 )

 3rd order Lagrange interpolation polynomial

3
P3 ( x )   yk L3,k  y0 L3,0  y1 L3,1  y2 L3,2  y3 L3,3
k 0
where

( x  x1 )( x  x2 )( x  x3 ) ( x  x0 )( x  x2 )( x  x3 )
L3,0 ( x )  , L3,1 ( x ) 
( x0  x1 )( x0  x2 )( x0  x3 ) ( x1  x0 )( x1  x2 )( x1  x3 )
( x  x0 )( x  x1 )( x  x3 ) ( x  x0 )( x  x1 )( x  x2 )
L3,2 ( x )  , L3,3 ( x ) 
( x2  x0 )( x2  x1 )( x2  x3 ) ( x3  x0 )( x3  x1 )( x3  x2 )

ERROR TERMS AND ERROR BOUNDS

Theorem : Assume that f  C N 1  a, b and that x0 , x1 ,..., x N   a, b are N  1 nodes. If


x   a, b then,

f ( x)  PN ( x)  E N ( x) ………………..(1)

where PN ( x ) polynomial that can be approximate f ( x ) .

N
f ( x )  PN ( x )   yk LN ,k ( x) …………(2)
k 0

4
The error term E N ( x ) has the form

E N ( x) 
 x  x0   x  x1  ...  x  x N  f ( N 1) (c ) ....................( 3)
 N  1 !

for some value of c  c ( x ) that lies in the interval  a, b 

 x  x0   x  x1  ...  x  x N 
E N ( x)  M ..................( 4)
 N  1 !
M max f ( N 1) (c )
x  x x
0 N

Theorem : (Error bounds for Lagrange Interpolation, equally space nodes)

Assume that f ( x ) defined on  a, b , which contains equally space nodes xk  x0  hk .


Additionally, assume that f ( x ) and the derivatives of f ( x ) up to the N+1 , are continuous and
bounded on the special subinterval  x0 , x1 ,  x1 , x2  and  x2 , x3  respectively ; that is

M  f ( N 1) (c)  M N 1 for x0  x  x N N  1, 2, 3

The error terms corresponding the cases N=1,2,3 have the following useful bounds on their
magnitude.

h2 M 2
E1 ( x )  valid for  x0 , x1 
8
3
h M3
E2 ( x )  valid for  x0 , x2 
9 3
h4 M 4
E3 ( x )  valid for  x0 , x3 
24

5
Example : The function y  sin x is tabulated as

 
x 0 4 2

y 0 0.707 1


Using lagrange interpolation polynomial, find its value at x  estimate the error.
6
Solution
 
Given x0  0, x1  , x2  , y0  0, y1  0.707 , y2  1
4 2

Find P2 ( x ), P2 ( ) and E2 ( x )
6

2
P2 ( x )   yk L2,k  y0 L2,0  y1 L2,1  y2 L2,2  0  y1 L2,1  y2 L2,2 (where, y0  0 then y0 L2,0  0)
k 0


 x  0   x  
( x  x0 )( x  x2 )  2  16  2  x 
L2,1 ( x )    x  
( x1  x0 )( x1  x2 )        2  2 
  0   
4  4 2 

( x  x0 )( x  x1 )
 x  0   x   8 x
 4 
L2,2 ( x )    2  x2  
( x2  x0 )( x2  x1 )         4 
  0   
2  2 4 
 16   x   8  2  x 
P2 ( x )  0.707  2  x 2    1 2  x    1.146 x  1.8 x  0.81 x  0.636 x
2 2

  2     4  
P2 ( x )  0.336 x 2  1.164 x

       
2
P2    0.336    1.164    0.517  P2    0.517
6 6 6 6
h3 M 3 
E2 ( x )  where h 
9 3 4
 
Find M 3 , f ( 3) ( x )  M 3 in  0, 
 2
f ( x )  cos x , f ( x )   sin x , f ( x )   cos x
 
f ( x )   cos x maximum value of f ( x ) in  0,  M 3   cos 0  1 then
 2
 
3
1
h3 M 3  4 
E2 ( x )    0.03
9 3 9 3

6
Exercise 1:

Find Lagrange interpolation polynomial which agrees with the following data and obtain a bound
x
for the errors in estimating the function f ( x )  sin  .
 2 

x 0 0.5 1

y 0 0.707 1

Exercise 2:

Consider y  cos x over  0, 1.2 . Determine the error bounds for the Lagrange polynomials
P1 ( x), P2 ( x) and P3 ( x) .

Exercise 3:
a) Find a second degree polynomial approximating the function f ( x)  x  ln x , and
passing from the points  1, f (1)  ,  2, f (2)  and (4, f (4)) .
b) Approximate f (2.5) using the polynomial in part (a)
c) use the error formula

f ( N 1) (c)
E N ( x)   x  x0   x  x1  x  x2  ... x  x N 
 N  1 !
To estimate the error at x=2.5

Exercise 4: Use lagrange interpolation to approximate y(0) for the


following data.

x 2 3 4
y 5 4 2

7
NEWTON POLYNOMIALS
If the Lagrange interpolation are used , there is no constructive relationship between
PN 1 ( x) and PN ( x) . Each polynomial has to be constructed individually and the work required
to compute the higher degree polynomials involves many computations.
We take the new approach and construct Newton’s polynomials that have the recursive pattern.

P1 ( x )  a0  a1 ( x  x0 ) (1)

P2 ( x )  a0  a1 ( x  x0 )  a2 ( x  x0 )( x  x1 )  P1 ( x )  a2 ( x  x0 )( x  x1 ) ( 2)

P3 ( x )  a0  a1 ( x  x0 )  a2 ( x  x0 )( x  x1 )  a3 ( x  x0 )( x  x1 )( x  x2 )
 P2 ( x )  a3 ( x  x0 )( x  x1 )( x  x3 ) ( 3)
.
.
.
PN ( x )  PN 1 ( x )  a N ( x  x0 )( x  x1 )( x  x3 )...( x  x N 1 ) (4)

The polynomial (4) is said to be Newton Polynomial with N centers x0 , x1 ,..., x N 1 . It involves
sums of products of linear factors up to

a N ( x  x0 )( x  x1 )( x  x3 )...( x  x N 1 )

So PN ( x ) will simply to be an ordinary polynomials of degree  N .

The Newton interpolation uses a divided difference method. The technique allows one to
add additional points easily

P  x   a0  a1  x  x0   a2  x  x0   x  x1  

For given set of data points:  x0 , y0  ,  x1 , y1  and  x2 , y2 


• If three data points are available, the estimate is improved by introducing some
curvature into the line connecting the points.

P2 ( x)  a0  a1 ( x  x0 )  a2 ( x  x0 )( x  x1 )

8
 A simple procedure can be used to determine the values of the coefficients

x  x0 a0  f ( x 0 )
f ( x1 )  f ( x0 )
x  x1 a1 
x1  x0
f ( x2 )  f ( x1 ) f ( x1 )  f ( x0 )

x2  x1 x1  x0
x  x2 a2 
x 2  x0

General Form of Newton’s Interpolating Polynomials

PN ( x )  f ( x0 )  ( x  x0 ) f [ x1 , x0 ]  ( x  x0 )( x  x1 ) f [ x2 , x1 , x0 ]
  ( x  x0 )( x  x1 ) ( x  x N 1 ) f [ x N , x N 1 , , x0 ]
a0  f ( x 0 )
a1  f [ x1 , x0 ]
a2  f [ x2 , x1 , x0 ]

a N  f [ x N , x N 1 , , x 1 , x0 ]
f ( xi )  f ( x j )
f [ xi , x j ] 
xi  x j
f [ xi , x j ]  f [ x j , xk ]
f [ xi , x j , xk ] 
xi  xk

, x1 ]  f [ x N 1 , x N  2 , , x0 ]
f [ x N , x N 1 ,
f [ x N , x N 1 , , x1 , x0 ] 
x N  x0
and use to construct the divided differences in the following table

xk f  xk  f ,  f ,,  f ,,,  f ,,,, 

x0 f  x0 

x1 f  x1  f  x1 , x0 

x2 f  x2  f  x2 , x1  f  x2 , x1 , x0 

x3 f  x3  f  x3 , x2  f  x3 , x2 , x1  f  x3 , x2 , x1 , x0 

x4 f  x4  f  x4 , x3  f  x4 , x3 , x2  f  x4 , x3 , x2 , x1  f  x4 , x3 , x2 , x1 , x0 

9
Theorem : Newton Polynomial

Suppose that x0 , x1 ,..., x N 1 are N+1 distinct numbers in  a, b . There exist a unique
polynomial PN ( x ) of degree at most N with the property that

 
f x j  PN x j   for j  0, 1,..., N

The Newton form polynomial is

PN ( x)  PN 1 ( x)  a N ( x  x0 )( x  x1 )( x  x3 )...( x  x N 1 )

where ak  f  xk , xk 1 ,..., x1 , x0  for k  0, 1,..., N and the Newton approximation

f ( x)  PN ( x)  E N ( x)
then

E N ( x) 
 x  x0   x  x1  ... x  x N  f ( N 1) (c)
 N  1 !

10
EXAMPLE 1: Let f ( x )  x3  4 x

Construct the divided difference table based on the nodes x0  1 , x1  2 , x2  3 , x3  4 , x4  5 , x5  6 .


Find the Newton polynomials P3 ( x) base on the above nodes.

xk f  xk  f ,  f , ,  f , , ,  f  , , , ,

x0  1 f (1)  3

x1  2 f (2)  0 0  (3)
3
2 1

x2  3 f (3)  15 15  0 15  3
 15 6
3 2 3 1

x3  4 f (4)  48 48  15 33  15 96
 33 9 1
43 42 4 1

x4  5 f (5)  105 105  48 57  33 12  9 11


 57  12 1 0
54 53 52 5 1
x5  6 1 1
f (6)  192 192  105 0
87  57 15  12 62
 87  15 1
65 64 63

Where a0  3 , a1  3, a2  6, a3  1, a4  0

P3 ( x)  a0  a1  x  x0   a2  x  x0   x  x1   a3  x  x0   x  x1  x  x2 

P3 ( x)  3  3  x  1  6  x  1 x  2   1 x  1 x  2  x  3 
then add like terms

P3 ( x)  x3  4 x

11
EXAMPLE 2: For the function y  f ( x) , given the following table, use the divided difference
to determine highest possible order and use the Newton’s polynomial to determine the valu of
11
x if f ( x )  .
3

xk f  xk  f ,  f , , 

x0  0 f (0)  1
= a0

x1  1 f (1)  2 2 1
 1 = a1
1 0

x2  3 f (3)  6 62 2 1 1
2  = a2
3 1 30 3

Highest possible order 2nd order

P2 ( x)  a0  a1  x  x0   a2  x  x0   x  x1 
1
P2 ( x)  1  1 x  0    x  0  x  1
3
then add like terms
1 2 11
P2 ( x)  x 2  x  1 find x where f ( x ) 
3 3 3
1 2 2 11 1 2 8
x  x 1   x2  x   0  x2  2x  8  0
3 3 3 3 3 3
 x  4  ( x  2)  0 then x  4 and x  2

x  2   0,3 , x  4   0,3

12
Exercise 1: Use the Newton divided-difference formula to compute the cubic interpolating
x
polynomial P3 ( x ) for the function f ( x )  sin( ) using interpolation points
2
x0  0 , x1  1 , x2  2 and x3  3 . What is an upper bound for the error at x=0.5 ?

Exercise 2: Given the table of the function f ( x)  2 x

X 0 1 2 3
f(x) 1 2 4 8

a) Write down the Newton polynomials P1(x), P2(x), P3(x).


b) Evaluate f(2.5) by using P3(x).

Exercise 3:For the function y  f ( x) given the following table, use the divided differences to
determine highest possible order and use Newton’s polynomial to determine the value of x if
f ( x )  0

x 0 1 2

y 0 -3 -4

13

You might also like