Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CH6 (1) Interpolation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 22

Interpolation

1
Objective:
The technique to study the behavior of the function
through some given points known as interpolation is
introduced.

Methodologies:
Two methods can be used for interpolation. They are

1. Newton’s divided difference interpolation


2. Lagrange Interpolating Polynomial

2
Newton’s divided difference interpolation
The interpolating polynomial p(x) through the points x0 , x1 , x 2 ,    , x n can be
written in the Newton form as
f ( x)  p( x)  a0  a1 ( x  x0 )  a 2 ( x  x0 )( x  x1 )      a n ( x  x0 )( x  x1 )    ( x  x n 1 )
Substituting x  x0 , x1, x 2 ,  , x n , we have
f ( x0 )  a 0
f ( x1 )  f ( x0 )
f ( x1 )  f ( x0 )  a1 ( x1  x0 ) or a1   f [ x0 , x1 ]
x1  x0
f ( x2 )  f ( x0 )  f [ x0 , x1 ]( x2  x0 )  a 2 ( x2  x0 )( x2  x1 )
f ( x 2 )  f ( x0 )
or ( x 2  x1 )a 2   f [ x0 , x1 ]  f [ x 2 , x0 ]  f [ x0 , x1 ]
( x 2  x0 )
f [ x2 , x0 ]  f [ x0 , x1 ] f [ x1 , x2 ]  f [ x0 , x1 ]
or a2    f [ x0 , x1 , x2 ]
( x2  x1 ) ( x 2  x0 )
Continuing the process it can be shown that a n  f [ x0 , x1 , x 2 ,    , xn ]
Thus in terms of the divided differences interpolating polynomial can be written as
p( x)  f ( x0 )  f [ x0 , x1 ]( x  x0 )  f [ x0 , x1 , x2 ]( x  x0 )( x  x1 )  
 f [ x0 , x1 , x 2 ,, xn ]( x  x0 )( x  x1 )  ( x  x n1 )
This is known as Newton’s divided difference interpolation formula.
3
If f (x) is a polynomial through (𝑛 + 1) points x0 , x1 , x 2 ,    , x n , then the polynomial g (x)
through those points with an extra point x  x n 1 is
g ( x)  f ( x)  b( x  x0 )( x  x1 )    ( x  xn )
The constant b can be calculated by substituting x  xn 1.
Example
The table below gives the values of x and f(x):

x: 1 1 2 3 4

f(x) : 7 1 8 29 68

(i) Construct a divided-difference table for the above data.


 (ii) Find the polynomial of least degree that incorporates the values in the
table and find
 (iii) Find by linear interpolation a real root of
 (iv)Find the polynomial that takes the values of the above table and
Solution

(i)The divided difference table for the given data is as follows:


 

x f(x) f1[ ] f2[ ] f3[ ] f4[ ]


-1 -7        
1 -1 3      
2 8 9 2    
3 29 21 6 1  
4 68 39 9 1 0

6
(ii) The needed differences are enclosed by the double lined box.
By Newton’s divided difference formula, we get
f ( x)  7  3( x  1)  2( x  1)( x  1)  1( x  1)( x  1)( x  2)
and f (5)  7  3(6)  2(6)( 4)  1(6)( 4)(3)
 7  18  48  72  131

(iii) Here f (1) f (2)  (1)(8)  8  0


Thus a root is in (1, 2).
From the table, we have
x f(x) 1DD
1 1
2 8 9
Thus the root is the solution of
f ( x)  1  9( x  1)  0
or x  1  19  1.111

7
(iv) The polynomial g (x) can be written as
g ( x)  f ( x)  b( x  1)( x  1)( x  2)( x  3)( x  4)
where b is a constant.
Taking x  5 , we have
g (5)  f (5)  b(6)( 4)(3)( 2)(1)
or 203  131  144b
203  131 72 1
Hence b   
144 144 2
The required polynomial is
g ( x)  f ( x)  12 ( x  1)( x  1)( x  2)( x  3)( x  4)

8
Advantages and Drawbacks:
Newton divided difference interpolation
Advantages of Newton divided difference interpolation:
 Higher-order polynomials can exactly fit larger datasets (by
construction).
 They are simpler to evaluate than non-polynomial approximations.

