You are on page 1of 79

Direct Method of

Interpolation

Major: All Engineering Majors

Authors: Autar Kaw, Jai Paul

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates

http://numericalmethods.eng.usf.edu 1
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.


2 http://numericalmethods.eng.usf.edu
Interpolants
Polynomials are the most common
choice of interpolants because they
are easy to:
Evaluate
Differentiate, and
Integrate

3 http://numericalmethods.eng.usf.edu
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.

4 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
5 http://numericalmethods.eng.usf.edu
Linear Interpolation
v(t ) = a0 + a1t y

v(15) = a0 + 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

6 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
7 http://numericalmethods.eng.usf.edu
Quadratic Interpolation
y

v(t ) = a0 + a1t + a2t 2 (x1 , y1 )


v(10 ) = a0 + a1 (10 ) + a2 (10 ) = 227.04
2 (x2 , y2 )

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
8 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (cont.)
550
517.35

v(t ) = 12.05 + 17.733t + 0.3766t , 10  t  20


500
2
450

ys

v(16) = 12.05 + 17.733(16) + 0.3766(16)


400
2 f ( range)

(
f x des ired ) 350

= 392.19 m/s 300

250

227.04 200
10 12 14 16 18 20
10 x s  range x des ired 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 %
9 http://numericalmethods.eng.usf.edu
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
10 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 )

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

11 http://numericalmethods.eng.usf.edu
Cubic Interpolation (contd)
v(t ) = −4.2540 + 21.266t + 0.13204 t 2 + 0.0054347 t 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 des ired )

392 .06 − 392 .19


400

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

12 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

13 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.13064 t 2 + 0.0054606 t 3 , 10  t  22.5
16
s(16 ) − s(11) =  v(t )dt
11
16
(
=  − 4.2540 + 21.266t + 0.13204 t 2 + 0.0054347 t 3 dt)
11
16
 t2 t3 t4 
= − 4.2540 t + 21.266 + 0.13204 + 0.0054347 
 2 3 4 11
= 1605 m

14 http://numericalmethods.eng.usf.edu
Acceleration from Velocity Profile
Find the acceleration of the rocket at t=16s given that
 (t ) = −4.2540 + 21.266t + 0.13204 2 + 0.0054347 t 3 ,10  t  22.5
d
a(t ) = v(t )
dt
=
d
dt
(
− 4.2540 + 21.266t + 0.13204 t 2 + 0.0054347 t 3 )
= 21.289 + 0.26130 t + 0.016382 t 2 , 10  t  22.5

a(16 ) = 21.266 + 0.26408 (16 ) + 0.016304 (16 )


2

= 29.665 m/s 2

15 http://numericalmethods.eng.usf.edu
Newton’s Divided Difference
Polynomial Method of
Interpolation

Major: All Engineering Majors

Authors: Autar Kaw, Jai Paul

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates

16 http://numericalmethods.eng.usf.edu
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 ( x0 )
f ( x1 ) − f ( x0 )
b1 =
x1 − x0

17 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

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
18
for the rocket example http://numericalmethods.eng.usf.edu
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 des ired )
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 des ired
20 22 24
x s + 10
0 1

19 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

= 362.78 + 30.914(t − 15), 15  t  20


At t = 16
v(16) = 362.78 + 30.914(16 − 15)
= 393.69 m/s
20 http://numericalmethods.eng.usf.edu
Quadratic Interpolation
Given ( x0 , y 0 ), ( x1 , y1 ), and ( x2 , y2 ), 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 =
x 2 − x0

21 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

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
22
for the rocket example http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
550
517.35

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
23 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

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
24 http://numericalmethods.eng.usf.edu
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 %

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

26 http://numericalmethods.eng.usf.edu
General Form
Given (n + 1) data points, (x0 , y 0 ), (x1 , y1 ),......,(xn −1 , y n −1 ), (xn , y n ) as
f n ( x) = b0 + b1 ( x − x0 ) + .... + bn ( x − x0 )( x − x1 )...(x − xn−1 )
where
b0 = f [ x0 ]
b1 = f [ x1 , x0 ]
b2 = f [ x 2 , x1 , x0 ]

bn −1 = f [ xn −1 , xn −2 ,...., x0 ]
bn = f [ xn , xn−1 ,...., x0 ]

27 http://numericalmethods.eng.usf.edu
General form
The third order polynomial, given ( x0 , y 0 ), ( x1 , y1 ), ( x2 , y2 ), and ( x3 , y3 ), 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 , x0 ] b2
x1 f ( x1 ) f [ x2 , x1 , x0 ] b3
f [ x2 , x1 ] f [ x3 , x2 , x1 , x0 ]
x2 f ( x2 ) f [ x3 , x2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )

