Numerical Chap 4
Numerical Chap 4
Direct Method of
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.
1
10/14/2021
Interpolants
Polynomials are the most common
choice of interpolants because they
are easy to:
Evaluate
Differentiate, and
Integrate
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.
2
10/14/2021
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 vt , 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
Linear Interpolation
vt a0 a1t y
Hence
vt 100.93 30.914t , 15 t 20.
v16 100.93 30.91416 393.7 m/s
3
10/14/2021
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 vt , 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
Quadratic Interpolation
y
f2 x
v20 a0 a120 a2 20 517.35
2
x 0 , y 0
x
4
10/14/2021
450
ys
f x desired 350
250
227.04 200
10 12 14 16 18 20
10 x s range x desired 20
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 vt , 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
5
10/14/2021
Cubic Interpolation
y
x3 , y3
vt a0 a1t a2t 2 a3t 3
x1 , y1
v10 227.04 a0 a1 10 a2 10 a3 10
2 3
f 3 x
x2 , y 2
v15 362.78 a0 a1 15 a2 15 a3 15
2 3
x0 , y0
x
v20 517.35 a0 a1 20 a2 20 a3 20
2 3
11
f x desired
a 100
392 .06
300
227.04 200
10
10
12 14 16 18
x s range x desired
20 22 24
22.5
0.033269 %
12
6
10/14/2021
Comparison Table
Table 4 Comparison of different orders of the polynomial.
Order of
t(s) v (m/s) 1 2 3
Polynomial
0 0
vt 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
11
16
t2 t3 t4
4.2540t 21.266 0.13204 0.0054347
2 3 4 11
1605 m
14
7
10/14/2021
29.665 m/s 2
15
THANK YOU!
8
10/14/2021
1
Son Dao, PhD ©
What is Interpolation ?
Given (x0,y0), (x1,y1), …… (xn,yn), find the
value of ‘y’ at a value of ‘x’ that is not given.
1
10/14/2021
Interpolants
Polynomials are the most common
choice of interpolants because they
are easy to:
Evaluate
Differentiate, and
Integrate.
2
10/14/2021
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
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
3
10/14/2021
Linear Interpolation
Given x0 , y0 , x1 , y1 ,......, x n 1 , y n1 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
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
4
10/14/2021
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
9
Linear Interpolation
t 0 15, v (t 0 ) 362.78 550
517.35
f ( range)
450
517.35 362.78 f x
362.78 (t 15) desired
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 desired x s 10
1
393.7 m/s
10
10
5
10/14/2021
Quadratic Interpolation
Given x0 , y0 , x1 , y1 ,......, x n1 , 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 b 2 x c2 , x1 x x 2
.
.
.
a n x 2 b n x cn , x n1 x x n
Find a i , bi , ci , i 1, 2, …, n
11
11
a1 x1 b1 x1 c1 f ( x1 )
2
.
.
.
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 n1 bn x n1 c n f ( xn 1 )
2
a n x n bn xn cn f ( x n )
This condition gives 2n equations
12
12
6
10/14/2021
2 a1 x1 b1 2a 2 x1 b2
2 a1 x1 b1 2a 2 x1 b2 0
13
13
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
14
14
7
10/14/2021
f ( x ) a1 x 2 b1 x c1 , x 0 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
15
15
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
16
16
8
10/14/2021
Solution
v(t ) a1t 2 b1t c1 , 0 t 10
a 2 t 2 b2 t c 2 , 10 t 15
a3 t 2 b3 t c3 , 15 t 20
a 4 t 2 b4 t c 4 , 20 t 22.5
a 5 t 2 b5 t c5 , 22.5 t 30
Let us set up the equations
17
17
18
18
9
10/14/2021
19
a 2 t 2 b2 t c 2 ,10 t 15
d
dt
a1t 2 b1t c1
d
dt
a2t 2 b2t c2
t 10 t 10
20
10
10/14/2021
21
Last Equation
a1 0
22
22
11
10/14/2021
23
23
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
24
24
12
10/14/2021
25
25
Final Solution
v (t ) 22.704t , 0 t 10
0.8888t 4.928t 88.88,
2
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.20889t 2 28.86t 152.13, 22.5 t 30
26
26
13
10/14/2021
394.24 m/s
27
27
28
28
14
10/14/2021
11 15
1595.9 m
29
29
THANK YOU!
30
15
10/14/2021
Lagrangian 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)
1
10/14/2021
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
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
2
10/14/2021
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.
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 )
3
10/14/2021
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 desired 350
j 0 t0 t j t 0 t 1 t 0 t 2
j 0
300
2 t t j t t0 t t 2
L1 (t )
j 0 t1 t j t1 t 0 t1 t2 250
j 1
t2 t j t 2 t 0 t 2 t 1
10 x s range x desired 20
j 0
j 2
10
4
10/14/2021
392.19 393.70
a 100
392.19
0.38410%
11
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 desired
400
300
227.04 200
10 12 14 16 18 20 22 24
10 x s range x desired 22.5
12
5
10/14/2021
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 t1 t t 2 t t 3 602.97
L0 (t ) ;
j 0 t0 t j t 0 t 1 t 0 t 2 t0 t 3 600
j 0
3 t t j t t0 t t 2 t t3
L1 (t )
ys
500
j 0 t1 t j t1 t 0 t1 t 2 t1 t 3 f ( range)
j 1
f x desired
400
3 ttj 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
j2
ttj t t 0 t t1 t t2
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 t3 t1 t3 t2
j 3
14
6
10/14/2021
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
16
7
10/14/2021
s(16) s (11) v( t) dt
11
16
t2 t3 t4
[ 4.245t 21.265 0.13195 0.00544 ]16
11
2 3 4
1605 m
17
dt dt
29.665 m / s 2
18
8
10/14/2021
THANK YOU!
9
10/14/2021
where
b0 f ( x 0 )
f ( x1 ) f ( x 0 )
b1
x1 x 0
1
10/14/2021
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
4 for the rocket example
Linear Interpolation
550
517.35
v(t ) b0 b1 (t t 0 ) 500
ys
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
2
10/14/2021
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
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 ( x 0 )
f ( x1 ) f ( x0 )
b1
x1 x 0
f ( x 2 ) f ( x1 ) f ( x1 ) f ( x 0 )
x 2 x1 x1 x 0
b2
x 2 x0
3
10/14/2021
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
8 for the rocket example
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
4
10/14/2021
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 %
11
5
10/14/2021
General Form
f 2 ( x ) b0 b1 ( x x 0 ) b2 ( x x 0 )( x x1 )
where
b0 f [ x0 ] f ( x0 )
f ( x1 ) f ( x0 )
b1 f [ x1 , x0 ]
x1 x 0
f ( x 2 ) f ( x1 ) f ( x1 ) f ( x 0 )
f [ x 2 , x1 ] f [ x1 , x0 ] x 2 x1 x1 x0
b2 f [ x2 , x1 , x0 ]
x 2 x0 x 2 x0
Rewriting
f 2 ( x) f [ x 0 ] f [ x1 , x0 ]( x x 0 ) f [ x 2 , x1 , x 0 ]( x x0 )( x x1 )
12
General Form
Given (n 1) data points, x 0 , y 0 , x1 , y1 ,......, x n 1 , y n 1 , x n , y n as
f n ( x) b0 b1 ( x x 0 ) .... bn ( x x 0 )( x x1 )...( x x n 1 )
where
b0 f [ x 0 ]
b1 f [ x1 , x0 ]
b2 f [ x 2 , x1 , x 0 ]
bn 1 f [ x n 1 , x n 2 ,...., x0 ]
bn f [ x n , x n 1 ,...., x 0 ]
13
6
10/14/2021
General form
The third order polynomial, given ( x 0 , y 0 ), ( x1 , y1 ), ( x 2 , y 2 ), and ( x3 , y 3 ), is
f 3 ( x) f [ x 0 ] f [ x1 , x 0 ]( x x 0 ) f [ x 2 , x1 , x 0 ]( x x 0 )( x x1 )
f [ x3 , x 2 , x1 , x 0 ]( x x 0 )( x x1 )( x x 2 )
b0
x0 f ( x0 ) b1
f [ x1 , x0 ] b2
x1 f ( x1 ) f [ x 2 , x1 , x 0 ] b3
f [ x 2 , x1 ] f [ x3 , x2 , x1 , x0 ]
x2 f ( x2 ) f [ x3 , x2 , x1 ]
f [ x3 , x 2 ]
x3 f ( x3 )
14
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
15 for the rocket example
7
10/14/2021
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
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
17
8
10/14/2021
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 %
18
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
19
9
10/14/2021
16
16
t2 t3 t4
4.2541t 21.265 0.13204 0.0054347
2 3 4 11
20 1605 m
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
29.664 m / s 2
21
10
10/14/2021
THANK YOU!
11