Upload
siddhartha-tungare
View
226
Download
0
Embed Size (px)
Citation preview
8/8/2019 Projects IIST 4 Sept'2010
1/60
http://numericalmethods.eng.usf.edu1
Projects ???
8/8/2019 Projects IIST 4 Sept'2010
2/60
http://numericalmethods.eng.usf.edu2
Interpolants Polynomials are the most
common choice of interpolants
because they are easy to:
EvaluateDifferentiate, andIntegrate.
8/8/2019 Projects IIST 4 Sept'2010
3/60
http://numericalmethods.eng.usf.edu3
Newtons Divided
Difference Method
8/8/2019 Projects IIST 4 Sept'2010
4/60
http://numericalmethods.eng.usf.edu4
f two data points are availablee as {x0,f(x0)}and {x1,f(x1)}, the points can be connected
by a straight line to obtain the simplest formof interpolation,namely,linear interpolation.(see Fig.5.4.)The formula for linearinterpolation can be derived by considering
the similar triangles ADE and ABC, which giveDE BC f1(x) f(x0) f(x1) f(x0)
= , or =
AE AC x x0 x1 x0
Newtons Divided Difference
Method
8/8/2019 Projects IIST 4 Sept'2010
5/60
http://numericalmethods.eng.usf.edu5
Newtons Divided Difference
MethodLinear interpolation: Given pass
a linear interpolant through the data
where
),,( 00 yx ),,( 11 yx
)()( 0101 xxbbxf +=
)( 00 xfb =
01
011
)()(
xx
xfxfb
=
8/8/2019 Projects IIST 4 Sept'2010
6/60
8/8/2019 Projects IIST 4 Sept'2010
7/60
http://numericalmethods.eng.usf.edu7
Linear Interpolation
5 0 5 107.08
7.1
7.12
7.14
7.16
7.18
7.27.2
7.1
y s
f range( )
f x desired( )
x s1
10+x s0
10 x s range, x desired,
)()( 010 xxbbxy +=
,00.20
=x 2.7)(0
=xy
,25.41 =x 1.7)( 1 =xy
)( 00 xyb = 2.7=
01
011 )()(
xxxyxyb = 00.225.4 2.71.7 =
04444.0=
8/8/2019 Projects IIST 4 Sept'2010
8/60
http://numericalmethods.eng.usf.edu8
Linear Interpolation
(contd)
5 0 5 107.08
7.1
7.12
7.14
7.16
7.18
7.27.2
7.1
y s
f range( )
f x desired( )
x s1 10+x s0 10 x s range, x desired,
)()( 010 xxbbxy +=
),00.2(04444.02.7 = x 25.400.2 x
4=x)00.200.4(04444.02.7)00.4( =x
.1111.7 in=
8/8/2019 Projects IIST 4 Sept'2010
9/60
http://numericalmethods.eng.usf.edu9
xamp e: n va ue o x =e . x results to estimate the value of f at
x=1
x0=0 and x1= 2f(x0)= f(0) = e0 =1.0
f(x1) = f(2) = e1.0= 2.718282
f1(x) = b0 + a1 (x-x0)a0=f(x0) = 1.0
f(x1)-f(x0) 2.718282 1.0
a1 = =
x1 x0 2.0 0.0
a1=0.859141
8/8/2019 Projects IIST 4 Sept'2010
10/60
http://numericalmethods.eng.usf.edu10
. results to estimate the value of f at
x=1x
0
=0 and x1
= 2
f1(x) = 1.0 + 0.859141x
X=1.0
f1(1) = 1.0 + 0.859141(1) =1.859141
exect value :f(1) = e0.5 = 1.648721
8/8/2019 Projects IIST 4 Sept'2010
11/60
http://numericalmethods.eng.usf.edu11
Quadratic Interpolation
8/8/2019 Projects IIST 4 Sept'2010
12/60
http://numericalmethods.eng.usf.edu12
Quadratic Interpolation
Given
),,( 00 yx ),,( 11 yx ),,( 22 yx
))(()()( 1020102 xxxxbxxbbxf ++=
)( 00 xfb =
01
011
)()(
xx
xfxfb
=
02
01
01
12
12
2
)()()()(
xx
xx
xfxf
xx
xfxf
b
=
8/8/2019 Projects IIST 4 Sept'2010
13/60
http://numericalmethods.eng.usf.edu13
ExampleThe path of a rapid laser is given by these specifications.If the laser is traversing from x = 2 to x = 4.25 to x=5.25 using aquadratic path, find the value of y at x = 4 using the Newtons Divideddifference polynomial method.
Path of a robot
0
1
2
3
4
5
6
7
8
0 5 10 15
X
Y
x (m) y (m)
2 7.2
4.25 7.1
5.25 67.81 5
9.2 3.5
10.6 5
8/8/2019 Projects IIST 4 Sept'2010
14/60
http://numericalmethods.eng.usf.edu14
Quadratic Interpolation
(contd)
2 2.5 3 3.5 4 4.5 5 5.56
6.5
7
7.5
87.56258
6
y s
f range( )
f x desired( )
5.252 x s range, x desired,
))(()()( 102010 xxxxbxxbbxy ++=
,00.20 =x 2.7)( 0 =xy
,25.41 =x 1.7)( 1 =xy
,25.52 =x 0.6)( 2 =xy
8/8/2019 Projects IIST 4 Sept'2010
15/60
http://numericalmethods.eng.usf.edu15
Quadratic Interpolation
(contd))( 00 xyb =
2.7=
01
011 )()(
xxxyxyb
= 00.225.42.71.7
=
04444.0=
02
01
01
12
12
2
)()()()(
xxxx
xyxy
xx
xyxy
b
=00.225.5
00.225.4
2.71.7
25.425.5
1.70.6
=
25.3
04444.01.1 +=
32479.0=
8/8/2019 Projects IIST 4 Sept'2010
16/60
http://numericalmethods.eng.usf.edu16
Quadratic Interpolation
(contd)))(()()( 102010 xxxxbxxbbxy ++=
),25.4)(00.2(32479.0)00.2(04444.02.7 = xxx 25.500.2 x
,4=x)25.400.4)(00.200.4(32479.0)00.200.4(04444.02.7)00.4( =y
.2735.7 in=
a
1002735.7
1111.72735.7
=a
%2327.2=
8/8/2019 Projects IIST 4 Sept'2010
17/60
http://numericalmethods.eng.usf.edu17
General Form))(()()( 1020102 xxxxbxxbbxf ++=
where
Rewriting
))(](,,[)](,[][)( 1001200102 xxxxxxxfxxxxfxfxf ++=
)(][ 000 xfxfb ==
01
01
011
)()(],[
xx
xfxfxxfb
==
02
01
01
12
12
02
0112
0122
)()()()(
],[],[],,[xx
xx
xfxf
xx
xfxf
xxxxfxxfxxxfb
===
8/8/2019 Projects IIST 4 Sept'2010
18/60
http://numericalmethods.eng.usf.edu18
General Form
Given
)1( +n ( ) ( ) ( ) ( )nnnn yxyxyxyx ,,,,......,,,, 111100 ))...()((....)()( 110010 +++= nnn xxxxxxbxxbbxf
][ 00 xfb =
],[ 011 xxfb =
],,[ 0122 xxxfb =
],....,,[ 0211 xxxfb nnn =
],....,,[ 01 xxxfb nnn =
8/8/2019 Projects IIST 4 Sept'2010
19/60
http://numericalmethods.eng.usf.edu19
General form
The third or
),,( 00 yx ),,( 11 yx ),,( 22 yx ),,( 33 yx
))()(](,,,[))(](,,[)](,[][)(
2100123
1001200103
xxxxxxxxxxfxxxxxxxfxxxxfxfxf
+ ++=
0b
0x )( 0xf 1b
],[ 01 xxf 2b
1x )( 1xf ],,[ 012 xxxf 3b
],[ 12 xxf ],,,[ 0123 xxxxf
2x )( 2xf ],,[ 123 xxxf
],[ 23 xxf
3x )( 3xf
8/8/2019 Projects IIST 4 Sept'2010
20/60
http://numericalmethods.eng.usf.edu20
8/8/2019 Projects IIST 4 Sept'2010
21/60
http://numericalmethods.eng.usf.edu21
Example The path of a rapid laser is given by thesespecifications. Find the path traversed by the laserusing the Newtons Divided Difference Polynomial
method.Path of a robot
0
1
2
3
4
5
6
7
8
0 5 10 15
X
Y
x (m) y (m)
2 7.2
4.25 7.1
5.25 67.81 5
9.2 3.5
10.6 5
8/8/2019 Projects IIST 4 Sept'2010
22/60
http://numericalmethods.eng.usf.edu22
Example
The value of))()()()(())()()((
))()(())(()()(
43210532104
2103102010
xxxxxxxxxxbxxxxxxxxb
xxxxxxbxxxxbxxbbxy
++
+++=
,00.20 =x 2.7)( 0 =xy ,25.41 =x 1.7)( 1 =xy
,25.52 =x 0.6)( 2 =xy ,81.73 =x 0.5)( 3 =xy
,20.94 =x 5.3)( 4 =xy ,60.105 =x 0.5)( 5 =xy
0b 2.7= 1b 04444.0= 2b 32479.0=
3b 090198.0= 4b 023009.0= 5b 0072922.0=
8/8/2019 Projects IIST 4 Sept'2010
23/60
http://numericalmethods.eng.usf.edu23
ExampleHence
))()()()(())()()((
))()(())(()()(
43210532104
2103102010
xxxxxxxxxxbxxxxxxxxb
xxxxxxbxxxxbxxbbxy
++
+++=
)2.9)(81.7)(25.5)(25.4)(2(0072922.0
)81.7)(25.5)(25.4)(2(023009.0
)25.5)(25.4)(2(090198.0
)25.4)(2(32479.0)2(04444.02.7
+
+
=
xxxxx
xxxx
xxx
xxx
6.102,0072922.023091.07862.2855.15344.41898.30)( 5432 +++= xxxxxxxy
8/8/2019 Projects IIST 4 Sept'2010
24/60
http://numericalmethods.eng.usf.edu24
Example
6.102,0072922.023091.07862.2855.15344.41898.30)( 5432 +++= xxxxxxxy
Path of a robot
7.2 7.1
6
5
3.5
5
0
1
2
3
4
5
6
7
8
9
10
0 2 4 6 8 10 12
X
Y
8/8/2019 Projects IIST 4 Sept'2010
25/60
http://numericalmethods.eng.usf.edu25
Newton-Gregory forwardinterpolation formula
The general Newtons interpolationformula can be simplified when the
data points are equally spacedalong x-axis. The resulting formulasare also known as Newton-Gregoryformulas. fh denotes the intervalbetween any two concecutivevalues of xi(xi+1 -xi=h) ve can write
xi
=x0
+ ih , i=1,2,.,n.
8/8/2019 Projects IIST 4 Sept'2010
26/60
http://numericalmethods.eng.usf.edu26
Newton-Gregory forwardinterpolation formula
In this case, the coefficients of the interpolationpolynominal a0,a1,.,an can be expressed as,
0f0
a0=f(x0) =h0
1f0 0f0
a1 = =h1 h0
8/8/2019 Projects IIST 4 Sept'2010
27/60
http://numericalmethods.eng.usf.edu27
Newton-Gregory forward
interpolation formulanf0
an =
n!hnjf0 is thejth-order forward difference(j=1,2,,n)
Using these relations we can write the nth-order
Newtons interpolation polynominal as; f0 2f0fn(x) =f(x0) + (x-x0) + (x-x0)(x-x0-h) +.
h 2!h2
8/8/2019 Projects IIST 4 Sept'2010
28/60
http://numericalmethods.eng.usf.edu28
Interpolation using Splines ,Why
Splines ?2251
1)(
xxf
+=
Table : Six equidistantly spaced points in [-1, 1]
Figure : 5th order polynomial vs. exact function
x 22511x
y+
=
-1.0 0.038461
-0.6 0.1
-0.2 0.5
0.2 0.5
0.6 0.1
1.0 0.038461
8/8/2019 Projects IIST 4 Sept'2010
29/60
http://numericalmethods.eng.usf.edu29
Why Splines ?
Figure : Higher order polynomial interpolation is a bad idea
Original
Function
16th Order
Polynomial
8th Order
Polynomial
4thOrder
Polynomial
8/8/2019 Projects IIST 4 Sept'2010
30/60
http://numericalmethods.eng.usf.edu30
8/8/2019 Projects IIST 4 Sept'2010
31/60
http://numericalmethods.eng.usf.edu31
8/8/2019 Projects IIST 4 Sept'2010
32/60
http://numericalmethods.eng.usf.edu32
8/8/2019 Projects IIST 4 Sept'2010
33/60
http://numericalmethods.eng.usf.edu33
8/8/2019 Projects IIST 4 Sept'2010
34/60
http://numericalmethods.eng.usf.edu34
8/8/2019 Projects IIST 4 Sept'2010
35/60
http://numericalmethods.eng.usf.edu35
Linear InterpolationGiven ( ) ( ) ( )( )nnnn yxyxyxyx ,,,......,,,, 111100 , fit linear splines to the data. This simply involvesforming the consecutive data through s traight lines. So if the above data is given in an ascending
order, the linear splines are given by ( ))( ii xfy =
Figure : Linear splines
8/8/2019 Projects IIST 4 Sept'2010
36/60
8/8/2019 Projects IIST 4 Sept'2010
37/60
http://numericalmethods.eng.usf.edu37
Example The path of a rapid laser is given by these specifications.If the laser is traversing from x = 2 to x = 4.25 in a linear path,find the value of y at x = 4 using the linear spline interpolation
method.
Path of a robot
0
1
2
3
4
5
6
7
8
0 5 10 15
X
Y
x (m) y (m)
2 7.2
4.25 7.1
5.25 67.81 5
9.2 3.5
10.6 5
8/8/2019 Projects IIST 4 Sept'2010
38/60
http://numericalmethods.eng.usf.edu38
Linear Interpolation
5 0 5 107.08
7.1
7.12
7.14
7.16
7.18
7.27.2
7.1
y s
f range( )
f x desired( )
x s1
10+x s0
10 x s range, x desired,
,00.20 =x
2.7)( 0 =xy
,25.41 =x 1.7)( 1 =xy
)()()()()( 001
010 xx
xx
xyxyxyxy +=
)00.2(00.225.4
2.71.72.7
+= x
)00.2(04444.02.7)( = xxy
,4=x
)00.200.4(04444.02.7)00.4( =y
.1111.7 in=
8/8/2019 Projects IIST 4 Sept'2010
39/60
http://numericalmethods.eng.usf.edu39
Linear Interpolation
(contd)
The linear sp),00.2(04444.02.7)( = xxy 25.400.2 x
),25.4(1.11.7)( = xxy 25.525.4 x
),25.5(390625.00.6)( = xxy 81.725.5 x
),81.7(07914.10.5)( = xxy 20.981.7 x
),20.9(07143.15.3)( += xxy 60.1020.9 x
Find the path of the robot if it follows linear splines.
8/8/2019 Projects IIST 4 Sept'2010
40/60
http://numericalmethods.eng.usf.edu40
Linear Interpolation
(contd)Find the length of the path traversed by therobot following linear splines.
The length of the robots path can be found by simply adding the length
of the line segments together. The length of a straight line from one point
),( 00 yx to another point ),( 11 yx is given by2
01
2
01 )()( yyxx + .
Hence, the length of the linear splines from x = 2.00 to x = 10.60 is
22
2222
2222
)5.30.5()20.960.10(
)0.55.3()81.720.9()0.60.5()25.581.7(
)1.70.6()25.425.5()2.71.7()00.225.4(
++
++++
+++=L
L=10.584 m
8/8/2019 Projects IIST 4 Sept'2010
41/60
http://numericalmethods.eng.usf.edu41
Exemple: find a linear spline to fit
the following data :i
0
12
3
4
xi
2.0
3.0
6.5
8.0
12.0
f(xi)
14.0
20.017.0
16.0
23.0
Use the results toestimate the value of fat x= 7.0.
8/8/2019 Projects IIST 4 Sept'2010
42/60
http://numericalmethods.eng.usf.edu42
solutionThe data points can be joined by straightlines to linear spline.since x=7.0 lies inthe interval (6.5 to 8.0) we can findthe equation of the straight linebetween x=6.5 and x=8.0 as
f(x3) f(x2)
f3(x) = f(x2) + (x-x2)x3 x2
8/8/2019 Projects IIST 4 Sept'2010
43/60
http://numericalmethods.eng.usf.edu43
Solution(con)f3(x) = 17.0 +((16.0 17.0) / (8.0 -6.5)) (x-6.5)
= 21.3333 0.6667xThe value of f at x=7.0 can be estimated as
f(7.0)=21.3333-0.6667(7.0) = 16.6664
8/8/2019 Projects IIST 4 Sept'2010
44/60
Q d i I l i
8/8/2019 Projects IIST 4 Sept'2010
45/60
http://numericalmethods.eng.usf.edu45
Quadratic Interpolation(contd)
Each quadratic spline goes through two consecutive data points
)( 01012
01xfcxbxa =++
)(1111
2
11xfcxbxa =++ .
.
.
)(11
2
1 =++ iiiiii xfcxbxa
)(2
iiiiii xfcxbxa =++ .
.
.
)(11
2
1 =++ nnnnnn xfcxbxa
)(2
nnnnnn xfcxbxa =++
This condition gives 2n equations
8/8/2019 Projects IIST 4 Sept'2010
46/60
http://numericalmethods.eng.usf.edu46
Quadratic Splines (contd)The first derivatives of two quadratic splines are continuous at the interior points.
For example, the derivative of the first spline
11
2
1
cxbxa
++is
11
2 bxa
+
The derivative of the second spline
22
2
2 cxbxa ++ is 222 bxa +
and the two are equal at1
xx = giving
21211122 bxabxa +=+
022212111 =+ bxabxa
8/8/2019 Projects IIST 4 Sept'2010
47/60
http://numericalmethods.eng.usf.edu47
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
8/8/2019 Projects IIST 4 Sept'2010
48/60
http://numericalmethods.eng.usf.edu48
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
.
.
.
,2 nnn cxbxa ++= nn xxx 1
8/8/2019 Projects IIST 4 Sept'2010
49/60
http://numericalmethods.eng.usf.edu49
ExampleThe path of a rapid laser is given by thesespecifications in Cartesian co-ordinates. Find thelength of the path traversed by the robot using
quadratic splines.Path of a robot
0
1
2
3
4
5
6
7
8
0 5 10 15
X
Y
x (m) y (m)
2 7.2
4.25 7.1
5.25 67.81 5
9.2 3.5
10.6 5
8/8/2019 Projects IIST 4 Sept'2010
50/60
http://numericalmethods.eng.usf.edu50
Solution
2 4 6 8 10 123
4
5
6
7
87.2
3.5
y
10.62 x
Since ther
fi d
,)( 1121 cxbxaxy ++= 25.400.2 x
,222
2 cxbxa ++= 25.525.4 x
,332
3 cxbxa ++= 81.725.5 x
,4424 cxbxa ++= 20.981.7 x
,552
5 cxbxa ++= 60.1020.9 x
8/8/2019 Projects IIST 4 Sept'2010
51/60
http://numericalmethods.eng.usf.edu51
Solution (contd)Setting up the eq
Each quadratic s
11
2
1cxbxa ++
2.7)00.2()00.2( 112
1 =++ cba
1.7)25.4()25.4( 112
1 =++ cba
Similarly,
1.7)25.4()25.4( 222
2 =++ cba
0.6)25.5()25.5( 222
2 =++ cba
0.6)25.5()25.5( 332
3 =++ cba
0.5)81.7()81.7( 332
3 =++ cba
0.5)81.7()81.7( 442
4 =++ cba
5.3)20.9()20.9( 442
4 =++ cba
5.3)20.9()20.9( 552
5 =++ cba
0.5)60.10()60.10( 552
5 =++ cba
8/8/2019 Projects IIST 4 Sept'2010
52/60
http://numericalmethods.eng.usf.edu52
Solution (contd)
Quadratic spline
At x = 4.25
0)25.4(2)25.4(2 2211 =+ baba
0)25.5(2)25.5(2 3322 =+ baba
0)81.7(2)81.7(2 4433 =+ baba
0)20.9(2)20.9(2 5544 =+ baba
11
2
1 cxbxa ++
01 =a
2 2.5 3 3.5 4 4.5 5 5.56
6.5
7
7.5
87.56258
6
y s
f range( )
f x desired( )
5.252 x s range, x desired,
8/8/2019 Projects IIST 4 Sept'2010
53/60
http://numericalmethods.eng.usf.edu53
Solution (contd)
=
0
0
0
0
0
0.5
5.3
5.3
0.5
0.5
0.6
0.6
1.7
1.7
2.7
000000000000001
014.18014.18000000000
0000162.150162.15000000
000000015.10015.10000
000000000015.8015.8
16.1036.112000000000000
12.964.84000000000000
00012.964.84000000000
000181.7996.60000000000
000000181.7996.60000000
000000125.5563.27000000
000000000125.5563.27000
000000000125.4063.18000
000000000000125.4063.18
000000000000124
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
8/8/2019 Projects IIST 4 Sept'2010
54/60
http://numericalmethods.eng.usf.edu54
Solution (contd)
Solving theia ib ic
8/8/2019 Projects IIST 4 Sept'2010
55/60
http://numericalmethods.eng.usf.edu55
Solution (contd),2889.704444.0)( += xxy 25.400.2 x
,777.119278.80556.1 2 += xx 25.525.4 x
,319.363945.968943.0 2 += xx 81.725.5 x
,40.113945.287651.1 2 += xx 20.981.7 x
,34.314042.642886.3 2 += xx 60.1020.9 x
8/8/2019 Projects IIST 4 Sept'2010
56/60
http://numericalmethods.eng.usf.edu56
Solution (contd)
2 4 6 8 100
2
4
6
88
0
y
fquadratic range( )
111.5 x range,
The length of a cu
)(xfy =
+=b
a
dxdx
dyL
2
1
( ),2889.704444.0 += xdx
d
dx
dy25.400.2 x
( ),777.119278.80556.1 2 += xxdx
d25.525.4 x
( ),319.363945.968943.0 2 += xxdxd 81.725.5 x
( ),40.113945.287651.1 2 += xxdx
d20.981.7 x
( ),34.314042.642886.3 2 += xxdx
d60.1020.9 x
8/8/2019 Projects IIST 4 Sept'2010
57/60
http://numericalmethods.eng.usf.edu57
Solution (contd)
++
++
++
++
+=
60.10
20.9
220.9
81.7
281.7
25.5
225.5
25.4
225.4
00.2
2
11111dx
dy
dx
dy
dx
dy
dx
dydx
dx
dyL
( ) ( ) ( )
( ) ( )
+++++
++++++=
60.10
20.9
220.9
81.7
2
81.7
25.5
225.5
25.4
225.4
00.2
2
042.645772.61945.285302.31
3945.93788.119278.81111.2104444.01
dxxdxx
dxxdxxdx
8080.36067.26596.35499.12522.2 ++++=
876.13=
8/8/2019 Projects IIST 4 Sept'2010
58/60
http://numericalmethods.eng.usf.edu58
ComparisonCompare the answer from part (a) to linearspline result and fifth order polynomial result.
We can find the
6.102,0072923.023091.07862.2855.15344.41898.30)(5432 +++= xxxxxxxy
+=b
a
dxdxdyL
2
1
( ) +++=60.10
00.2
432036461.092364.03586.8710.31344.411 dxxxxx
133.13=
8/8/2019 Projects IIST 4 Sept'2010
59/60
http://numericalmethods.eng.usf.edu59
C programming#include/* interpolation using splines */int main(void){
int n,i,i1,i2;float x[30],fx[30],xx,ffx,a,b;printf("Enter number of datapoints\n");scanf("%d",&n);printf("enter data points (values of x) \n");
for( i=0;i
8/8/2019 Projects IIST 4 Sept'2010
60/60