PPT - Math For College

advertisement
Spline Interpolation Method
Chemical Engineering Majors
Authors: Autar Kaw, Jai Paul
http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates
http://numericalmethods.eng.usf.edu
1
Spline Method of
Interpolation
http://numericalmethods.eng.usf.edu
What is Interpolation ?
Given (x0,y0), (x1,y1), …… (xn,yn), find the
value of ‘y’ at a value of ‘x’ that is not given.
3
http://numericalmethods.eng.usf.edu
Interpolants
Polynomials are the most common
choice of interpolants because they
are easy to:
Evaluate
Differentiate, and
Integrate.
4
http://numericalmethods.eng.usf.edu
Why Splines ?
1
f ( x) 
1  25 x 2
Table : Six equidistantly spaced points in [-1, 1]
x
1
1  25 x 2
-1.0
0.038461
-0.6
0.1
-0.2
0.5
0.2
0.5
0.6
0.1
1.0
5
y
0.038461
Figure : 5th order polynomial vs. exact function
http://numericalmethods.eng.usf.edu
Why Splines ?
1.2
0.8
y
0.4
0
-1
-0.5
0
0.5
1
-0.4
-0.8
x
19th Order Polynomial
f (x)
5th Order Polynomial
Figure : Higher order polynomial interpolation is a bad idea
6
http://numericalmethods.eng.usf.edu
Linear Interpolation
Given  x0 , y0 , x1 , y1 ,......, x n1 , y n 1  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
7
http://numericalmethods.eng.usf.edu
Linear Interpolation (contd)
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 .
8
http://numericalmethods.eng.usf.edu
Example
To find how much heat is required to bring a kettle of water to its boiling point,
you are asked to calculate the specific heat of water at 61°C. The specific heat of
water is given as a function of time in Table 1. Use linear spline interpolation to
determine the value of the specific heat at T = 61°C.
Table 1 Specific heat of water as a
function of temperature.
Temperature,
Specific heat,
22
42
52
82
100
4181
4179
4186
4199
4217
T C
 J 

C p 
 kg  C 
Figure 2 Specific heat of water vs. temperature.
9
http://numericalmethods.eng.usf.edu
Linear Interpolation
T0  52,
C p (T0 )  4186
T1  82,
C p (T1 )  4199
C p (T )  C p (T0 ) 
C p (T1 )  C p (T0 )
T1  T0
(T  T0 )
4199  4186
 4186 
(T  52)
82  52
3 4200
4.19910
4195
ys
f ( range)


f x desired
4190
C p (T )  4186 0.43333(T  52), 52  T  82
3
4.18610
At T  61,
4185
50
x s  10
0
60
70
80
x s  range x desired
C p (61)  4186 0.43333(61 52)
 4189.9
10
J
kg   C
http://numericalmethods.eng.usf.edu
90
x s  10
1
Quadratic 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
Find a i , bi , ci , i  1, 2, …, n
11
http://numericalmethods.eng.usf.edu
Quadratic Interpolation (contd)
Each quadratic spline goes through two consecutive data points
a1 x 0  b1 x 0  c1  f ( x0 )
2
a1 x1  b1 x1  c1  f ( x1 )
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 n 1  bn x n 1  c n  f ( xn 1 )
2
a n x n  bn xn  cn  f ( x n )
2
12
This condition gives 2n equations
http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
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 a1x1  b1  2a 2 x1  b2  0
13
http://numericalmethods.eng.usf.edu
Quadratic Splines (contd)
Similarly at the other interior points,
2a 2 x 2  b2  2a3 x 2  b3  0
.
.
.
2ai xi  bi  2ai 1 xi  bi 1  0
.
.
.
2a n 1 x n 1  bn 1  2a n x n1  bn  0
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
http://numericalmethods.eng.usf.edu
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,
f ( x)  a1 x 2  b1 x  c1 ,
 a 2 x 2  b2 x  c 2 ,
x0  x  x1
x1  x  x 2
.
.
.
 a n x 2  bn x  c n ,
15
x n 1  x  x n
http://numericalmethods.eng.usf.edu
Example
To find how much heat is required to bring a kettle of water to its boiling point,
you are asked to calculate the specific heat of water at 61°C. The specific heat of
water is given as a function of time in Table 1. Use quadratic spline interpolation
to determine the value of the specific heat at T = 61°C.
Table 1 Specific heat of water as a
function of temperature.
Temperature,
Specific heat,
22
42
52
82
100
4181
4179
4186
4199
4217
T C
 J 

C p 
 kg  C 
Figure 2 Specific heat of water vs. temperature.
16
http://numericalmethods.eng.usf.edu
Solution
Since there are five data points,
four quadratic splines pass through them.
17
C p (T )  a1T 2  b1T  c1 ,
22  T  42
 a2T 2  b2T  c2 ,
42  T  52
 a3T 2  b3T  c3 ,
52  T  82
 a4T 2  b4T  c4 ,
