You are on page 1of 52

Interpolation

1
Direct Method of
Interpolation

2
What is Interpolation ?
Given (x0,y0), (x1,y1), …… (xn,yn), find the value of ‘y’ at a
value of ‘x’ that is not given.

Figure 1 Interpolation of discrete.


3
Interpolants
Polynomials are the most common
choice of interpolants because they
are easy to:
Evaluate
Differentiate, and
Integrate

4
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

where a0, a1,………………. an are real constants.


 Set up ‘n+1’ equations to find ‘n+1’ constants.

 To find the value ‘y’ at a given value of ‘x’, simply


substitute the value of ‘x’ in the above polynomial.

5
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
Linear Interpolation
vt   a0  a1t y

v15  a 0  a1 15  362.78 x1 , y1 

v20  a0  a1 20  517.35 x0 , y0 


f1 x 

Solving the above two equations gives, x

a0  100.93 a1  30.914 Figure 3 Linear interpolation.

Hence
vt   100.93  30.914t , 15  t  20.
v16  100.93  30.91416  393.7 m/s

7
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
Quadratic Interpolation
y

vt   a0  a1t  a2t 2 x1 , y1 


v10  a0  a1 10  a2 10  227.04
2  x2 , y 2 

v15  a0  a1 15  a2 15  362.78


2

f 2 x
v20  a0  a1 20  a2 20  517.35
2
 x0 , y 0 
x

Figure 6 Quadratic interpolation.

Solving the above three equations gives


a0  12.05 a1  17.733 a2  0.3766
9
Quadratic Interpolation (cont.)
550
517.35

v t   12 .05  17 .733t  0.3766 t , 10  t  20


500
2
450

ys

v 16   12.05  17.73316   0.376616 


400
2 f ( range)


f x desired  350

 392.19 m/s 300

250

227.04 200
10 12 14 16 18 20
10 x s  range x desired 20

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%
10
Example 3
The upward velocity of a rocket is given as a
function of time in Table 3.
Find the velocity at t=16 seconds using the
direct method for cubic interpolation.
Table 3 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 6 Velocity vs. time data for the
rocket example
11
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 
 x2 , y 2 
v15  362.78  a0  a1 15  a2 15  a3 15
2 3
x0 , y0 

v20  517.35  a0  a1 20  a2 20  a3 20


2 3 x

Figure 7 Cubic interpolation.


v22.5  602.97  a0  a1 22.5  a2 22.5  a3 22.5
2 3

a0  4.2540 a1  21.266 a2  0.13204 a3  0.0054347

12
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
602.97

The absolute percentage relative


approximate error a between
600

ys 500 second and third order polynomial is


f ( range)


f x desired 

392 .06  392 .19


400

a   100
300
392 .06
227.04 200
10
10
12 14 16 18
x s  range x desired
20 22 24
22.5
 0.033269 %

13
Comparison Table
Table 4 Comparison of different orders of the polynomial.
Order of
1 2 3
Polynomial
vt  16 m/s 393.7 392.19 392.06
Absolute Relative
---------- 0.38410 % 0.033269 %
Approximate Error

14
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.0054347 t 3 dt
11
16
 t2 t3 t4 
  4.2540t  21.266  0.13204  0.0054347 
 2 3 4 11
 1605 m

15
Acceleration from Velocity Profile
Find the acceleration of the rocket at t=16s given that
 t   4.2540  21.266t  0.132042  0.0054347t 3 ,10  t  22.5
d
a t   vt 
dt
  4.2540  21.266t  0.13204t 2  0.0054347t 3 
d
dt
 21.289  0.26130t  0.016382t 2 , 10  t  22.5

a16  21.266  0.2640816  0.01630416 


2

 29.665 m/s 2

16
Lagrange Method of
Interpolation
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)

given at (n  1) data points as  x0 , y 0 , x1 , y1 ,......, x n 1 , y n 1 ,  x n , y n  , and


n x  xj
Li ( x )  
j 0 xi  x j
j i

Li (x) is a weighting function that includes a product of (n  1) terms with terms of j  i


omitted.

18
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 linear 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

Figure. Velocity vs. time data


19 for the rocket example
Linear Interpolation
550
517.35

1
v(t )   Li (t )v(ti ) 500
i 0
ys
 L0 (t )v(t 0 )  L1 (t )v(t1 ) f ( range)
450

f x desired 

t 0  15, t 0   362.78 400

t1  20, t1   517.35 362.78 350


10 12 14 16 18 20 22 24
x s  10 x s  range x desired x s  10
0 1

20
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.

21
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 )

22
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

