1 Interpolation. 2 What is Interpolation ? Given (x 0,y 0 ), (x 1,y 1 ), …… (x n,y n ), find...
-
Upload
philomena-potter -
Category
Documents
-
view
230 -
download
3
Transcript of 1 Interpolation. 2 What is Interpolation ? Given (x 0,y 0 ), (x 1,y 1 ), …… (x n,y n ), find...
http://numericalmethods.eng.usf.edu
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.
http://numericalmethods.eng.usf.edu
3
Interpolants
Polynomials are the most common choice of interpolants because they are easy to:
Evaluate Differentiate, and Integrate
http://numericalmethods.eng.usf.edu
5
Direct MethodGiven ‘n+1’ data points (x0,y0), (x1,y1),…………..
(xn,yn),pass a polynomial of order ‘n’ through the data as
given below:
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.
.....................10n
nxaxaay
http://numericalmethods.eng.usf.edu
6
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.
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Table 1 Velocity as a function of time.
Figure 2 Velocity vs. time data for the rocket example
s ,t m/s ,tv
http://numericalmethods.eng.usf.edu
7
Linear Interpolation taatv 10
78.3621515 10 aav
35.5172020 10 aav
Solving the above two equations gives,
93.1000 a 914.301 a
Hence .2015,914.3093.100 tttv
m/s 7.39316914.3093.10016 v
00 , yx
xf1
11, yx
x
y
Figure 3 Linear interpolation.
http://numericalmethods.eng.usf.edu
8
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.
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Table 2 Velocity as a function of time.
Figure 5 Velocity vs. time data for the rocket example
s ,t m/s ,tv
http://numericalmethods.eng.usf.edu
9
Quadratic Interpolation
2210 tataatv
04.227101010 2210 aaav
78.362151515 2210 aaav
35.517202020 2210 aaav
Solving the above three equations gives
05.120 a 733.171 a 3766.02 a
Quadratic Interpolation
00 , yx
11, yx
22 , yx
xf2
y
x
Figure 6 Quadratic interpolation.
http://numericalmethods.eng.usf.edu
10
Quadratic Interpolation (cont.)
10 12 14 16 18 20200
250
300
350
400
450
500
550517.35
227.04
y s
f range( )
f x desired
2010 x s range x desired
2010,3766.0733.1705.12 2 ttttv
2163766.016733.1705.1216 v
m/s 19.392
The absolute relative approximate error obtained between the results from the first and second order polynomial is
%38410.0
10019.392
70.39319.392
a
a
http://numericalmethods.eng.usf.edu
11
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.
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Table 3 Velocity as a function of time.
Figure 6 Velocity vs. time data for the rocket example
s ,t m/s ,tv
http://numericalmethods.eng.usf.edu
12
Cubic Interpolation
33
2210 tatataatv
33
2210 10101004.22710 aaaav
33
2210 15151578.36215 aaaav
33
2210 20202035.51720 aaaav
33
2210 5.225.225.2297.6025.22 aaaav
2540.40 a 266.211 a 13204.02 a 0054347.03 a
y
x
xf3
33 , yx
22 , yx
11, yx
00 , yx
Figure 7 Cubic interpolation.
http://numericalmethods.eng.usf.edu
13
Cubic Interpolation (contd)
10 12 14 16 18 20 22 24200
300
400
500
600
700602.97
227.04
y s
f range( )
f x desired
22.510 x s range x desired
5.2210,0054347.013204.0266.212540.4 32 tttttv
m/s 06.392
160054347.01613204.016266.212540.416 32
v
The absolute percentage relative approximate error between second and third order polynomial is
a
%033269.0
10006.392
19.39206.392
a
http://numericalmethods.eng.usf.edu
14
Comparison Table
Order of Polynomial
1 2 3
m/s 16tv 393.7 392.19 392.06
Absolute Relative Approximate Error
---------- 0.38410 % 0.033269 %
Table 4 Comparison of different orders of the polynomial.
http://numericalmethods.eng.usf.edu
15
Distance from Velocity ProfileFind the distance covered by the rocket from t=11s to t=16s ?
5.2210,0054606.013064.0289.213810.4 32 tttttv
m 1605
40054347.0
313204.0
2266.212540.4
0054347.013204.0266.212540.4
1116
16
11
432
16
11
32
16
11
tttt
dtttt
dttvss
http://numericalmethods.eng.usf.edu
16
Acceleration from Velocity Profile
5.2210,0054347.013204.0266.212540.4 32 ttttFind the acceleration of the rocket at t=16s given that
5.2210 ,016382.026130.0289.21
0054347.013204.0266.212540.4
2
32
ttt
tttdt
d
tvdt
dta
2
2
m/s 665.29
16016304.01626408.0266.2116
a
http://numericalmethods.eng.usf.edu
18
Why Splines ?2251
1)(
xxf
Table : Six equidistantly spaced points in [-1, 1]
Figure : 5th order polynomial vs. exact function
x 2251
1
xy
-1.0 0.038461
-0.6 0.1
-0.2 0.5
0.2 0.5
0.6 0.1
1.0 0.038461
http://numericalmethods.eng.usf.edu
19
Why Splines ?
Figure : Higher order polynomial interpolation is a bad idea
-0.8
-0.4
0
0.4
0.8
1.2
-1 -0.5 0 0.5 1
x
y
19th Order Polynomial f (x) 5th Order Polynomial
http://numericalmethods.eng.usf.edu
20
Linear InterpolationGiven nnnn yxyxyxyx ,,,......,,,, 111100 , 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 )( ii xfy
Figure : Linear splines
http://numericalmethods.eng.usf.edu
21
Linear Interpolation (contd)
),()()(
)()( 001
010 xx
xx
xfxfxfxf
10 xxx
),()()(
)( 112
121 xx
xx
xfxfxf
21 xxx
.
.
.
),()()(
)( 11
11
nnn
nnn xx
xx
xfxfxf nn xxx 1
Note the terms of
1
1)()(
ii
ii
xx
xfxf
in the above function are simply slopes between 1ix and ix .
http://numericalmethods.eng.usf.edu
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 linear splines.Table Velocity as a
function of time
Figure. Velocity vs. time data for the rocket example
(s) (m/s)0 0
10 227.0415 362.7820 517.35
22.5 602.9730 901.67
t )(tv
http://numericalmethods.eng.usf.edu
23
Linear Interpolation
10 12 14 16 18 20 22 24350
400
450
500
550517.35
362.78
y s
f range( )
f x desired
x s1
10x s0
10 x s range x desired
,150 t 78.362)( 0 tv
,201 t 35.517)( 1 tv
)()()(
)()( 001
010 tt
tt
tvtvtvtv
)15(1520
78.36235.51778.362
t
)15(913.3078.362)( ttv
At ,16t
)1516(913.3078.362)16( v
7.393 m/s
http://numericalmethods.eng.usf.edu
24
Quadratic InterpolationGiven nnnn yxyxyxyx ,,,,......,,,, 111100 , fit quadratic splines through the data. The splines
are given by
,)( 112
1 cxbxaxf 10 xxx
,222
2 cxbxa 21 xxx
.
.
.
,2nnn cxbxa nn xxx 1
Find ,ia ,ib ,ic i 1, 2, …, n
http://numericalmethods.eng.usf.edu
25
Quadratic Interpolation (contd)
Each quadratic spline goes through two consecutive data points
)( 0101
2
01 xfcxbxa
)( 11112
11 xfcxbxa .
.
.
)( 11
2
1 iiiiii xfcxbxa
)(2
iiiiii xfcxbxa .
.
.
)( 11
2
1 nnnnnn xfcxbxa
)(2
nnnnnn xfcxbxa
This condition gives 2n equations
http://numericalmethods.eng.usf.edu
26
Quadratic Splines (contd)The first derivatives of two quadratic splines are continuous at the interior points.
For example, the derivative of the first spline
112
1 cxbxa is 112 bxa
The derivative of the second spline
222
2 cxbxa is 222 bxa
and the two are equal at 1xx giving
212111 22 bxabxa
022 212111 bxabxa
http://numericalmethods.eng.usf.edu
27
Quadratic Splines (contd)Similarly at the other interior points,
022 323222 bxabxa
.
.
.
022 11 iiiiii bxabxa
.
.
.
022 1111 nnnnnn bxabxa
We have (n-1) such equations. The total number of equations is )13()1()2( nnn .
We can assume that the first spline is linear, that is 01 a
http://numericalmethods.eng.usf.edu
28
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,
,)( 112
1 cxbxaxf 10 xxx
,222
2 cxbxa 21 xxx
.
.
.
,2nnn cxbxa nn xxx 1
http://numericalmethods.eng.usf.edu
29
Quadratic Spline ExampleThe upward velocity of a rocket is given as a function of time. Using quadratic splinesa) Find the velocity at t=16 secondsb) Find the acceleration at t=16 secondsc) Find the distance covered between t=11 and t=16 seconds
Table Velocity as a function of time
Figure. Velocity vs. time data for the rocket example
(s) (m/s)0 0
10 227.0415 362.7820 517.35
22.5 602.9730 901.67
t )(tv
http://numericalmethods.eng.usf.edu
30
Solution,)( 11
21 ctbtatv 100 t
,222
2 ctbta 1510 t
,332
3 ctbta 2015 t,44
24 ctbta 5.2220 t
,552
5 ctbta 305.22 t
Let us set up the equations
http://numericalmethods.eng.usf.edu
31
Each Spline Goes Through Two Consecutive Data
Points,)( 11
21 ctbtatv 100 t
0)0()0( 112
1 cba
04.227)10()10( 112
1 cba
http://numericalmethods.eng.usf.edu
32
t v(t)
s m/s
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Each Spline Goes Through Two Consecutive Data
Points04.227)10()10( 22
22 cba
78.362)15()15( 222
2 cba
78.362)15()15( 332
3 cba
35.517)20()20( 332
3 cba
67.901)30()30( 552
5 cba
35.517)20()20( 442
4 cba
97.602)5.22()5.22( 442
4 cba
97.602)5.22()5.22( 552
5 cba
http://numericalmethods.eng.usf.edu
33
Derivatives are Continuous at Interior Data Points
,)( 112
1 ctbtatv 100 t
,222
2 ctbta 1510 t
10
222
210
112
1
tt
ctbtadt
dctbta
dt
d
10221011 22
ttbtabta
2211 102102 baba
02020 2211 baba
http://numericalmethods.eng.usf.edu
34
Derivatives are continuous at Interior Data Points
0)10(2)10(2 2211 baba
0)15(2)15(2 3322 baba
0)20(2)20(2 4433 baba
0)5.22(2)5.22(2 5544 baba
At t=10
At t=15
At t=20
At t=22.5
http://numericalmethods.eng.usf.edu
36
Final Set of Equations
0
0
0
0
0
67.901
97.602
97.602
35.517
35.517
78.362
78.362
04.227
04.227
0
000000000000001
01450145000000000
00001400140000000
00000001300130000
00000000001200120
130900000000000000
15.2225.506000000000000
00015.2225.506000000000
000120400000000000
000000120400000000
000000115225000000
000000000115225000
000000000110100000
000000000000110100
000000000000100
5
5
5
4
4
4
3
3
3
2
2
2
1
1
1
c
b
a
c
b
a
c
b
a
c
b
a
c
b
a
http://numericalmethods.eng.usf.edu
37
Coefficients of Splinei ai bi ci1 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
http://numericalmethods.eng.usf.edu
38
Final Solution,704.22)( ttv 100 t
,88.88928.48888.0 2 tt 1510 t,61.14166.351356.0 2 tt 2015 t,55.554956.336048.1 2 tt 5.2220 t,13.15286.2820889.0 2 tt 305.22 t
http://numericalmethods.eng.usf.edu
39
Velocity at a Particular Pointa) Velocity at t=16
,704.22)( ttv 100 t,88.88928.48888.0 2 tt 1510 t
,61.14166.351356.0 2 tt 2015 t,55.554956.336048.1 2 tt 5.2220 t,13.15286.2820889.0 2 tt 305.22 t
m/s24.394
61.1411666.35161356.016 2
v
http://numericalmethods.eng.usf.edu
40
Acceleration from Velocity Profile
16)()16(
ttv
dt
da
b) The quadratic spline valid at t=16 is given by
)61.14166.351356.0()( 2 ttdt
dta
,66.352712.0 t 2015 t
66.35)16(2712.0)16( a 2m/s321.31
,61.14166.351356.0 2 tttv 2015 t
http://numericalmethods.eng.usf.edu
41
Distance from Velocity Profile
c) Find the distance covered by the rocket from t=11s to t=16s.
16
11
)(1116 dttvSS
2015,61.14166.351356.0
1510,88.88928.48888.02
2
ttt
ttttv
m9.1595
61.14166.351356.088.88928.48888.0
1116
16
15
215
11
2
16
11
15
11
16
15
dtttdttt
dttvdttvdttvSS
43
Newton’s Divided Difference Method
Linear interpolation: Given pass a linear interpolant through the data
where
),,( 00 yx ),,( 11 yx
)()( 0101 xxbbxf
)( 00 xfb
01
011
)()(
xx
xfxfb
44
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.
t v(t)
s m/s
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Table 1: Velocity as a function of time
Figure 2: Velocity vs. time data for the rocket example
45
Linear Interpolation
10 12 14 16 18 20 22 24350
400
450
500
550517.35
362.78
y s
f range( )
f x desired
x s1
10x s0
10 x s range x desired
,150 t 78.362)( 0 tv
,201 t 35.517)( 1 tv
)( 00 tvb 78.362
01
011
)()(
tt
tvtvb
914.30
)()( 010 ttbbtv
46
Linear Interpolation (contd)
10 12 14 16 18 20 22 24350
400
450
500
550517.35
362.78
y s
f range( )
f x desired
x s1
10x s0
10 x s range x desired
)()( 010 ttbbtv
),15(914.3078.362 t 2015 t
At 16t
)1516(914.3078.362)16( v
69.393 m/s
47
Quadratic InterpolationGiven ),,( 00 yx ),,( 11 yx and ),,( 22 yx fit a quadratic interpolant through the data.
))(()()( 1020102 xxxxbxxbbxf
)( 00 xfb
01
011
)()(
xx
xfxfb
02
01
01
12
12
2
)()()()(
xx
xx
xfxf
xx
xfxf
b
48
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.
t v(t)
s m/s
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Table 1: Velocity as a function of time
Figure 2: Velocity vs. time data for the rocket example
49
Quadratic Interpolation (contd)
0104.203.0 623 xxxxf10 12 14 16 18 20
200
250
300
350
400
450
500
550517.35
227.04
y s
f range( )
f x desired
2010 x s range x desired
,100 t 04.227)( 0 tv
,151 t 78.362)( 1 tv
,202 t 35.517)( 2 tv
50
Quadratic Interpolation (contd)
)( 00 tvb
04.227
01
011
)()(
tt
tvtvb
1015
04.22778.362
148.27
02
01
01
12
12
2
)()()()(
tt
tt
tvtv
tt
tvtv
b
1020
1015
04.22778.362
1520
78.36235.517
10
148.27914.30
37660.0
51
Quadratic Interpolation (contd)
))(()()( 102010 ttttbttbbtv
),15)(10(37660.0)10(148.2704.227 ttt 2010 t
At ,16t
)1516)(1016(37660.0)1016(148.2704.227)16( v 19.392 m/s
The absolute relative approximate error a obtained between the results from the first
order and second order polynomial is
a 100x19.392
69.39319.392
= 0.38502 %
52
General Form
))(()()( 1020102 xxxxbxxbbxf
where
Rewriting))(](,,[)](,[][)( 1001200102 xxxxxxxfxxxxfxfxf
)(][ 000 xfxfb
01
01011
)()(],[
xx
xfxfxxfb
02
01
01
12
12
02
01120122
)()()()(
],[],[],,[
xx
xx
xfxf
xx
xfxf
xx
xxfxxfxxxfb
53
General FormGiven )1( n data points, nnnn yxyxyxyx ,,,,......,,,, 111100 as
))...()((....)()( 110010 nnn xxxxxxbxxbbxf
where
][ 00 xfb
],[ 011 xxfb
],,[ 0122 xxxfb
],....,,[ 0211 xxxfb nnn
],....,,[ 01 xxxfb nnn
54
General formThe third order polynomial, given ),,( 00 yx ),,( 11 yx ),,( 22 yx and ),,( 33 yx is
))()(](,,,[
))(](,,[)](,[][)(
2100123
1001200103
xxxxxxxxxxf
xxxxxxxfxxxxfxfxf
0b
0x )( 0xf 1b
],[ 01 xxf 2b
1x )( 1xf ],,[ 012 xxxf 3b
],[ 12 xxf ],,,[ 0123 xxxxf
2x )( 2xf ],,[ 123 xxxf
],[ 23 xxf
3x )( 3xf
55
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.
t v(t)
s m/s
0 0
10 227.04
15 362.78
20 517.35
22.5 602.97
30 901.67
Table 1: Velocity as a function of time
Figure 2: Velocity vs. time data for the rocket example
56
Example
The velocity profile is chosen as))()(())(()()( 2103102010 ttttttbttttbttbbtv
we need to choose four data points that are closest to 16t
,100 t 04.227)( 0 tv
,151 t 78.362)( 1 tv ,202 t 35.517)( 2 tv ,5.223 t 97.602)( 3 tv
The values of the constants are found as : b0 = 227.04; b1 = 27.148; b2 = 0.37660; b3 = 5.4347*10-3
57
Example
b0 = 227.04; b1 = 27.148; b2 = 0.37660; b3 = 5.4347*10-3
0b
100 t 04.227 1b
148.27 2b
,151 t 78.362 37660.0 3b
914.30 3104347.5 x
,202 t 35.517 44453.0
248.34
,5.223 t 97.602
58
ExampleHence
))()(())(()()( 2103102010 ttttttbttttbttbbtv
)20)(15)(10(10*4347.5
)15)(10(37660.0)10(148.2704.2273
ttt
ttt
At ,16t
)2016)(1516)(1016(10*4347.5
)1516)(1016(37660.0)1016(148.2704.227)16(3
v
06.392 m/s
The absolute relative approximate error a obtained is
a 100x06.392
19.39206.392
= 0.033427 %
59
Comparison Table
Order of Polynomial
1 2 3
v(t=16) m/s
393.69 392.19 392.06
Absolute Relative Approximate Error
---------- 0.38502 %
0.033427 %
60
Distance from Velocity Profile
Find the distance covered by the rocket from t=11s tot=16s ?
)20)(15)(10(10*4347.5
)15)(10(37660.0)10(148.2704.227)(3
ttt
ttttv 5.2210 t
32 0054347.013204.0265.212541.4 ttt 5.2210 t So
16
11
1116 dttvss
dtttt )0054347.013204.0265.212541.4( 3216
11
16
11
432
40054347.0
313204.0
2265.212541.4
tttt
m 1605