PowerPoint Template

advertisement
13/14 Semester 1
Computer Programming
(TKK-2144)
Instructor: Rama Oktavian
Email: rama.oktavian@ub.ac.id
Office Hr.: M.13-15, W. 13-15 Th. 13-15, F. 13-15
Outlines
1. Quadratic Interpolation
2. Cubic Interpolation
3. Spline Interpolation
4. Example in chem.eng
Quadratic interpolation
We want to find a polynomial
P2 ( x)  a0  a1 x  a2 x 2
which satisfies
P2 ( xi )  yi
for
i  0,1,2
for given data points (x0,y0),(x1,y1),(x2,y2).
Quadratic interpolation
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 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 1Velocity vs. time data for the rocket
example
http://numericalmethods.eng.usf.edu
Quadratic interpolation
y
vt   a0  a1t  a2t 2
x1 , y1 
x2 , y2 
v10  a0  a1 10  a2 10  227.04
2
v15  a0  a1 15  a2 15  362.78
2
v20  a0  a1 20  a2 20  517.35
2
f 2 x 
 x0 , y 0 
x
Figure 2 Quadratic interpolation.
Solving the above three equations gives
a0  12.05 a1  17.733 a2  0.3766
http://numericalmethods.eng.usf.edu
Quadratic interpolation
y
vt   12.05  17.733t  0.3766t 2 , 10  t  20
x1 , y1 
x2 , y2 
v16  12.05  17.73316  0.376616
2
 392.19 m/s
f 2 x 
 x0 , y 0 
x
Figure 2 Quadratic interpolation.
http://numericalmethods.eng.usf.edu
Cubic Interpolation
y
vt   a0  a1t  a2t  a3t
2
x3 , y3 
3
x1, y1 
v10  227.04  a0  a1 10  a2 10  a3 10
2
3
v15  362.78  a0  a1 15  a2 15  a3 15
2
3
x0 , y0 
v20  517.35  a0  a1 20  a2 20  a3 20
2
x2 , y2 
f 3 x 
x
3
Figure 3 Cubic interpolation.
v22.5  602.97  a0  a1 22.5  a2 22.5  a3 22.5
2
a0  4.2540
a1  21.266
3
a2  0.13204
a3  0.0054347
http://numericalmethods.eng.usf.edu
Cubic Interpolation
y
x3 , y3 
x1, y1 
x0 , y0 
f 3 x 
x2 , y2 
x
Figure 3 Cubic interpolation.
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 
 392.06 m/s
2
3
http://numericalmethods.eng.usf.edu
Spline Interpolation
 Spline:
 In Mathematics, a spline is a special function defined
piecewise by polynomials;
 In Computer Science, the term spline more frequently
refers to a piecewise polynomial (parametric) curve.
 Simple construction, ease and accuracy of evaluation,
capacity to approximate complex shapes through curve
fitting and interactive curve design.
Spline Interpolation




Spline Interpolation:
Linear spline
Quadratic spline
Cubic spline
Spline Interpolation
 Linear Spline Interpolation:
Spline Interpolation
 Linear Spline Interpolation:
f ( x )  f ( x0 ) 
f ( x1 )  f ( x 0 )
( x  x 0 ),
x1  x 0
x 0  x  x1
 f ( x1 ) 
f ( x 2 )  f ( x1 )
( x  x1 ),
x2  x1
x1  x  x 2
.
.
.
 f ( x n 1 ) 
f ( x n )  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 .
http://numericalmethods.eng.usf.edu
Spline Interpolation
 Quadratic Spline 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 ,
 a 2 x 2  b2 x  c2 ,
x 0  x  x1
x1  x  x 2
.
.
.
 a n x 2  bn x  cn ,
x n 1  x  x n
http://numericalmethods.eng.usf.edu
Spline Interpolation
 Quadratic Spline Interpolation:
Each quadratic spline goes through two consecutive data points
a1 x 0  b1 x 0  c1  f ( x0 )
2
a1 x1 2  b1 x1  c1  f ( x1 )
.
.
.
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 )
2
This condition gives 2n equations
http://numericalmethods.eng.usf.edu
Spline Interpolation
 Quadratic Spline Interpolation:
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
http://numericalmethods.eng.usf.edu
Download