Figure. Velocity vs. time data


23 for the rocket example
Quadratic Interpolation (contd)
t 0  10, v(t 0 )  227.04
550
517.35

t1  15, v(t1 )  362.78 500

t 2  20, v(t 2 )  517.35 450

ys
400
f ( range)
2 t tj  t  t1  t  t 2 
L0 (t )       
f x desired  350
j 0 t0  t j t  t
 0 1  0 2 t  t
j 0
300
2 t t j  t  t0  t  t 2 
L1 (t )      
j 0 t1  t j  t1  t0  t1  t 2  250
j 1

2 t  tj  t  t0  t  t1  227.04 200
L2 (t )       10 12 14 16 18 20

j 0 t2  t j t  t
 2 0  2 1 t  t 10 x s  range x desired 20
j 2

24
Quadratic Interpolation (contd)
 t  t1  t  t2   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%
25
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

 L0 (t ) v( t 0 )  L1 ( t ) v(t 1 )  L2 ( t ) v(t 2 )  L3 ( t ) v(t 3 )


700
602.97

600

ys 500

f ( range)


f x desired 
400

300

227.04 200
10 12 14 16 18 20 22 24
10 x s  range x desired 22.5

26
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

Figure. Velocity vs. time data


27 for the rocket example
Cubic Interpolation (contd)
t o  10, v t o   227.04 t1  15, v t1   362.78

t 2  20, v t 2   517.35 t 3  22.5, v t 3   602.97

700
3 t tj  t  t 1  t  t 2  t  t 3  602.97

L0 (t )        ;
j 0 t0  t j t  t t  t
 0 1  0 2  0 3  t  t 600
j 0

3 t t j  t  t0  t  t 2  t  t 3 
L1 (t )  
ys
     500

t1  t j  t1  t 0  1 2  t1  t 3
t  t 
f ( range)
j 0
j 1 
f x desired 
400

3 t tj  t  t 0  t  t1  t  t 3 
L2 (t )        ;
t2  t j  t 2  t 0  t 2  t 1  t 2  t 3 
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 desired 22.5

j 0 t3  t j  t3  t 0  t 3  t1  t3  t 2 
j 3

28
Cubic Interpolation (contd)
 t  t1  t  t 2  t  t3   t  t0  t  t2  t  t3 
vt      vt1      vt 2 
t  t t 
 0 1  0 2  0 3  t t  t t  t t
 1 0  1 2  1 3   t t  t
 t  t0  t  t1  t  t3   t  t1  t  t1  t  t 2 
    vt 2      vt3 
t  t t 
 2 0  2 1  2 3  t t  t t  t t
 3 1  3 1  3 2   t t  t
 16  15  16  20  16  22.5   16  10  16  20  16  22.5 
v16      227.04     362.78
 10  15  10  20  10  22.5   15  10  15  20  15  22.5 
 16  10  16  15  16  22.5   16  10  16  15  16  20 
   517.35     602.97 
 20  10  20  15  20  22 .5   22 .5  10  22 .5  15  22. 5  20 
  0.0416227.04   0.832362.78  0.312517.35   0.1024602.97 
 392.06 m/s
The absolute relative approximate error a obtained between the
results from the first and second order polynomial is
392.06 392.19
a  100
392.06
 0.033269%
29
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

30
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

31
 1605 m
Acceleration from Velocity Profile
Find the acceleration of the rocket at t=16s given that

v(t )  4.245  21.265t  0.13195t 2  0.00544t 3 , 10  t  22.5

a t   v t    4.245  21.265t  0.13195t  0.00544t 3 


d d 2 ,

dt dt

 21.265  0.26390t  0.01632t 2

a (16)  21. 265  0.26390(16)  0.01632(16) 2

 29.665 m / s 2

32
Newton’s Divided
Difference Method of
Interpolation
Newton’s Divided Difference
Method
Linear interpolation: Given ( x0 , y0 ), ( x1 , y1 ), pass a
linear interpolant through the data
f1 ( x)  b0  b1 ( x  x0 )

where
b0  f ( x 0 )
f ( x1 )  f ( x 0 )
b1 
x1  x 0

34
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

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. Velocity vs. time data
35
for the rocket example
Linear Interpolation
550
517.35

v(t )  b0  b1 (t  t 0 ) 500

ys

t 0  15, v(t 0 )  362.78 f ( range)


450

f x desired 
t1  20, v(t1 )  517.35
b0  v(t 0 )  362.78 400

v(t1 )  v(t 0 )
b1   30.914 362.78 350
t1  t 0 10
x s  10
12 14 16 18
x s  range x desired
20 22 24
x s  10
0 1

