CH6 (1) Interpolation
CH6 (1) Interpolation
CH6 (1) 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
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 n1 )
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
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
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.
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
Solution:
(i) Applying Lagrange’s formula, we have
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
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)
Velocity v(t)
600
pt = -0.0002 0.0240 -0.4267 28.2000
-34.2000 400
200
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
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
19
3. The table below gives the values of
4 5 7 9 11
62 95 185 307 461
20
4. The table below gives the values of x and f(x):
x -2 -1 0 3
f(x) 12 14 10 22
21
22