# Spline Interpolation Method Power Point

Document Sample

```					Spline Interpolation Method

Chemical Engineering Majors

Authors: Autar Kaw, Jai Paul

http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM

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  25x 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

1.0      0.038461                 Figure : 5th order polynomial vs. exact function

5                                                              http://numericalmethods.eng.usf.edu
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

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 ( x1 )  f ( x 0 )
f ( x )  f ( x0 )                          ( x  x 0 ),        x 0  x  x1
x1  x 0

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

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,
T C
 J 
 kg  C 
Cp          
         
22              4181
42              4179
52              4186
82              4199
100             4217

Figure 2 Specific heat of water vs. temperature.
9                                                        http://numericalmethods.eng.usf.edu
Linear Interpolation
T0  52,            C p (T0 )  4186
4200
T1  82 ,           C p (T1 )  4199
3
4.19910

C p (T1 )  C p (T0 )
C p (T )  C p (T0 )                            (T  T0 )                    4195

T1  T0                       ys

f ( range)

           
4199  4186                                f x desired

 4186              (T  52)                                        4190
82  52
C p (T )  4186  0.43333 (T  52 ), 52  T  82
3
4.18610         4185

At T  61,
50    60                   70        80    90
x s  10              x s  range  x desired        x s  10
0                                                    1

C p (61)  4186  0.43333 (61  52 )

J
 4189 .9
kg   C
10                                                                                              http://numericalmethods.eng.usf.edu
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 ,        x 0  x  x1

 a 2 x 2  b2 x  c2 ,        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
Each quadratic spline goes through two consecutive data points
a1 x 0  b1 x 0  c1  f ( x0 )
2

a1 x12  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
12                                                                http://numericalmethods.eng.usf.edu
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

13                                                        http://numericalmethods.eng.usf.edu
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
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 ,    x0  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                                                          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,
T C
 J 
 kg  C 
Cp          
         
22              4181
42              4179
52              4186
82              4199
100             4217

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.
C p (T )  a1T 2  b1T  c1 ,    22  T  42

 a 2T 2  b2T  c 2 ,   42  T  52

 a 3T 2  b3T  c3 ,    52  T  82

 a 4T 2  b4T  c 4 ,   82  T  100

17                                                   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,
a 2 (42 ) 2  b2 (42 )  c 2  4179     (3)

a 2 (52 ) 2  b2 (52 )  c 2  4186     (4)

a3 (52 ) 2  b3 (52 )  c3  4186       (5)

a3 (82 ) 2  b3 (82 )  c3  4199       (6)

a 4 (82 ) 2  b4 (82 )  c 4  4199     (7)

a 4 (100 ) 2  b4 (100 )  c 4  4217   (8)
18                                                               http://numericalmethods.eng.usf.edu
Solution (contd)
Quadratic splines have continuous derivatives at the interior data points
At T = 42                                           4.19910
3
4200

2a1 (42 )  b1  2a 2 (42 )  b2  0   (9)                           4195

At T = 52                                           ys               4190

2a 2 (52 )  b2  2a3 (52 )  b3  0   (10)         f ( range)


f x desired  
4185

At T = 82
2a3 (82 )  b3  2a 4 (82 )  b4  0
4180
(11)
3
4.17910         4175
40   45   50   55      60          65         70   75   80   85
42                  x s  range  x desired                  82

Assuming the first spline a1T 2  b1T  c1 is linear,
a1  0

19                                                                                    http://numericalmethods.eng.usf.edu
Solution (contd)
 484 22 1  0   0 0  0    0 0   0    0 0  a1   4181
1764 42 1
           0   0 0  0    0 0   0    0 0  b1   4179
            
 0   0 0 1764 42 1  0    0 0   0    0 0  c1   4179
                                                    
  0  0 0 2704 52 1  0    0 0   0    0 0 a 2   4186
 0   0 0   0   0 0 2704 52 1   0    0 0 b2   4186
                                                    
 0   0 0   0   0 0 6724 82 1   0    0 0  c 2   4199
 0   0 0   0   0 0  0    0 0 6724 82 1 3  a    4199
                                                    
 0   0 0   0   0 0  0    0 0 10000 100 1  b3  4217
 84  1 0  84  1 0 0    0 0   0    0 0  c3   0 
                                                    
 0   0 0 104 1 0  104  1 0   0    0 0  a 4   0 
                                                    
  0  0 0   0   0 0 164  1 0  164  1 0 b4   0 
 1
     0 0   0   0 0  0    0 0   0    0 0  c 4   0 
            

20                                         http://numericalmethods.eng.usf.edu
Solution (contd)
Solving the above 12 equations gives the 12 unknowns as

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

21                                             http://numericalmethods.eng.usf.edu
Solution (contd)
Therefore, the splines are given by                                   4.19910
3
4200

C p (T )  0.1T  4183 .2,                     22  T  42
4195

 0.08T  6.82T  4324 .3,
2
42  T  52
ys               4190
 0.035556 T 2  5.1978 T  4011 .9, 52  T  82      f ( range)


f x desired  
 0.090741 T 2  15 .515 T  4861 .1,   82  T  100                    4185

At T = 61
4180

C p (61)  0.035556(61)  5.1978(61)  4011.9
2

3
4.17910         4175
40   45   50   55      60          65         70   75   80   85
J
 4196 .6                                                                      42                  x s  range  x desired                  82

kg   C
The absolute relative approximate error a obtained between the results from the linear and
4196 .6  4189 .9
a                      100
4196 .6
 0.16013 %
22                                                                                          http://numericalmethods.eng.usf.edu
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 )             Tb  boiling temperature of water (C )

Given             Tr  22 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              100

C
Tr
p   dT     C
22
p   (T )dT

42                    52             82             100
  C p (T )dT   C p (T )dT   C p (T )dT   C p (T )dT
22                    42             52             82

  0.1T  4183.2dT   0.08T                                      
42                                 52
                                             2
 6.82T  4324.3 dT
22                                 42

                                                         0.090741T                        
82                                                             100
   0.035556T  5.1978T  4011.9 dT 
2                                                  2
 15.515T  4861.1 dT
52                                                             82

42                                                 52
      T2                   T3        T2           
  0.1     4183.2T   0.08     6.82     4324.3T 
       2            22     3         2             42
82                                              100
             T3           T2                         T3         T2           
  0.035556  5.1978            4011.9T   0.090741  15.515        4861.1T 
             3             2               52         3         2             82
 [83600 ]  [41812 ]  [125940 ]  [75656 ]
J
 3.2700  10 5
kg
24                                                                  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   dT
C p ,avg 
Tr

Tb  Tr

3.2700 10 5

100  22
J
 4192 .3
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
a                      100
4192 .3
 0.10211 %
25                                                                   http://numericalmethods.eng.usf.edu
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

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 63 posted: 11/3/2012 language: Unknown pages: 27
How are you planning on using Docstoc?