Spline Interpolation Method Power Point

Download Report

Transcript Spline Interpolation Method Power Point

Spline Interpolation Method
Civil 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 n1 , 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 maximize a catch of bass in a lake, it is suggested to throw the line to
the depth of the thermocline. The characteristic feature of this area is the
sudden change in temperature. We are given the temperature vs. depth plot
for a lake. Determine the value of the temperature at z = −7.5 using Linear
Spline Interpolation.
Temperature
T (oC)
19.1
19.1
19
18.8
18.7
18.3
18.2
17.6
11.7
9.9
9.1
9
Depth
z (m)
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
Temperature vs. depth of a lake
http://numericalmethods.eng.usf.edu
Linear Interpolation
z 0  8,
T ( z 0 )  11.7
z1  7,
T ( z1 )  17.6
T ( z)  T ( z0 ) 
 11.7 
T ( z1 )  T ( z 0 )
( z  z0 )
z1  z 0
17.6  11.7
( z  8)
78
17.6
17
16
ys
15
f ( range)


f x desired
14
13
T z   11.7  5.9z  8,  8  z  7
At z  7.5,
18
12
11.7
11
15
x s  10
0
10
5
x s  range x desired
0
x s  10
T (7.5)  11.7  5.9(7.5  8)
 14 .65 C
10
http://numericalmethods.eng.usf.edu
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 n1  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 maximize a catch of bass in a lake, it is suggested to throw the line to
the depth of the thermocline. The characteristic feature of this area is the
sudden change in temperature. We are given the temperature vs. depth plot
for a lake. Determine the value of the temperature at z = −7.5 using
Quadratic Spline Interpolation.
Temperature
T (oC)
19.1
19.1
19
18.8
18.7
18.3
18.2
17.6
11.7
9.9
9.1
16
Depth
z (m)
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
Temperature vs. depth of a lake
http://numericalmethods.eng.usf.edu
Solution
Since there are eleven data points,
ten quadratic splines pass through them.
T ( z)  a1 z 2  b1 z  c1 ,
17
 10  z  9
 a2 z 2  b2 z  c2 ,
 9  z  8
 a3 z 2  b3 z  c3 ,
 8  z  7
 a4 z 2  b4 z  c4 ,
 7  z  6
 a5 z 2  b5 z  c5 ,
 6  z  5
 a6 z 2  b6 z  c6 ,
 5  z  4
 a7 z 2  b7 z  c7 ,
 4  z  3
 a8 z 2  b8 z  c8 ,
 3  z  2
 a9 z 2  b9 z  c9 ,
 2  z  1
 a10 z 2  b10 z  c10 ,
1  z  0
http://numericalmethods.eng.usf.edu
Solution (contd)
Setting up the equations
Each quadratic spline passes through two consecutive data points giving
a1 z 2  b1 z  c1 passes through z = −10 and z = −9,
Similarly,
18
a1 (10) 2  b1 (10)  c1  9.1
(1)
a1 (9) 2  b1 (9)  c1  9.9
(2)
a2 (9) 2  b2 (9)  c2  9.9
(3)
a2 (8) 2  b2 (8)  c2  11.7
(4)
a3 (8) 2  b3 (8)  c3  11.7
(5)
a3 (7) 2  b3 (7)  c3  17.6
(6)
a4 (7) 2  b4 (7)  c4  17.6
(7)
a4 (6) 2  b4 (6)  c4  18.2
(8)
a5 (6) 2  b5 (6)  c5  18.2
(9)
a5 (5) 2  b5 (5)  c5  18.3
(10)
http://numericalmethods.eng.usf.edu
Solution (contd)
19
a6 (5) 2  b6 (5)  c6  18.3
(11)
a6 (4) 2  b6 (4)  c6  18.7
(12)
a7 (4) 2  b7 (4)  c7  18.7
(13)
a7 (3) 2  b7 (3)  c7  18.8
(14)
a8 (3) 2  b8 (3)  c8  18.8
(15)
a8 (2) 2  b8 (2)  c8  19
(16)
a9 (2) 2  b9 (2)  c9  19
(17)
a9 (1) 2  b9 (1)  c9  19.1
(18)
a10 (1) 2  b10 (1)  c10  19.1
(19)
a10 (0) 2  b10 (0)  c10  19.1
(20)
http://numericalmethods.eng.usf.edu
Solution (contd)
Quadratic splines have continuous derivatives at the interior data points
At z = −9
2a1 (9)  b1  2a2 (9)  b2  0
(21)
At z = −8
2a2 (8)  b2  2a3 (8)  b3  0
(22)
At z = −7
2a3 (7)  b3  2a4 (7)  b4  0
(23)
At z = −6
2a4 (6)  b4  2a5 (6)  b5  0
(24)
At z = −5
2a5 (5)  b5  2a6 (5)  b6  0
(25)
At z = −4
2a6 (4)  b6  2a7 (4)  b7  0
(26)
At z = −3
2a7 (3)  b7  2a8 (3)  b8  0
(27)
At z = −2
2a8 (2)  b8  2a9 (2)  b9  0
(28)
At z = −1
2a9 (1)  b9  2a10 (1)  b10  0
(29)
Assuming the first spline a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0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
1
0
0
0
0 0
0 6
0 4
0 0
0 0
0
1
1
0
0
0 0
0 0
0 4
0 2
0 0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 18  1
0  16 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 16  1
0  14 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 14  1
0  12 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 12  1
0  10 1
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 10
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0 8
0 0
0 0
0 0
0 0
1
0
0
0
0
0 8
0 6
0 0
0 0
0 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0  a1   9.1 
  