82  T  100
http://numericalmethods.eng.usf.edu
Solution (contd)
Setting up the equations
Each quadratic spline passes through two consecutive data points giving
a1T 2  b1T  c1 passes through T = 22 and T = 42,
a1 (22) 2  b1 (22)  c1  4181
(1)
a1 (42) 2  b1 (42)  c1  4179
(2)
Similarly,
18
a2 (42) 2  b2 (42)  c2  4179
(3)
a2 (52) 2  b2 (52)  c2  4186
(4)
a3 (52) 2  b3 (52)  c3  4186
(5)
a3 (82) 2  b3 (82)  c3  4199
(6)
a4 (82) 2  b4 (82)  c4  4199
(7)
a4 (100) 2  b4 (100)  c4  4217
(8)
http://numericalmethods.eng.usf.edu
Solution (contd)
Quadratic splines have continuous derivatives at the interior data points
At T = 42
2a1 (42)  b1  2a2 (42)  b2  0
3
4.19910
(9)
At T = 52
2a2 (52)  b2  2a3 (52)  b3  0
4195
ys
(10)
4200
4190
f ( range)


f x desired
4185
At T = 82
2a3 (82)  b3  2a4 (82)  b4  0
4180
(11)
3
4.17910
4175
40
42
45
50
55
60
65
70
75
80
x s  range x desired
Assuming the first spline a1T 2  b1T  c1 is linear,
a1  0
19
http://numericalmethods.eng.usf.edu
85
82
Solution (contd)
 484
1764

 0

 0
 0

 0
 0

 0
 84

 0

 0
 1
20
22 1
42 1
0
0
0
0
0
0
0
0
0
0 1764 42 1
0 2704 52 1
0
0
0 0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
 84
104
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0 0
0
0 0
2704 52 1
0 6724 82
0
0
0
0
0
0
0
0
0
0  104  1
0 164 1
0
0
0
1
0
0
0
0
0
0
0  a1   4181
0  b1  4179
0
0 0  c1  4179
  

0
0 0 a 2  4186
0
0 0 b2  4186
  

0
0 0  c 2  4199




6724 82 1 a3
4199
  

b
10000 100 1  3  4217
0
0 0  c 3   0 
  

0
0 0  a 4   0 
  

 164  1 0 b4   0 
0
0 0  c 4   0 
0
0
0
0
http://numericalmethods.eng.usf.edu
Solution (contd)
Solving the above 12 equations gives the 12 unknowns as
21
i
ai
bi
ci
1
0
−0.1
4183.2
2
0.08
−6.82
4324.3
3
−0.035556 5.1978
4011.9
4
0.090741 −15.515 4861.1
http://numericalmethods.eng.usf.edu
Solution (contd)
Therefore, the splines are given by
C p (T )  0.1T  4183.2,
3
4.19910
4200
22  T  42
4195
 0.08T  6.82T  4324.3,
2
42  T  52
 0.035556T 2  5.1978T  4011.9, 52  T  82
 0.090741T 2  15.515T  4861.1,
82  T  100
ys
4190
f ( range)


f x desired
4185
At T = 61
4180
C p (61)  0.035556(61)  5.1978(61)  4011.9
2
3
4.17910
J
 4196.6
kg   C
4175
40
45
50
55
42
60
65
70
75
80
x s  range x desired
The absolute relative approximate error a obtained between the results from the linear and
quadratic splines is
4196.6  4189.9
 100
4196.6
 0.16013%
a 
22
http://numericalmethods.eng.usf.edu
85
82
Better Estimate
The heat required to heat the water is given more accurately by
Tb
Q  m  C p dT
Tr
Tr  room temperature (C )
Given
Tr  22C
Tb  boiling temperature of water (C )
Tb  100C
Find a better estimate of the heat required. What is the difference between the
results from this method and the Quadratic Interpolation?
23
http://numericalmethods.eng.usf.edu
Better Estimate
Tb
C
100
p
dT 
Tr
C
p
(T )dT
22
42
52
82
100
22
42
52
82
  C p (T )dT   C p (T )dT   C p (T )dT   C p (T )dT
  0.1T  4183.2dT   0.08T
42

22
82

52
2
 6.82T  4324.3 dT
42


   0.035556T  5.1978T  4011.9 dT 
2
52
 0.090741T

100
2
 15.515T  4861.1 dT
82
42
52




T2
T3
T2
  0.1
 4183.2T   0.08  6.82
 4324.3T 
2
3
2

 22 
 42
82
100




T3
T2
T3
T2
  0.035556  5.1978  4011.9T   0.090741  15.515  4861.1T 
3
2
3
2

 52 
 82
 [83600]  [41812]  [125940]  [75656]
 3.2700 105
24
J
kg
http://numericalmethods.eng.usf.edu
Better Estimate
To compare this result with our results from Quadratic interpolation, we take the average specific
heat over this interval, given by:
Tb
C p ,avg 
C
p
dT
Tr
Tb  Tr
3.2700105

100 22
 4192.3
J
kg   C
Knowing that this method is the more accurate way of calculating the heat transfer, we define the
absolute relative approximate error a by
4192.3  4196.7
100
4192.3
 0.10211%
a 
25
http://numericalmethods.eng.usf.edu
Additional Resources
For all resources on this topic such as digital audiovisual
lectures, primers, textbook chapters, multiple-choice
tests, worksheets in MATLAB, MATHEMATICA, MathCad
and MAPLE, blogs, related physical problems, please
visit
http://numericalmethods.eng.usf.edu/topics/spline_met
hod.html
THE END
http://numericalmethods.eng.usf.edu
Download