Download as pdf or txt
Download as pdf or txt
You are on page 1of 71

a0 = 1 a1 a2 a3F a3MF x

b0 = b1 = b2 = ... = 2

Numerical Analysis

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


Interpolation by Polynomials
• We occasionally try to estimate intermediate values between
precise data points.

• Polynomials are used as the basic means of approximation


in nearly all areas of numerical analysis.
• Approximating functions
Page• 3 Integrals and derivatives
• Solutions of integrals and differential equations

• This is due to their simple structure.

• Interpolation by polynomials is by far the most widely used


technique among various interpolating functions.
Interpolation by Polynomials
• For n+1 points there is only one polynomial of order n
passes through all of these points.

• For example, there is only one straight line that connects two
points.

• Polynomial interpolation consists of determining nth order


polynomial that fits n+1 points.
Page 4

• 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

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

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

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

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
9 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%
10 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
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 )

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

The absolute percentage relative


602.97

approximate error a between


600

ys 500 second and third order polynomial is


f ( range)

(
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

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


2

= 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

P( x) = a0 + a1 (x − c1 ) + a2 (x − c1 )(x − c2 ) + a3 (x − c1 )(x − c2 )(x − c3 ) +  + an (x − c1 ) (x − cn )

• Newton form plays a major role in constructing interpolation polynomials.

Newton Form
Page 18
P( x) = a0 +  ai  (x − c j )
n i

i =1 j =1
Newton’s Divided Difference Method

Linear interpolation: Given ( x0 , y 0 ), ( 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

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

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

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


At t = 16
v(16) = 362.78 + 30.914(16 − 15)

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

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

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
26 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 %

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 ]

pn ( x) = f x0  + f x0 , x1 (x − x0 ) +  + f x0 , x1 ,, xn (x − x0 )(x − x1 )(x − x2 ) (x − xn −1 )


30
Divided Difference

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

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
33
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
34 http://numericalmethods.eng.usf.edu
Example
(362.78-227.04)/15-10 =
b0 27.148
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
(34.248-30.914)/22.5-15
t3 = 22.5, 602.97

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

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

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

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

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)

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


41 for the rocket example http://numericalmethods.eng.usf.edu
Linear Interpolation
550
517.35

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 )

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

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

Figure. Velocity vs. time data


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

2 t −tj  t − t 0  t − t1  227.04 200


L2 (t ) =  =    10 12 14 16 18 20

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

= L0 (t ) v( t 0 ) + L1 ( t ) v(t1 ) + 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

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

Figure. Velocity vs. time data


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

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

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

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

We also have the function values:


f (2 ) = 0.5 f (2.5) = 0.4 f (4 ) = 0.25
Lagrange Polynomial
So we obtain
P( x ) = L2, 0 ( x ) f ( x0 ) + L2,1 ( x ) f ( x1 ) + L2, 2 ( x ) f ( x2 )

= 0.5(( x − 6.5)x + 10 ) + 0.4


(− 4 x + 24)x − 32 + 0.25 (x − 4.5)x + 5
3 3
= (0.05 x − 0.425)x + 1.15

Page 56
Lagrange Polynomial Disadvantages

• Disadvantage of Lagrange Polynomial can be summarized as:

• We don’t know how many points to include in an interpolation.


• In general, one would calculate the interpolation function for an
increasing number of points, until the convergence criteria is
satisfied.
• However, this process would be wasteful for Lagrange polynomial,
since we can not use the previous polynomial interpolation for the
Page 57
current one.
• For this purpose, other interpolation schemes that is based on
Newton form of interpolation are much better for computational
efficiency.
Divided Difference
Example: Using the data below, utilize first Lagrange interpolation of
different orders to obtain f(1.5). After that utilize divided difference
technique to obtain the same.
x f (x )
1.0 0.7651977
1.3 0.6200860
1.6 0.4554022
1.9 0.2818186
2.2 0.1103623
Page 58
Divided Difference
Example: Using the data below, utilize first Lagrange interpolation of
different orders to obtain f(1.5). After that utilize divided difference
technique to obtain the same. 𝑥0 = 1.3, 𝑥1 = 1.6,
x f (x ) P1 (1.5) =
(1.5 − 1.6)
f (1.3) +
(1.5 − 1.3)
f (1.6)
1.0 0.7651977 (1.3 − 1.6) (1.6 − 1.3)
1.3 0.6200860
=
(1.5 − 1.6)
0.6200860 +
(1.5 − 1.3)
0.4554022
1.6
1.9
0.4554022
0.2818186
(1.3 − 1.6) (1.6 − 1.3)
= 0.5102968
2.2 0.1103623
Page 59 𝑥0 = 1.3, 𝑥1 = 1.6, 𝑥2 = 1.9

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

x0 = 1.0, x1 = 1.3, x2 = 1.6, x3 = 1.9  P3 (1.5) = 0.5118127


x0 = 1.3, x1 = 1.6, x2 = 1.9, x3 = 2.2  P3 (1.5) = 0.5118302

x0 = 1.0, x1 = 1.3, x2 = 1.6, x3 = 1.9, x4 = 2.2  P4 (1.5) = 0.5118200


Page 60
Divided Difference
Now let’s use the divided difference technique to obtain the same result.
i xi f (xi )
0 1.0 0.7651977
1 1.3 0.6200860

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

P4 (x ) = 0.7651977 − 0.4837057(x − 1.0) − 0.1087339(x − 1.0)(x − 1.3)


+ 0.0658784(x − 1.0)(x − 1.3)(x − 1.6)
+ 0.0018251(x − 1.0)(x − 1.3)(x − 1.6)(x − 1.9)
P4 (1.5) = 0.5118200
The Error in Polynomial Interpolation

Theorem: Let f (x) be a real valued function, defined on [a, b] and k+1

times differentiable in [a, b]. If x0 , x1 ,  , xk are k+1 distinct points in [a, b]

then there exists c  [ a, b] such that the error is bounded by

f k +1 (c)
Page 64
( x − x0 )( x − x1 )......( x − xk )
(k + 1)!
𝑅 𝑋
=
𝜋 180

You might also like