PPT - Math For College

Download Report

Transcript PPT - Math For College

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

3

What is Interpolation ?

Given (x

0

,y

0

), (x

1

,y

1

), …… (x

n

,y

n

), find the value of ‘y’ at a value of ‘x’ that is not given.

http://numericalmethods.eng.usf.edu

4

Interpolants Polynomials are the most common choice of interpolants because they are easy to: Evaluate Differentiate, and Integrate .

http://numericalmethods.eng.usf.edu

5

Why Splines ?

f

(

x

)  1 1  25

x

2

Table : Six equidistantly spaced points in [-1, 1]

x

-1.0 -0.6 -0.2 0.2 0.6

y

 1  1 25

x

2 0.038461 0.1 0.5 0.5 0.1 1.0 0.038461

Figure : 5 th order polynomial vs. exact function

http://numericalmethods.eng.usf.edu

6

Why Splines ?

1.2

0.8

0.4

-1 -0.5

0 0 -0.4

19th Order Polynomial -0.8

x

f (x) 0.5

5th Order Polynomial 1

Figure : Higher order polynomial interpolation is a bad idea

http://numericalmethods.eng.usf.edu

7

Linear Interpolation

Given 

x

0 ,

y

0  

x

1 ,

y

1  ,......, 

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 

y i

f

(

x i

) 

Figure : Linear splines

http://numericalmethods.eng.usf.edu

8

Linear Interpolation (contd)

f

(

x

) 

f

(

x

0 ) 

f

(

x

1 )

x

1  

f x

0 (

x

0 ) (

x

x

0 ), 

f

(

x

1 ) 

f

(

x

2 ) 

x

2 

f x

1 (

x

1 ) (

x

x

1 ),

x x

0 1  

x x

x

1 

x

2 . . . 

f

(

x n

 1 ) 

f

(

x n

) 

x n

f

(

x n

 1 ) (

x

x n

 1

x n

 1 ),

x n

 1 

x

x n

Note the terms of

f

(

x i

)

x i

f

(

x i

 1 ) 

x i

 1 in the above function are simply slopes between

x i

 1 and

x i

. http://numericalmethods.eng.usf.edu

9

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 determine the value of the specific heat at T = 61 ° C.

° C. The specific heat of water is given as a function of time in Table 1. Use linear spline interpolation to Table 1 Specific heat of water as a function of temperature.

Temperature,

T

  22 42 52 82 100 Specific heat,

C p

  kg J   C   4181 4179 4186 4199 4217 Figure 2 Specific heat of water vs. temperature.

http://numericalmethods.eng.usf.edu

10

Linear Interpolation

T

0  52 ,

C p

(

T

0 )  4186

T

1  82 ,

C p

(

T

1 )  4199 4.199 10 3 4200

C p

(

T

) 

C p

(

T

0 ) At

T

 61 , 

C p

(

T

1 )

T

1 

C p

(

T

0 ) 

T

0

C p

(

T

)  4186  0 .

43333 (

T

 52 ), (

T

 4186  4199 82  4186  52 (

T

 52 ) 52  

T

0

T

) y s f range )  desired  4195 4190  82 4.186 10 3 4185 x s 0  10

C p

( 61 )  4186  0 .

43333 ( 61  52 ) 50 60 70 x s  range  x desired  4189 .

9

kg J

 

C

80 http://numericalmethods.eng.usf.edu

90 x s 1  10

11

Quadratic Interpolation

Given 

x

0 ,

y

0

x

1 ,

y

1  ,......, 

x n

 1 ,

y n

 1 are given by

f

(

x

) 

a

1

x

2 

b

1

x

c

1 , 

a

2

x

2 

b

2

x

c

2 ,

x n

,

y n

 , fit quadratic splines through the data. The splines

x

0 

x

x

1

x

1 

x

x

2 . . . 

a n x

2 

b n x

c n

,

x n

 1 

x

x n

Find

a i

,

b i

,

c i

,

i

 1, 2, …, n http://numericalmethods.eng.usf.edu

12

Quadratic Interpolation (contd)

Each quadratic spline goes through two consecutive data points

a

1

x

0 2 

b

1

x

0 

c

1 

f

(

x

0 )

a

1

x

1 2 

b

1

x

1 

c

1 

f