28 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 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
29
for the rocket example http://numericalmethods.eng.usf.edu
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
30 http://numericalmethods.eng.usf.edu
Example
b0
t0 = 10 227.04 b1
27.148 b2
t1 = 15, 362.78 0.37660 b3
30.914 5.4347 10 −3
t2 = 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

31 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 %
32 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

33 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

= −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

34 = 1605 m http://numericalmethods.eng.usf.edu
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

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

35 http://numericalmethods.eng.usf.edu
Lagrangian Interpolation

Major: All Engineering Majors

Authors: Autar Kaw, Jai Paul

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates

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

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.

37 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 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


38 for the rocket example http://numericalmethods.eng.usf.edu
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 des ired )

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 des ired x s + 10
0 1

39 http://numericalmethods.eng.usf.edu
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.

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

41 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

Figure. Velocity vs. time data


42 for the rocket example http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
550
t 0 = 10, v(t 0 ) = 227.04 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 des ired ) 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 − t 0  t1 − t 2  250
j 1

227.04
2 t −tj  t − t 0  t − t1  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 des ired 20
j 2

43 http://numericalmethods.eng.usf.edu
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 %
44 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

= L0 (t ) v( t0 ) + 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 des ired )
400

300

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

45 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

Figure. Velocity vs. time data


46 for the rocket example http://numericalmethods.eng.usf.edu
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 des ired )
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 des ired 22.5

j =0 t3 − t j  t3 − t 0  t 3 − t1  t3 − t 2 
j 3

47 http://numericalmethods.eng.usf.edu
Cubic Interpolation (contd)
 t − t1  t − t 2  t − t3   t − t0  t − t 2  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 %
48 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

49 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
50 http://numericalmethods.eng.usf.edu
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

51 http://numericalmethods.eng.usf.edu
Spline Interpolation Method

Major: All Engineering Majors

Authors: Autar Kaw, Jai Paul

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates

52 http://numericalmethods.eng.usf.edu
Rocket Example Results
t v Polynomial Velocity at Absolute Least
(s) (m/s) Order t=16 in Relative Number of
0 0 m/s Approxima Significant
10 227.04 te Error Digits
15 362.78 Correct
20 517.35 1 393.69 -------------
22.5 602.97 2 392.19 0.38% 2
30 901.67 3 392.05 0.036% 3
4 392.07 0.0051% 3
5 392.06 0.0026% 4

53 http://numericalmethods.eng.usf.edu
Why Splines ?
1
f ( x) =
1 + 25 x 2
Table : Six equidistantly spaced points in [-1, 1]
1
x y=
1 + 25 x 2

-1.0 0.038461

-0.6 0.1

-0.2 0.5

0.2 0.5

0.6 0.1

1.0 0.038461 Figure : 5th order polynomial vs. exact function

54 http://numericalmethods.eng.usf.edu
Why Splines ?
1.2

0.8

0.4
y

0
-1 -0.5 0 0.5 1
-0.4

-0.8
x
19th Order Polynomial f (x) 5th Order Polynomial

Figure : Higher order polynomial interpolation is a bad idea


55 http://numericalmethods.eng.usf.edu
Linear Interpolation
Given ( x0 , y0 ), (x1 , y1 ),......, (x n −1 , y n −1 )( x n , y n ) , fit linear splines to the data. This simply involves
forming the consecutive data through straight lines. So if the above data is given in an ascending
order, the linear splines are given by ( yi = f ( xi ) )
Figure : Linear splines

56 http://numericalmethods.eng.usf.edu
Linear Interpolation (contd)
f ( x1 ) − f ( x 0 )
f ( x ) = f ( x0 ) + ( x − x 0 ), x 0  x  x1
x1 − x 0

f ( x 2 ) − f ( x1 )
= f ( x1 ) + ( x − x1 ), x1  x  x 2
x2 − x1
.
.
.
f ( x n ) − f ( x n −1 )
= f ( x n −1 ) + ( x − x n−1 ), x n−1  x  x n
x n − x n −1

Note the terms of


f ( xi ) − f ( x i−1 )
xi − x i−1

in the above function are simply slopes between xi −1 and x i .


57 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 linear splines.
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
for the rocket example
58 http://numericalmethods.eng.usf.edu
Linear Interpolation
t 0 = 15, v (t 0 ) = 362.78 550
517.35

t1 = 20, v (t1 ) = 517.35


500
v(t ) − v (t 0 )
v (t ) = v(t 0 ) + 1 (t − t 0 )
t1 − t 0 ys

f ( range)
450
517.35 − 362.78 f(x )
= 362.78 + (t − 15) des ired
20 − 15
400
v (t ) = 362.78 + 30.913( t − 15)
At t = 16, 362.78 350
10 12 14 16 18 20 22 24
v (16) = 362.78 + 30.913(16 − 15) x s −10
0
x s  range x des ired x s + 10
1