Drawbacks of Newton divided difference interpolation

 Because of their rigidity (due to smoothness), they tend to over-fit


the data.
 This over-fitting is a serious issue, which is why it is often much
better to use a spline, i.e., a collection of polynomials stitched
together

9
Lagrange Interpolating Polynomial

Lagrange polynomial of degree one passing through two points ( x0 , y 0 ) and ( x1 , y1 ) is written
as
x  x1 x  x0
L1 ( x)  y0  y1
x0  x1 x1  x0
Lagrange polynomial of degree two passing through three points ( x0 , y 0 ) , ( x1 , y1 ) and ( x 2 , y 2 )
is written as
( x  x1 )( x  x2 ) ( x  x0 )( x  x2 ) ( x  x0 )( x  x1 )
L2 ( x)  y0  y1  y2
( x0  x1 )( x0  x2 ) ( x1  x0 )( x1  x2 ) ( x2  x0 )( x2  x1 )

10
Lagrange polynomial of degree three passing through four points ( x0 , y 0 ) , ( x1 , y1 ) , ( x 2 , y 2 ) and
( x3 , y3 ) is written as
( x  x1 )( x  x2 )( x  x3 ) ( x  x0 )( x  x2 )( x  x3 )
L3 ( x)  y0  y1
( x0  x1 )( x0  x2 )( x0  x3 ) ( x1  x0 )( x1  x2 )( x1  x3 )
( x  x0 )( x  x1 )( x  x3 ) ( x  x0 )( x  x1 )( x  x2 )
 y2  y3
( x2  x0 )( x2  x1 )( x2  x3 ) ( x3  x0 )( x3  x1 )( x3  x2 )
In general, the Lagrange polynomial of degree n passing through (n  1) points ( x0 , y 0 ) , ( x1 , y1 )
,    , ( xn , yn ) is written as
( x  x1 )( x  x2 )    ( x  xn ) ( x  x0 )( x  x2 )    ( x  xn )
Ln ( x)  y0  y1
( x0  x1 )( x0  x2 )    ( x0  xn ) ( x1  x0 )( x1  x2 )    ( x1  xn )
( x  x0 )( x  x1 )    ( x  xn 1 )
  yn
( xn  x0 )( xn  x1 )    ( xn  xn 1 )

11
Example
The following table gives the values of an empirical function
x 0 1 2 3
f(x) 4 1 8 29

 (i) Use the Lagrange interpolation formula to estimate


  (ii) the root of the equation

Solution:
(i) Applying Lagrange’s formula, we have

( x  1)( x  2)( x  3) ( x  0)( x  2)( x  3)


f ( x )  4 1
(0  1)(0  2)(0  3) (1  0)(1  2)(1  3)
( x  0)( x  1)( x  3) ( x  0)( x  1)( x  2)
8  29
(2  0)( 2  1)( 2  3) (3  0)(3  1)(3  2)

12
(1.5)(0.5)(0.5) (2.5)(0.5)(0.5)
f (2.5)  4 1
(1)(2)(3) (1)(1)(2)
(2.5)(1.5)( 0.5) (2.5)(1.5)(0.5)
8  29
(2)(1)( 1) (3)( 2)(1)
 0.25  0.3125  7.5  9.0625
 16.625
(ii) Let y  f (x) . Then the root of f ( x)  0 corresponds to y  0 . To find the root let us use the
Lagrange formula in reverse order i.e. consider the polynomial in terms of y.
y 4 1 8 29
x 0 1 2 3

Then
( y  4)( y  8)( y  29) ( y  4)( y  1)( y  29) ( y  4)( y  1)( y  8)
x  0 1 2 3
(1  4)( 1  8)( 1  29) (8  4)(8  1)(8  29) (29  4)( 29  1)( 29  8)

13
When y  0 , then
(4)( 8)( 29) (4)(1)( 29) (4)(1)( 8)
x  0 1 2 3
(3)( 9)( 30) (12)(9)( 21) (33)(30)( 21)
 1.1457  0.1023  0.0046
 1.2434

