Professional Documents
Culture Documents
5 Interpolation
5 Interpolation
b0 = b1 = b2 = ... = 2
Numerical Analysis
Interpolation
What is Interpolation ?
• For example, there is only one straight line that connects two
points.
• Although there is only one nth order polynomial that fits n+1
points, there are a variety of mathematical formats that this
polynomial can be expressed. Examples are:
• Direct Method
• Newton polynomials
• Lagrange polynomials
Direct Method
Given ‘n+1’ data points (x0,y0), (x1,y1),………….. (xn,yn),
pass a polynomial of order ‘n’ through the data as given
below:
y = a0 + a1 x + .................... + an x . n
5 http://numericalmethods.eng.usf.edu
Example 1
The upward velocity of a rocket is given as a
function of time in Table 1.
Find the velocity at t=16 seconds using the
direct method for linear interpolation.
Table 1 Velocity as a function
of time.
t , (s ) v(t ), (m/s)
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67 Figure 2 Velocity vs. time data for the
rocket example
6 http://numericalmethods.eng.usf.edu
Linear Interpolation
v(t ) = a0 + a1t y
Hence
v(t ) = −100.93 + 30.914t , 15 t 20.
v(16) = −100.93 + 30.914(16) = 393.7 m/s
7 http://numericalmethods.eng.usf.edu
Example 2
The upward velocity of a rocket is given as a
function of time in Table 2.
Find the velocity at t=16 seconds using the
direct method for quadratic interpolation.
Table 2 Velocity as a function
of time.
t , (s ) v(t ), (m/s)
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67 Figure 5 Velocity vs. time data for the
rocket example
8 http://numericalmethods.eng.usf.edu
Quadratic Interpolation
y
f 2 (x )
v(20 ) = a0 + a1 (20 ) + a2 (20 ) = 517 .35
2
( x0 , y 0 )
x
ys
(
f x des ired ) 350
250
227.04 200
10 12 14 16 18 20
10 x s range x des ired 20
t , (s ) v(t ), (m/s)
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67 Figure 6 Velocity vs. time data for the
rocket example
11 http://numericalmethods.eng.usf.edu
Cubic Interpolation
y
(x3 , y3 )
v(t ) = a0 + a1t + a2t + a3t
2 3
(x1 , y1 )
v(10 ) = 227 .04 = a0 + a1 (10 ) + a2 (10 ) + a3 (10 )
2 3
f 3 (x )
v(15 ) = 362 .78 = a0 + a1 (15 ) + a2 (15 ) + a3 (15 )
2 3 (x2 , y2 )
(x0 , y0 )
12 http://numericalmethods.eng.usf.edu
Cubic Interpolation (contd)
v(t ) = −4.2540 + 21.266t + 0.13204t 2 + 0.0054347t 3 , 10 t 22.5
v(16) = −4.2540 + 21.266(16) + 0.13204(16) + 0.0054347(16)
2 3
= 392.06 m/s
700
(
f x des ired )
392.06 − 392.19
400
300
a = 100
392.06
227.04 200
10
10
12 14 16 18
x s range x des ired
20 22 24
22.5
= 0.033269%
13 http://numericalmethods.eng.usf.edu
Comparison Table
Table 4 Comparison of different orders of the polynomial.
Order of
t(s) v (m/s) 1 2 3
Polynomial
0 0
v(t = 16) m/s 393.7 392.19 392.06
10 227.04
15 362.78 Absolute Relative
---------- 0.38410 % 0.033269 %
Approximate Error
20 517.35
22.5 602.97
30 901.67
14 http://numericalmethods.eng.usf.edu
Distance from Velocity Profile
Find the distance covered by the rocket from t=11s to t=16s ?
v(t ) = −4.3810 + 21.289t + 0.13064t 2 + 0.0054606t 3 , 10 t 22.5
16
s(16) − s(11) = v(t )dt
11
( )
16
= − 4.2540 + 21.266t + 0.13204t 2 + 0.0054347t 3 dt
11
16
t2 t3 t4
= − 4.2540t + 21.266 + 0.13204 + 0.0054347
2 3 4 11
= 1605 m
15 http://numericalmethods.eng.usf.edu
Acceleration from Velocity Profile
Find the acceleration of the rocket at t=16s given that
𝜈 𝑡 = −4.2540 + 21.266𝑡 + 0.13204𝑡 2 + 0.0054347𝑡 3 , 10 ≤ 𝑡 ≤ 22.5
a(t ) = v(t )
d
dt
=
d
dt
(
− 4.2540 + 21.266t + 0.13204t 2 + 0.0054347t 3 )
= 21.289 + 0.26130t + 0.016382t 2 , 10 t 22.5
= 29.665 m/s 2
16 http://numericalmethods.eng.usf.edu
Newton’s Divided
Difference Method of
Interpolation
Newton’s Divided Difference Method
• A further generalization of the shifted power form is the Newton form
Newton Form
Page 18
P( x) = a0 + ai (x − c j )
n i
i =1 j =1
Newton’s Divided Difference Method
where
b0 = f ( x0 )
f ( x1 ) − f ( x0 )
b1 =
x1 − x0
19 http://numericalmethods.eng.usf.edu
Example
The upward velocity of a rocket is given as a function of
time in Table 1. Find the velocity at t=16 seconds using
the Newton Divided Difference method for linear
interpolation.
Table. Velocity as a
function of time
v(t ) = b0 + b1 (t − t 0 ) 500
ys
v(t1 ) − v(t 0 )
b1 = = 30.914 362.78
t1 − t 0
350
10 12 14 16 18 20 22 24
x s − 10 x s range x des ired x s + 10
0 1
21 http://numericalmethods.eng.usf.edu
Linear Interpolation (contd)
550
517.35
500
ys
f ( range)
450
(
f x des ired )
400
362.78 350
10 12 14 16 18 20 22 24
x s − 10 x s range x des ired x s + 10
v(t ) = b0 + b1 (t − t 0 )
0 1
22
= 393.69 m/s http://numericalmethods.eng.usf.edu
Quadratic Interpolation
Given ( x 0 , y 0 ), ( x1 , y1 ), and ( x2 , y 2 ), fit a quadratic interpolant through the data.
f 2 ( x) = b0 + b1 ( x − x0 ) + b2 ( x − x0 )( x − x1 )
b0 = f ( x0 )
f ( x1 ) − f ( x0 )
b1 =
x1 − x0
f ( x2 ) − f ( x1 ) f ( x1 ) − f ( x0 )
−
x2 − x1 x1 − x0
b2 =
x 2 − x0
23 http://numericalmethods.eng.usf.edu
Example
The upward velocity of a rocket is given as a function of
time in Table 1. Find the velocity at t=16 seconds using
the Newton Divided Difference method for quadratic
interpolation.
Table. Velocity as a
function of time
500
450
ys
400
f ( range)
(
f x des ired ) 350
300
250
227.04 200
10 12 14 16 18 20
10 x s range x des ired 20
t 0 = 10 , v(t 0 ) = 227.04
t1 = 15, v(t1 ) = 362.78
t 2 = 20, v(t 2 ) = 517.35
25 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
b0 = v(t 0 )
= 227.04
v(t ) − v(t 0 ) 362.78 − 227.04
b1 = 1 =
t1 − t 0 15 − 10
= 27.148
= 0.38502 %
27 http://numericalmethods.eng.usf.edu
General Form
f 2 ( x) = b0 + b1 ( x − x0 ) + b2 ( x − x0 )( x − x1 )
where
b0 = f [ x0 ] = f ( x0 )
f ( x1 ) − f ( x 0 )
b1 = f [ x1 , x0 ] =
x1 − x0
f ( x 2 ) − f ( x1 ) f ( x1 ) − f ( x0 )
−
f [ x 2 , x1 ] − f [ x1 , x0 ] x 2 − x1 x1 − x0
b2 = f [ x 2 , x1 , x0 ] = =
x 2 − x0 x 2 − x0
Rewriting
f 2 ( x) = f [ x0 ] + f [ x1 , x0 ]( x − x0 ) + f [ x2 , x1 , x0 ]( x − x0 )( x − x1 )
28 http://numericalmethods.eng.usf.edu
General form
The third order polynomial, given ( x 0 , y 0 ), ( x1 , y1 ), ( x2 , y 2 ), and ( x3 , y 3 ), is
f 3 ( x) = f [ x0 ] + f [ x1 , x0 ]( x − x0 ) + f [ x 2 , x1 , x0 ]( x − x0 )( x − x1 )
+ f [ x3 , x 2 , x1 , x0 ]( x − x0 )( x − x1 )( x − x 2 )
b0
x0 f ( x0 ) b1
f [ x1 , x 0 ] b2
x1 f ( x1 ) f [ x 2 , x1 , x0 ] b3
f [ x2 , x1 ] f [ x3 , x2 , x1 , x0 ]
x2 f ( x2 ) f [ x3 , x 2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )
29 http://numericalmethods.eng.usf.edu
General Form
Given (n + 1) data points, (x0 , y0 ), (x1 , y1 ),......, (xn−1 , yn−1 ), (xn , yn ) as
f n ( x) = b0 + b1 ( x − x0 ) + .... + bn ( x − x0 )( x − x1 )...(x − xn−1 )
where
b0 = f [ x0 ] i −1
pn ( x) = f x0 ,, xi (x − x j )
n
b1 = f [ x1 , x0 ]
i =0 j =0
b2 = f [ x2 , x1 , x0 ]
bn−1 = f [ xn−1 , xn−2 ,...., x0 ]
bn = f [ xn , xn−1 ,...., x0 ]
Slope = f [ xk −1 , xk ] Slope = f [ xk +1 , xk + 2 ]
Slope = f [ xk , xk +1 ]
Page 31
xk −1 xk xk +1 xk + 2
Divided Difference
• For linear interpolation 1st divided difference
f ( x1 ) − f ( x0 )
f ( x) = f ( x0 ) + (x − x0 )
x1 − x0
A0
A1 = f [ x0 , x1 ]
f ( xk +1 ) − f ( xk )
1st order f [ xk , xk +1 ] =
divided difference xk +1 − xk
Page 32
f [ xk , xk +1 ] − f [ xk −1 , xk ]
2nd order f [ xk −1 , xk , xk +1 ] =
divided difference xk +1 − xk −1
f [ x1 , x2 ,, xk ] − f [ x0 , x1 ,, xk −1 ]
kth order f [ x0 , x1 ,, xk ] =
divided difference xk − x0
Example
The upward velocity of a rocket is given as a function of
time in Table 1. Find the velocity at t=16 seconds using
the Newton Divided Difference method for cubic
interpolation.
Table. Velocity as a
function of time
35 http://numericalmethods.eng.usf.edu
Example
Hence
v (t ) = b0 + b1 (t − t 0 ) + b2 (t − t 0 )( t − t1 ) + b3 (t − t 0 )( t − t1 )(t − t 2 )
= 227.04 + 27.148( t − 10) + 0.37660(t − 10)(t − 15)
+ 5.4347 * 10 −3 (t − 10)( t − 15)( t − 20)
At t = 16,
v (16) = 227.04 + 27.148(16 − 10) + 0.37660(16 − 10)(16 − 15)
+ 5.4347 * 10 −3 (16 − 10)(16 − 15)(16 − 20)
= 392.06 m/s
The absolute relative approximate error a obtained is
392 .06 − 392 .19
a = x100
392 .06
= 0.033427 %
36 http://numericalmethods.eng.usf.edu
Comparison Table
Order of 1 2 3
Polynomial
v(t=16) 393.69 392.19 392.06
m/s
Absolute Relative ---------- 0.38502 % 0.033427 %
Approximate Error
37 http://numericalmethods.eng.usf.edu
Distance from Velocity Profile
Find the distance covered by the rocket from t=11s to
t=16s ?
v (t ) = 227.04 + 27.148(t − 10) + 0.37660( t − 10)( t − 15)
10 t 22.5
+ 5.4347 * 10 (t − 10)( t − 15)( t − 20)
−3
16
= ( − 4.2541 + 21.265t + 0.13204t 2 + 0.0054347t 3 ) dt
11
16
t2 t3 t4
= − 4.2541t + 21.265 + 0.13204 + 0.0054347
2 3 4 11
38 = 1605 m http://numericalmethods.eng.usf.edu
Acceleration from Velocity Profile
Find the acceleration of the rocket at t=16s given that
a(t ) =
d
dt
v(t ) =
d
(
dt
− 4.2541 + 21.265t + 0.13204t 2 + 0.0054347t 3 )
= 21.265 + 0.26408t + 0.016304t 2
a(16) = 21.265 + 0.26408(16) + 0.016304(16) 2
= 29.664 m / s 2
39 http://numericalmethods.eng.usf.edu
Lagrangian Interpolation
Lagrangian interpolating polynomial is given by
n
f n ( x) = Li ( x) f ( xi )
i =0
where ‘ n ’ in f n (x) stands for the n th order polynomial that approximates the function y = f (x)
1
v(t ) = Li (t )v(ti ) 500
i =0
= L0 (t )v (t 0 ) + L1 (t )v (t1 )
ys
f ( range)
450
(
f x des ired )
42
Linear Interpolation (contd)
1 t −tj t − t1
L0 (t ) = =
j =0 t0 − t j t 0 − t1
j 0
1 t −tj t − t0
L1 (t ) = =
j =0 t1 − t j t1 − t 0
j 1
t − t1 t − t0 t − 20 t − 15
v(t ) = v(t 0 ) + v(t1 ) = (362.78) + (517.35)
t 0 − t1 t1 − t 0 15 − 20 20 − 15
16 − 20 16 − 15
v(16) = (362.78) + (517.35)
15 − 20 20 − 15
= 0.8(362.78) + 0.2(517.35)
= 393.7 m/s.
43 http://numericalmethods.eng.usf.edu
Quadratic Interpolation
For the second order polynomial interpolation (also called quadratic interpolation), we
choose the velocity given by
2
v (t ) = Li ( t ) v(t i )
i =0
= L0 (t )v (t 0 ) + L1 (t ) v( t1 ) + L2 (t ) v( t 2 )
44 http://numericalmethods.eng.usf.edu
Example
The upward velocity of a rocket is given as a function of
time in Table 1. Find the velocity at t=16 seconds using
the Lagrangian method for quadratic interpolation.
Table Velocity as a
function of time
t (s) v(t ) (m/s)
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
ys
400
f ( range)
2 t −tj t − t1 t − t 2
L0 (t ) = = (
f x des ired ) 350
j =0 t0 − t j t −
0 1 0 2
t t − t
j 0
300
2 t −t j t − t0 t − t 2
L1 (t ) = =
j =0 t1 − t j t1 − t 0 t1 − t 2 250
j 1
j =0 t2 − t j −
2 0 2 1
t t t − t 10 x s range x des ired 20
j 2
46 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
t − t1 t − t 2 t − t0 t − t2 t − t0 t − t1
v(t ) = v(t0 ) + v(t1 ) + v(t2 )
t0 − t1 t0 − t2 t1 − t0 t1 − t2 t2 − t0 t2 − t1
16 − 15 16 − 20 16 − 10 16 − 20 16 − 10 16 − 15
v(16) = (227 .04 ) + (362 . 78 ) + (517.35)
10 − 15 10 − 20 15 − 10 15 − 20 20 − 10 20 − 15
= (− 0.08)(227.04) + (0.96)(362.78) + (0.12)(527.35)
= 392.19 m/s
The absolute relative approximate error a obtained between the
results from the first and second order polynomial is
392.19 − 393.70
a = 100
392.19
= 0.38410%
47 http://numericalmethods.eng.usf.edu
Cubic Interpolation
For the third order polynomial (also called cubic interpolation), we choose the velocity given by
3
v (t ) = Li ( t ) v(t i )
i =0
600
ys 500
f ( range)
(
f x des ired )
400
300
227.04 200
10 12 14 16 18 20 22 24
10 x s range x des ired 22.5
48 http://numericalmethods.eng.usf.edu
Example
The upward velocity of a rocket is given as a function of
time in Table 1. Find the velocity at t=16 seconds using
the Lagrangian method for cubic interpolation.
Table Velocity as a
function of time
t (s) v(t ) (m/s)
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
700
3 t −tj t − t 1 t − t 2 t − t 3 602.97
L0 (t ) = = ;
j =0 t0 − t j t 0 − t 1 t 0 − t 2 t 0 − t 3 600
j 0
3 t −t j t − t0 t − t 2 t − t 3
L1 (t ) = =
ys 500
j =0 t1 − t j t1 − t 0 t1 − t 2 t1 − t 3 f ( range)
j 1 (
f x des ired )
400
3 t −tj t − t 0 t − t1 t − t 3
L2 (t ) = = ;
t2 − t j 2 0 2 1 t 2 − t 3
t − t t − t
300
j =0
j 2
t −tj t − t 0 t − t1 t − t 2
227.04 200
3
L3 ( t ) =
10 12 14 16 18 20 22 24
= 10 x s range x des ired 22.5
j =0 t3 − t j − t t −
3 0 3 1 3 2
t t t − t
j 3
50 http://numericalmethods.eng.usf.edu
Cubic Interpolation (contd)
𝑡 − 𝑡1 𝑡 − 𝑡2 𝑡 − 𝑡3 𝑡 − 𝑡0 𝑡 − 𝑡2 𝑡 − 𝑡3
𝑣 𝑡 = 𝑣 𝑡𝑜 + 𝑣 𝑡1
𝑡0 − 𝑡1 𝑡0 − 𝑡2 𝑡0 − 𝑡3 𝑡1 − 𝑡0 𝑡1 − 𝑡2 𝑡1 − 𝑡3
𝑡 − 𝑡0 𝑡 − 𝑡1 𝑡 − 𝑡3 𝑡 − 𝑡1 𝑡 − 𝑡1 𝑡 − 𝑡2
+ 𝑣 𝑡2 + 𝑣 𝑡3
𝑡2 − 𝑡0 𝑡2 − 𝑡1 𝑡2 − 𝑡3 𝑡3 − 𝑡1 𝑡3 − 𝑡1 𝑡3 − 𝑡2
𝑣 16
16 − 15 16 − 20 16 − 22.5
= 227.04
10 − 15 10 − 20 10 − 22.5
16 − 10 16 − 20 16 − 22.5
+ 362.78
15 − 10 15 − 20 15 − 22.5
16 − 10 16 − 15 16 − 22.5
+ 517.35
20 − 10 20 − 15 20 − 22.5
16 − 10 16 − 15 16 − 20
+ 602.97
22.5 − 10 22.5 − 15 22.5 − 20
= −0.0416 227.04 + 0.832 362.78 + 0.312 517.35
= 392.06m/s
392.06 − 392.19
a = 100
392.06
51
= 0.033269% http://numericalmethods.eng.usf.edu
Comparison Table
Order of
1 2 3
Polynomial
v(t=16) m/s 393.69 392.19 392.06
Absolute Relative
-------- 0.38410% 0.033269%
Approximate Error
52 http://numericalmethods.eng.usf.edu
Distance from Velocity Profile
Find the distance covered by the rocket from t=11s to
t=16s ?
v(t ) = (t 3 − 57.5t 2 + 1087.5t − 6750)(−0.36326) + (t 3 − 52.5t 2 + 875t − 4500)(1.9348)
+ (t 3 − 47.5t 2 + 712.5t − 3375)(−4.1388) + (t 3 − 45t 2 + 650t − 3000)(2.5727)
v (t ) = −4.245 + 21.265t + 0.13195t 2 + 0.00544t 3 , 10 t 22.5
16
s(16) − s (11) = v( t ) dt
11
16
( −4.245 + 21.265t + 0.13195t 2 + 0.00544t 3 ) dt
11
t2 t3 t 4 16
= [ −4.245t + 21.265 + 0.13195 + 0.00544 ]11
2 3 4
= 1605 m
53 http://numericalmethods.eng.usf.edu
Acceleration from Velocity Profile
Find the acceleration of the rocket at t=16s given that
dt dt
= 29.665 m / s 2
54 http://numericalmethods.eng.usf.edu
Lagrange Polynomial
Example: By using the nodes x0=2.0, x1=2.5, and x2=4.0 find the second
order interpolating polynomial for f ( x ) = 1 / x .
Let’s first calculate the Lagrange coefficients:
L2, 0 ( x ) =
(x − 2.5)(x − 4.0) = (x − 6.5)x + 10
(2.0 − 2.5)(2.0 − 4.0)
L2,1 ( x ) =
( x − 2.0 )( x − 4.0 )
=
( − 4 x + 24 )x − 32
Page 55 (2.5 − 2.0)(2.5 − 4.0) 3
L2, 2 ( x ) =
( x − 2.0 )( x − 2.5)
=
( x − 4.5)x + 5
(4.0 − 2.0)(4.0 − 2.5) 3
Page 56
Lagrange Polynomial Disadvantages
P2 (1.5) =
(1.5 − 1.6)(1.5 − 1.9) f (1.3) + (1.5 − 1.3)(1.5 − 1.9) f (1.6)
(1.3 − 1.6)(1.3 − 1.9) (1.6 − 1.3)(1.6 − 1.9)
+
(1.5 − 1.3)(1.5 − 1.6) f (1.9) = 0.5112857
(1.9 − 1.3)(1.9 − 1.6)
Divided Difference
𝑥0 = 1.3, 𝑥1 = 1.6, 𝑥2 = 1.9 ⇒ 𝑃2 1.5 = 0.5112857
x0 = 1.0, x1 = 1.3, x2 = 1.6 P2 (1.5) = 0.5124715
2 1.6 0.4554022
3 1.9 0.2818186
4 Page
2.2 610.1103623
Divided Difference
Now let’s use the divided difference technique to obtain the same result.
i xi f (xi )
0 1.0 0.7651977
− 0.4837057
1 1.3 0.6200860 − 0.1087339
− 0.5489460 0.0658784
2 1.6 0.4554022 − 0.0494433 0.0018251
− 0.5786120 0.0680685
3 1.9 0.2818186 0.0118183
− 0.5715210
Page
2.2 620.1103623
4
Divided Difference
Now let’s use the divided difference technique to obtain the same result.
i xi f (xi )
0 1.0 0.7651977
− 0.4837057
1 1.3 0.6200860 − 0.1087339
− 0.5489460 0.0658784
2 1.6 0.4554022 − 0.0494433 0.0018251
− 0.5786120 0.0680685
3 1.9 0.2818186 0.0118183
− 0.5715210
Page
2.2 630.1103623
4
Theorem: Let f (x) be a real valued function, defined on [a, b] and k+1
f k +1 (c)
Page 64
( x − x0 )( x − x1 )......( x − xk )
(k + 1)!
𝑅 𝑋
=
𝜋 180