(Ch4) - Interpolation-Material
(Ch4) - Interpolation-Material
1. Polynomial Interpolation.
• Lagrange Interpolation.
• Newton’s divided difference method
2. Natural Cubic Spline Interpolation
Why need interpolation?
This called as linear interpolation
General Form of Lagrange
for
i=0,1,2,3 …n
L0(x)=,
L1(x)=
L2(x)=
L3(x)=
Example 1
a)Find the Lagrange interpolating polynomial for
data f(0) = 1, f(2)= -1, f(4)= -1 and f(6)= 1.
b)Hence evaluate f(3), f(5) and f(6.5) if applicable.
Solution;
i 0 1 2 3
xi 0 2 4 6
f(xi) 1 -1 -1 1
Lagrange polynomial; given i=0,1,2,3
Pn ( x) L0 ( x) f ( x0 ) L1 ( x) f ( x1 ) L2 ( x) f ( x2 ) L3 ( x) f ( x3 )
L0 ( x)
x x1 x x2 x x3
x0 x1 x0 x2 x0 x3
L1 ( x)
x x0 x x2 x x3
x1 x0 x1 x2 x1 x3
L2 ( x)
x x0 x x1 x x3
x2 x0 x2 x1 x2 x3
L3 ( x)
x x0 x x1 x x2
x3 x0 x3 x1 x3 x2
L0 ( x )
x x1 x x2 x x3
x 2 x 4 x 6
x0 x1 x0 x2 x0 x3 0 2 0 4 0 6
1
x 2 x 4 x 6
48
L1 ( x)
x x0 x x2 x x3
x 0 x 4 x 6
x1 x0 x1 x2 x1 x3 2 0 2 4 2 6
1
x x 4 x 6
16
L2 ( x)
x x0 x x1 x x3
x 0 x 2 x 6
x2 x0 x2 x1 x2 x3 4 0 4 2 4 6
1
x x 2 x 6
16
L3 ( x)
x x0 x x1 x x2
x 0 x 2 x 4
x3 x0 x3 x1 x3 x2 6 0 6 2 6 4
1
x x 2 x 4
48
1 1
x 2 x 4 x 6 (1) x x 4 x 6 (1)
48 16
1 1
16 x x 2 x 6 ( 1) 48 x x 2 x 4 (1)
b) Hence evaluate f(3), f(5) and f(6.5)
From the table, we only can interpolate xi3 and
5. Coz xi=6.5 is not in interval.
Pn ( x) L0 ( x) f ( x0 ) L1 ( x) f ( x1 ) L2 ( x) f ( x2 ) L3 ( x) f ( x3 )
1 2 3 4
Example 2
Given (x,y) (1,2) , (2,3) and (3,7). Approximate
f(1.5) using Langrange interpolating polynomial.
Solution;
i 0 1 2
xi 1 2 3
f(xi) 2 3 7
How many Lagrange polynomials you need?
L (x) given i = 0,1,2 so we have
i
L0 ( x), L1 ( x), L2 ( x)
L0 ( x)
x x1 x x2 x x3
x 2 x 3
x0 x1 x0 x2 x0 x3 1 21 3
1
x 2 x 3
2
Coz value of last i 2, xi=x2 ….No x3
L1 ( x)
x x0 x x2 x 1 x 3
x1 x0 x1 x2 2 1 2 3
1 x 1 x 3
L2 ( x)
x x0 x x1
x 1 x 2
x2 x0 x2 x1 3 1 3 2
1
x 1 x 2
2
Find f(1.5) with subs x = 1.5 into each Langrange polynomial
1
L0 1.5 2 1.5 3 ,
2
L1 (1)(1.5 1)(1.5 3),
1
L2 (1.5 1)(1.5 2)
2
L0 0.375, L1 0.75, L2 0.125
Using Lagrange polynomial;
Pn ( x) L0 ( x) f ( x0 ) .....Li ( x) f ( xi )
Pn ( x) L0 ( x) f ( x0 ) L1 ( x) f ( x1 ) L2 ( x) f ( x2 )
0.375(2) 0.75(3) 0.125(7) 2.215
xy
Example 3
A robot arm with a rapid laser scanner is doing a quick quality
check on holes drilled in a rectangular plate. The centers of the
holes in the plate describe the path the arm needs to take, and
the hole centers are located on a Cartesian coordinate system
(with the origin at the bottom left corner of the plate) given by
the specifications in Table 1: The coordinates of the holes on
the plate.
x (in.) y (in.)
2.00 7.2
4.25 7.1
5.25 6.0
7.81 5.0
9.20 3.5
10.60 5.0
a) If the laser is traversing from x=2 to
x=4.25 in a linear path, what is the value
of y at x=4 using the Lagrangian method
and a first order polynomial?
Solution;
i x (in.) y (in.)
0 2.00 7.2
7.25 1 4.25 7.1
7.2
7.15
7.1
7.05
7 x=4, y?
0.5 1 1.5 2 2.5 3 3.5
Given;
x0 2.00, y x0 7.2 x1 4.25, y x1 7.1
L0 ( x)
x x1 x x2 x x3
x 4.25
x0 x1 x0 x2 x0 x3 2 4.25
L1 ( x )
x x0
x 2
x1 x0 4.25 2
The value of y when x=4;
L0 ( x) f ( x0 ) L1 ( x) f ( x1 )
4 4.25
(7.2)
4 2
(7.1)
2 4.25 4.25 2
0.8 6.31 7.11inch
xy
Exercise 1
1) A robot arm with a rapid laser scanner is doing a quick
quality check on holes drilled in a rectangular plate. The
centers of the holes in the plate describe the path the arm
needs to take, and the hole centers are located on a
Cartesian coordinate system (with the origin at the bottom
left corner of the plate) given by the specifications in Table
2.
x (in.) y (in.)
2.00 7.2
4.25 7.1
5.25 6.0
7.81 5.0
9.20 3.5
10.60 5.0
a) If the laser is traversing from x=2 to x=4.25
and to x=5.25 in a quadratic path, what is the
value of y at x=4 using a second order
Lagrange polynomial?
( 0) (1) ( 2)
P( x) f 0 f 0 ( x x0 ) f 0 ( x x0 )( x x1 )
0.521 (0.037)( x 2.1) (1.216)( x 2.1)( x 2.4)
P(2.5) subs x 2.5 0.458
b)Find f(2.5) if f(2)= 0.51 is added in the
data given
i xi fi(0) fi(1) fi(2) fi(3)
Find f(2.5);
( 0) (1) ( 2) ( 3)
P ( x ) f0 f0 ( x x 0 ) f0 ( x x 0 )( x x1 ) f0 ( x x 0 )( x x1 )( x x 2 )
0.51 ( 0.11)( x 2.0 ) ( 0.368)( x 2.0 )( x 2.1) ( 1.413)( x 2.0 )( x 2.1)( x 2.4 )
Find f(2.5) =?
(0) (1) ( 2)
P2 ( x) f 0 f 0 ( x x0 ) f 0 ( x x0 )( x x1 )
0.510 (0.645)( x 2.4) (1.217)( x 2.4)( x 2.6)
P2 (2.5) subs x 2.5 0.458
Exercise 2
Page 106No-9
Piecewise Polynomial Approximation
Step 4: Generate formula
Solution;
Step 1: Construct divided difference table
k xk yk hk dk bk
f1 f 0
0 -1 -1 x1 x0 6( d1 d 0 )
h0
1 0 0 f 2 f1
x2 x1 6( d 2 d1 )
h1
2 1 1 f3 f 2
x3 x2
h2
3 2 0
Solve it; yk = fk
k xk yk hk dk bk
4m1 m2 0
()4m1 16m2 48
m2 3.2, m1 0.8
Step 4: Generate equation,
How to know total of k that will be used?
Value of k=4, k=0,1,2,3 .. n-1 = 4-1 = 3
So k=0, k=1, k=2
Clamped Cubic Spline
Exercise
Page 96, No;6