14
Advantages and Drawbacks: Lagrange Interpolation

Advantages of Lagrange Interpolation


 The answers for Higher-order polynomials will be more accurate.
 For Higher-order polynomials the approximate result converges to the
exact solution very quickly.

Drawbacks of Lagrange interpolation

 It becomes a tedious job to do when the polynomial order


increases the number of points and we need to evaluate
approximate solutions for each point.

15
MATLAB CODE
Write down MATLAB codes using “polyfit(x, y, n)” and “polyval(p, x)” for
the following.
t (s) 10 15 20 22.5 30
v(t) (m/s) 227 363 517 603 903

  a. Find the polynomial of least degree that incorporates all the values in
the table. and estimate the velocities corresponding to . seconds.
b. Draw the figure showing fitted polynomial and the given points.
Graph of v against t
1200
a) >> t=[10 15 20 22.5 30]; b)

>> v=[227 363 517 603 903]; 1000

>> pt=polyfit(t,v,4) 800

Velocity v(t)
600
pt = -0.0002 0.0240 -0.4267 28.2000
-34.2000 400

  200

>> t1=[17 25 30]; 0


5 10 15 20 25 30 35
>> v1=polyval(pt,t1); Time (t)

>> % Output value of v for t


>> t_v =[t1',v1']
t_v = 17.0000 421.9875
25.0000 695.8000
16
30.0000 903.0000
SAMPLE MCQ
1. To study the behavior of the function through only a few discrete sets of values
points a technique known as
(a) Curve fitting, (b) Interpolation, (c)Trapezoidal Rule, (d) None

 2. By inverse Lagrange method find the real root for from the sets of data:

-1 0
-2.5 3

(a) 0.45,
(b) -0.54,
(c) -1,
(d) 2.
3. What is the MATLAB command for finding polynomial from some discrete sets of
values.
(a) polyal(x,y,x0) , (b) polyfit(x,y,n) , (c) Both, (d) None.

17
4. By Newtons Divided Difference method find the polynomial from the data:

1 2
-1 8

  (a) (b) (c) (d)

  5. From the polynomial from question 4, Find .


(a) 40, (b) 45, (c) 35, (d) 30.
 

  6. With the help of question 4 and 5, Find the polynomial which takes
the value
(a) (b) (c) (d)

18
Exercises
1. The table below gives the velocity v at time t
t(s) 1 3 4 7
v(m/s) 3 5 21 201

 i. Construct a divided-difference table for the above data.


ii. Find the polynomial of least degree that incorporates the
values in the table.
iii. Find the acceleration at time .
iv. Find the distance function when .
   2. The table below gives the values of
x -2 0 3 6 7
f(x) 2 -4 -58 842 1802

 (i) Construct a divided-difference table for the above data.


(ii) Find the polynomial which passes through all the points of the table
and find
 (iii) Find the polynomial that takes the values of the above table and

19
  3. The table below gives the values of

4 5 7 9 11
62 95 185 307 461

i. Construct a divided-difference table for the above data.


ii. Find the polynomial which passes through all the points of the table and find f(12).
iii.Find the polynomial g(x) that takes the values of the above table and g (12)=1280.
iv. Use Lagrange interpolating polynomial to estimate
a. The value of f(8 )using two points.
b. The value of x for f(x)=380 using three points.
v. Write down MATLAB codes using “polyfit(x, y, n)” and “polyval(p, x)” for the
following.
vi. Find the polynomial of least degree that incorporates all the values in the table and
estimate the values corresponding to x=1, 3 and 5

20
4. The table below gives the values of x and f(x):

x -2 -1 0 3
f(x) 12 14 10 22

 i.Construct a divided-difference table for the above data.


ii.Find the polynomial of least degree that incorporates the values in the table and
find f(8).
iii.Given g(8)=1202, find the polynomial g(x) that also takes the values of the
above table.
iv. Use Lagrange interpolation formula to find
a. a real root of using linear approximation.
b. a real root of fx=0 using all the points.
v. Write down MATLAB codes using “polyfit(x, y, n)” and “polyval(p, x)” to plot
the figure showing fitted polynomial and the given points.

21
22

You might also like