(

x

1 ) . . .

a i x i

 1 2 

b i x i

 1 

c i

f

(

x i

 1 )

a i x i

2 

b i x i

c i

f

(

x i

) . . .

a n x n

 1 2 

b n x n

 1 

c n

f

(

x n

 1 )

a n x n

2 

b n x n

c n

f

(

x n

) This condition gives 2n equations http://numericalmethods.eng.usf.edu

13

Quadratic Splines (contd)

The first derivatives of two quadratic splines are continuous at the interior points. For example, the derivative of the first spline

a

1

x

2 

b

1

x

c

1 is 2

a

1

x

b

1 The derivative of the second spline

a

2

x

2 

b

2

x

c

2 is 2

a

2

x

b

2 and the two are equal at

x

x

1 giving 2

a

1

x

1 

b

1  2

a

2

x

1 

b

2 2

a

1

x

1 

b

1  2

a

2

x

1 

b

2  0 http://numericalmethods.eng.usf.edu

Quadratic Splines (contd)

Similarly at the other interior points, 2

a

2

x

2 

b

2  2

a

3

x

2 

b

3  0 . . . 2

a i x i

b i

 2

a i

 1

x i

b i

 1  0 . . 14 . 2

a n

 1

x n

 1 

b n

 1  2

a n x n

 1 

b n

 0 We have (n-1) such equations. The total number of equations is ( 2

n

)  (

n

 1 )  ( 3

n

 1 ) . We can assume that the first spline is linear, that is

a

1  0 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

) 

a

1

x

2 

b

1

x

c

1 , 

a

2

x

2 

b

2

x

c

2 , . . . 

a n x

2 

b n x

c n

,

x

0 

x

x

1

x

1 

x

x

2

x n

 1 

x

x n

15 http://numericalmethods.eng.usf.edu

16

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 to determine the value of the specific heat at T = 61 ° C.

° C. The specific heat of water is given as a function of time in Table 1. Use quadratic spline interpolation Table 1 Specific heat of water as a function of temperature.

Temperature,

T

  22 42 52 82 100 Specific heat,

C p

  kg J   C   4181 4179 4186 4199 4217 Figure 2 Specific heat of water vs. temperature.

http://numericalmethods.eng.usf.edu

Solution

Since there are five data points, four quadratic splines pass through them.

C p

(

T

) 

a

1

T

2 

b

1

T

c

1 , 22 

T

 42 

a

2

T

2 

b

2

T

c

2 , 

a

3

T

2 

b

3

T

c

3 , 

a

4

T

2 

b

4

T

c

4 , 42 

T

 52 52 

T

 82 82 

T

 100 17 http://numericalmethods.eng.usf.edu

18

Solution (contd)

Setting up the equations Each quadratic spline passes through two consecutive data points giving

a

1

T

2 

b

1

T

c

1 passes through T = 22 and T = 42,

a

1 ( 22 ) 2 

b

1 ( 22 ) 

c

1  4181

a

1 ( 42 ) 2 

b

1 ( 42 ) 

c

1  4179 Similarly, (1) (2)

a

2 ( 42 ) 2 

b

2 ( 42 ) 

c

2  4179

a

2 ( 52 ) 2 

b

2 ( 52 ) 

c

2  4186

a

3 ( 52 ) 2 

b

3 ( 52 ) 

c

3  4186 (3) (4) (5)

a

3 ( 82 ) 2 

b

3 ( 82 ) 

c

3  4199

a

4 ( 82 ) 2 

b

4 ( 82 ) 

c

4  4199

a

4 ( 100 ) 2 

b

4 ( 100 ) 

c

4  4217 (6) (7) (8) http://numericalmethods.eng.usf.edu

Solution (contd)

19 Quadratic splines have continuous derivatives at the interior data points At T = 42 2

a

1 ( 42 ) 

b

1  2

a

2 ( 42 ) 

b

2  0 (9) 4.199 10 3 4200 4195 At T = 52 2

a

2 ( 52 ) 

b

2  2

a

3 ( 52 ) 

b

3  0 (10) y s 4190 f range )  desired  4185 At T = 82 2

a

3 ( 82 ) 

b

3  2

a

4 ( 82 ) 

b

4  0 (11) 4180 Assuming the first spline

a

1

T

2 

b