= 393.7 m/s

59 http://numericalmethods.eng.usf.edu
Quadratic Interpolation
Given ( x0 , y0 ), ( x1 , y1 ),......, (x n−1 , y n −1 ), ( x n , y n ) , fit quadratic splines through the data. The splines
are given by
f ( x ) = a1 x 2 + b1 x + c1 , x 0  x  x1

= a 2 x 2 + b2 x + c2 , x1  x  x 2
.
.
.
= a n x 2 + bn x + cn , x n−1  x  x n

Find a i , bi , ci , i = 1, 2, …, n

60 http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
Each quadratic spline goes through two consecutive data points
2
a1 x 0 + b1 x 0 + c1 = f ( x0 )

a1 x12 + b1 x1 + c1 = f ( x1 ) .
.
.
2
a i xi −1 + bi xi −1 + ci = f ( xi −1 )
2
a i xi + bi xi + c i = f ( xi ) .
.
.
2
a n x n−1 + bn x n−1 + c n = f ( xn −1 )
2
a n x n + bn xn + cn = f ( x n )
This condition gives 2n equations
61 http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
The first derivatives of two quadratic splines are continuous at the interior points.
For example, the derivative of the first spline
a1 x 2 + b1 x + c1 is 2 a1 x + b1
The derivative of the second spline
a 2 x 2 + b2 x + c 2 is 2 a2 x + b2
and the two are equal at x = x1 giving
2 a1 x1 + b1 = 2a 2 x1 + b2
2 a1 x1 + b1 − 2a 2 x1 − b2 = 0

62 http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
Similarly at the other interior points,
2a 2 x 2 + b2 − 2a3 x 2 − b3 = 0
.
.
.
2ai xi + bi − 2ai +1 xi − bi +1 = 0
.
.
.
2a n −1 x n −1 + bn −1 − 2a n x n−1 − bn = 0

We have (n-1) such equations. The total number of equations is (2n) + (n − 1) = (3n − 1) .
We can assume that the first spline is linear, that is a1 = 0

63 http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
This gives us ‘3n’ equations and ‘3n’ unknowns. Once we find the ‘3n’ constants,
we can find the function at any value of ‘x’ using the splines,

f ( x) = a1 x 2 + b1 x + c1 , x0  x  x1

= a 2 x 2 + b2 x + c 2 , x1  x  x 2
.
.
.
= a n x 2 + bn x + c n , x n −1  x  x n

64 http://numericalmethods.eng.usf.edu
Quadratic Spline Example
The upward velocity of a rocket is given as a function of time.
Using quadratic splines
a) Find the velocity at t=16 seconds
b) Find the acceleration at t=16 seconds

c) Find the distance covered between t=11 and t=16 seconds

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
for the rocket example

65 http://numericalmethods.eng.usf.edu
Solution
v(t ) = a1t + b1t + c1 , 0  t  10
2

= a2 t + b2 t + c2 , 10  t  15
2

= a3t + b3t + c3 , 15  t  20
2

= a4 t + b4 t + c4 , 20  t  22.5
2

= a5t + b5t + c5 ,
2
22.5  t  30
Let us set up the equations
66 http://numericalmethods.eng.usf.edu
Each Spline Goes Through
Two Consecutive Data Points
v(t ) = a1t + b1t + c1 , 0  t  10
2

a1 (0) + b1 (0) + c1 = 0
2

a1 (10) + b1 (10) + c1 = 227.04


2

67 http://numericalmethods.eng.usf.edu
Each Spline Goes Through
Two Consecutive Data Points
a 2 (10) 2 + b2 (10) + c2 = 227.04
t v(t)
a 2 (15) 2 + b2 (15) + c2 = 362.78
s m/s
0 0 a3 (15) + b3 (15) + c3 = 362.78
2

10 227.04 a3 (20) + b3 (20) + c3 = 517.35


2

15 362.78
a4 (20) 2 + b4 (20) + c4 = 517.35
20 517.35
a4 (22.5) 2 + b4 (22.5) + c4 = 602.97
22.5 602.97
30 901.67 a5 (22.5) + b5 (22.5) + c5 = 602.97
2

a5 (30) 2 + b5 (30) + c5 = 901.67


68 http://numericalmethods.eng.usf.edu
Derivatives are Continuous at
Interior Data Points
v(t ) = a1t + b1t + c1 , 0  t  10
2

= a2 t + b2 t + c2 ,10  t  15
2

d
dt
(a1t + b1t + c1
2
) =
d
(
dt
a2t + b2t + c2
2
)
t =10 t =10

(2a1t + b1 ) t =10 = (2a2t + b2 ) t =10