36
Linear Interpolation (contd)
550
517.35

500

ys

f ( range)
450

f x desired 

400

362.78 350
10 12 14 16 18 20 22 24
x s  10 x s  range x desired x s  10

v (t )  b0  b1 (t  t 0 )
0 1

 362.78  30.914(t  15), 15  t  20


At t  16
v (16)  362.78  30.914(16  15)
 393.69 m/s
37
Quadratic Interpolation
Given ( x0 , y 0 ), ( x1 , y1 ), and ( x 2 , 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 ( x 2 )  f ( x1 ) f ( x1 )  f ( x0 )

x 2  x1 x1  x0
b2 
x2  x0

38
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

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. Velocity vs. time data
39
for the rocket example
Quadratic Interpolation (contd)
550
517.35

500

450

ys
400
f ( range)


f x desired  350

300

250

227.04 200
10 12 14 16 18 20
10 x s  range x desired 20

t 0  10, v(t 0 )  227.04


t1  15, v(t1 )  362.78
t 2  20, v(t 2 )  517.35
40
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

v(t 2 )  v(t1 ) v(t1 )  v(t 0 ) 517.35  362.78 362.78  227.04


 
t 2  t1 t1  t 0 20  15 15  10
b2  
t 2  t0 20  10
30.914  27.148

10
 0.37660
41
Quadratic Interpolation (contd)
v(t )  b0  b1 (t  t 0 )  b2 (t  t 0 )(t  t1 )
 227.04  27.148(t  10)  0.37660(t  10)(t  15), 10  t  20
At t  16,
v(16)  227.04  27.148(16  10)  0.37660(16  10)(16  15)  392.19 m/s

The absolute relative approximate error a obtained between the results from the first
order and second order polynomial is

392.19  393.69
a  x100
392.19

= 0.38502 %

42
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 , x 0 ] x 2  x1 x1  x0
b2  f [ x 2 , x1 , x 0 ]  
x 2  x0 x 2  x0
Rewriting
f 2 ( x)  f [ x0 ]  f [ x1 , x0 ]( x  x0 )  f [ x 2 , x1 , x0 ]( x  x0 )( x  x1 )

43
General Form
Given (n  1) data points,  x0 , y 0 ,  x1 , y1 ,......,  x n 1 , y n 1 ,  x n , y n  as
f n ( x)  b0  b1 ( x  x0 )  ....  bn ( x  x0 )( x  x1 )...( x  x n 1 )
where
b0  f [[xx0 ]
b1  f [ x1 , x0 ]
b2  f [ x 2 , x1 , x0 ]

bn 1  f [ x n 1 , x n  2 ,...., x0 ]
bn  f [ x n , x n 1 ,...., x0 ]

44
General form
The third order polynomial, given ( x0 , y 0 ), ( x1 , y1 ), ( x 2 , 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 [ x 2 , x1 ] f [ x3 , x 2 , x1 , x 0 ]
x2 f ( x2 ) f [ x3 , x 2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )

45
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

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. Velocity vs. time data
46
for the rocket example
Example
The velocity profile is chosen as
v(t )  b0  b1 (t  t 0 )  b2 (t  t 0 )(t  t1 )  b3 (t  t 0 )(t  t1 )(t  t 2 )
we need to choose four data points that are closest to t  16
t0  10, v(t 0 )  227.04
t1  15, v(t1 )  362.78
t 2  20, v(t 2 )  517.35
t 3  22.5, v(t 3 )  602.97

The values of the constants are found as:


b0 = 227.04; b1 = 27.148; b2 = 0.37660; b3 = 5.4347×10−3

47
Example
b0
t0  10 227.04 b1
27.148 b2
t1  15, 362.78 0.37660 b3
30.914 5.4347  10 3
t 2  20, 517.35 0.44453
34.248
t3  22.5, 602.97

b0 = 227.04; b1 = 27.148; b2 = 0.37660; b3 = 5.4347×10−3

48
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 %
49
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

50
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

 4.2541  21.265t  0.13204t 2  0.0054347t 3 10  t  22.5


So
16
s16  s11   v t dt
11

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

51  1605 m
Acceleration from Velocity Profile
Find the acceleration of the rocket at t=16s given that

v(t )  4.2541  21.265t  0.13204t 2  0.0054347t 3

v(t )   4.2541  21.265t  0.13204t 2  0.0054347t 3 


d d
a (t ) 
dt dt

 21.265  0.26408t  0.016304t 2


a (16)  21.265  0.26408(16)  0.016304(16) 2

 29.664 m / s 2

52

You might also like