1

T

4.179 10 3 4175 40 42 

c

1 is linear,

a

1  0 45 50 55 60 65 x s  range  x desired 70 75 80 http://numericalmethods.eng.usf.edu

85 82

20

Solution (contd)

                484   1764 0 0 0 0 0 0 84 0 0 1 0 0 1 0 0 0 22 42 0 0 0 0 0 0 1764 2704 0 0 0 0  84 104 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0  1 1 0 0 0 0 42 52 0 0 0 0 0 0 2704 6724 0 0 0  104 164 0 52 82 0 0 0 0 0 0 0  1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 6724 10000 0 0  164 0 0 0 82 100 0 0 0 0 0 0  1 0                   1 0   0   0 0   0 0 0 0   0   0 1                    

a b c

 

a

1

b c a b c

1 1 2 2 2 3 3 3    

a b

4

c

4 4                    4181 4179 4179     4186 4186 4199 4199 4217 0 0 0 0               http://numericalmethods.eng.usf.edu

21

Solution (contd)

Solving the above 12 equations gives the 12 unknowns as i

a i b i c i

1 2 3 0 0.08 −0.1 4183.2 −6.82 4324.3 −0.035556 5.1978 4011.9 4 0.090741 −15.515 4861.1 http://numericalmethods.eng.usf.edu

Solution (contd)

22 Therefore, the splines are given by

C p

(

T

)   0 .

1

T

 4183 .

2 , 22 

T

 42 4.199 10 3 4200 4195  0 .

08

T

2  6 .

82

T

 4324 .

3 , 42 

T

 52  0 .

090741

T

2  15 .

515

T

 4861 .

1 , y s 4190   0 .

035556

T

2  5 .

1978

T

 4011 .

9 , 52 

T

 82 82 

T

 100 f range )  desired  4185 At T = 61

C p

( 61 )   0 .

035556 ( 61 ) 2  5 .

1978 ( 61 )  4011 .

9 4180 4.179 10 3 4175 40 42  4196 .

6

kg J

 

C

45 50 55 60 65 x s  range  x desired 70 75 80 The absolute relative approximate error 

a

quadratic splines is obtained between the results from the linear and 

a

 4196 .

6  4189 .

4196 .

6  0 .

16013 % 9  100 http://numericalmethods.eng.usf.edu

85 82

Better Estimate

23 The heat required to heat the water is given more accurately by

Q

m T r

T b C p dT T r

 room temperature ( 

C

) Given

T r

 22 

C T b

 boiling temperature of water ( 

C

)

T b

 100 

C

Find a better estimate of the heat required. What is the difference between the results from this method and the Quadratic Interpolation? http://numericalmethods.eng.usf.edu

24

Better Estimate

T r

T b C p dT

 100  22

C p

(

T

)

dT

  42 22

C p

(

T

)

dT

  52 42

C p

(

T

)

dT

  82 52

C p

(

T

)

dT

 100  82

C p

(

T

)

dT

  42 22   0 .

1

T

 4183 .

2 

dT

  82 52   0 .

035556

T

2   52 42  0 .

08

T

 5 .

1978

T

2  6 .

82

T

 4011 .

9 

dT

  4324 .

3 

dT

100  82  0 .

090741

T

2  15 .

515

T

 4861 .

1 

dT

    0 .

1

T

2 2  4183 .

2

T

  42 22    0 .

08

T

3 3  6 .

82

T

2 2  4324 .

3

T

  52 42     0 .

035556

T

3 3  5 .

1978

T

2 2  4011 .

9

T

  82 52  [ 83600 ]  [ 41812 ]  [ 125940 ]  [ 75656 ]    0 .

090741

T

3 3  15 .

515

T

2 2  4861 .

1

T

  100 82  3 .

2700  10 5

J kg

http://numericalmethods.eng.usf.edu

25

Better Estimate

To compare this result with our results from Quadratic interpolation, we take the average specific heat over this interval, given by:

C p

,

avg

T r T b

C p dT T b

T r

 3 .

2700  10 5 100  22  4192 .

3

kg J

 

C

Knowing that this method is the more accurate way of calculating the heat transfer, we define the absolute relative approximate error 

a

by 

a

 4192 .

3  4196 4192 .

3  0 .

10211 % .

7  100 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