2a1 (10) + b1 = 2a2 (10) + b2
20a1 + b1 − 20a2 − b2 = 0
69 http://numericalmethods.eng.usf.edu
Derivatives are continuous at
Interior Data Points
At t=10
2a1 (10) + b1 − 2a2 (10) − b2 = 0
At t=15
2a2 (15) + b2 − 2a3 (15) − b3 = 0
At t=20
2a3 (20) + b3 − 2a 4 (20) − b4 = 0
At t=22.5
2a 4 (22.5) + b4 − 2a5 (22.5) − b5 = 0
70 http://numericalmethods.eng.usf.edu
Last Equation

a1 = 0

71 http://numericalmethods.eng.usf.edu
Final Set of Equations
0 0 1 0 0 0 0 0 0 0 0 0 0 0 0  a1   0 
100 10 1 0 0 0 0 0 0 0 0 0 0 0 0  b1  227.04
0 0 0 100 10 1 0 0 0 0 0 0 0 0
   227.04
0 c1
    
0 0 0 225 15 1 0 0 0 0 0 0 0 0 0 a2  362.78
0 0 0 0 0 0 225 15 1 0 0 0 0 0 0  b2  362.78
0 0 0 0 0 0 400 20 1 0 0 0 0 0
  517.35
0 c2
    
0 0 0 0 0 0 0 0 0 400 20 1 0 0 0  a3  517.35
0 0 0 0 0 0 0 0 0 506.25 22.5 1 0 0 0  b3  = 602.97
0 0 0 0 0 0 0 0 0 0 0 0 506.25 22.5 1   c3  602.97
    
0 0 0 0 0 0 0 0 0 0 0 0 900 30 1  a4  901.67 
 20 1 0 − 20 − 1 0 0 0 0 0 0 0 0 0 0  b4   0 
0 0 0 30 1 0 − 30 − 1 0 0 0 0 0 0 0  c4   0 
    
1 0 − 40 −1 0  a5 
0 0 0 0 0 0 40 0 0 0
  0

0 0 0 0 0 0 0 0 0 45 1 0 − 45 −1 0  b5   0 
 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0  c5   0 

72 http://numericalmethods.eng.usf.edu
Coefficients of Spline
i ai bi ci
1 0 22.704 0
2 0.8888 4.928 88.88
3 −0.1356 35.66 −141.61
4 1.6048 −33.956 554.55
5 0.20889 28.86 −152.13

73 http://numericalmethods.eng.usf.edu
Quadratic Spline Interpolation
Part 2 of 2

http://numericalmethods.eng.usf.edu

74 http://numericalmethods.eng.usf.edu
Final Solution
v(t ) = 22.704t , 0  t  10
= 0.8888t 2 + 4.928t + 88.88, 10  t  15
= −0.1356t 2 + 35.66t − 141.61, 15  t  20
= 1.6048t 2 − 33.956t + 554.55, 20  t  22.5
= 0.20889 t 2 + 28.86t − 152.13, 22.5  t  30

75 http://numericalmethods.eng.usf.edu
Velocity at a Particular Point
a) Velocity at t=16
v(t ) = 22.704t , 0  t  10
= 0.8888t 2 + 4.928t + 88.88, 10  t  15
= −0.1356t 2 + 35.66t − 141.61, 15  t  20
= 1.6048t 2 − 33.956t + 554.55, 20  t  22.5
= 0.20889 t 2 + 28.86t − 152.13, 22.5  t  30

v(16 ) = −0.1356 (16 ) + 35.66(16 ) − 141 .61


2

= 394 .24 m/s

76 http://numericalmethods.eng.usf.edu
Acceleration from Velocity Profile
b) The quadratic spline valid at t=16 is
given by
d
a(16) = v(t ) t =16
dt
v(t ) = −0.1356 t 2 + 35.66t − 141 .61, 15  t  20
d
a(t ) = ( −0.1356t + 35.66t − 141.61)
2

dt
= −0.2712t + 35.66, 15  t  20
a(16) = −0.2712 (16) + 35.66 = 31.321 m/s
2

77 http://numericalmethods.eng.usf.edu
Distance from Velocity Profile
c) Find the distance covered by the rocket from t=11s to
t=16s.
16
S (16 ) − S (11) =  v (t )dt
11

v(t ) = 0.8888t 2 + 4.928t + 88.88, 10  t  15


= −0.1356 t 2 + 35.66t − 141 .61, 15  t  20
16 15 16
S (16 ) − S (11) =  v(t )dt =  v(t )dt +  v(t )dt
11 11 15
15 16
( ) (
=  0.8888t 2 + 4.928t + 88.88 dt +  − 0.1356 t 2 + 35.66t − 141 .61 dt )
11 15

= 1595 .9 m
78 http://numericalmethods.eng.usf.edu
THE END

You might also like