0  b1   9.9 
0 0 0  c1   9.9 
  

0 0 0  a2  11.7 
0 0 0  b2  11.7 
  

0 0 0  c2  17.6
  

0 0 0  a3  17.6
0 0 0  b3  18.2
  

0 0 0  c3  18.2
0 0 0  a4  18.3
  

0 0 0  b4  18.3
  

0 0 0  c4  18.7 
0 0 0  a5  18.7 
  

0 0 0  b5  18.8
0 0 0  c5  18.8
   

0 0 0  a6   19 
  

0 0 0  b6   19 
0 0 0  c6  19.1
  

1  1 1  a7  19.1
0 0 1  b7  19.1
  

0 0 0  c7   0 
  

0 0 0  a8   0 
0 0 0  b8   0 
  

0 0 0  c8   0 
0 0 0  a9   0 
  

0 0 0  b9   0 





0 0 0  c9   0 




0 0 0 a10
0 
  

2  1 0  b10   0 
0 0 0  c10   0 
0 0
0 0
0
0
http://numericalmethods.eng.usf.edu
Solution (contd)
Solving the above 30 equations gives the 30 unknowns as
i
1
2
3
4
5
6
7
8
9
10
22
ai
0
1
3.1
−8.4
7.9
−7.6
7.3
−7.2
7.1
−7.2
bi
0.8
18.8
52.4
−108.6
87
−68
51.2
−35.8
21.4
−7.2
ci
17.1
98.1
232.5
−331
255.8
−131.7
106.7
−23.8
33.4
19.1
http://numericalmethods.eng.usf.edu
Solution
(contd)
Therefore, the splines are given by
T ( z )  0.8z  17.1,
 z 2  18.8z  98.1,
 10  z  9
 9  z  8
18
 3.1z 2  52.4z  232.5,
 8  z  7
16
 8.4 z 2  108.6 z  331,
 7  z  6
 7.9z  87z  255.8,
 6  z  5
 7.6 z 2  68z  131.7,
 5  z  4
 7.3z 2  51.2z  106.7,
 4  z  3
2
ys
14
f ( range)


f xdesired
12
10
8
23
 7.2z 2  35.8z  23.8,
 3  z  2
 7.1z 2  21.4z  33.4,
 2  z  1
 7.2z 2  7.2z  19.1,
1  z  0
9
8.5
8
7.5
xs  range xdesired
http://numericalmethods.eng.usf.edu
7
Solution (contd)
At z = −7.5
T (7.5)  3.1(7.5) 2  52.4(7.5)  232.5
 13.875 C
The absolute relative approximate error a obtained
between the results from the linear and quadratic splines is
a 
13.875 14.65
 100
13.875
 5.5856 %
24
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