Spline Interpolation Method
Spline Interpolation Method
Method
What is Interpolation ?
Given (x0,y0), (x1,y1), (xn,yn), find
the value of y at a value of x that is
not given.
http://numericalmethods.eng.usf.edu
Interpolants
Polynomials are the most common
choice of interpolants because
they are easy to:
Evaluate
Differentiate, and
Integrate.
Why Splines ?
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
0.038461
Why Splines ?
Linear Interpolation
Given x0 , y0 , x1 , y1 ,......, x n 1 , y n1 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
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 n1 x x n
x n x n 1
Example
The upward velocity of a rocket is given as a
function of time in Table 1. Find the velocity
at t=16 seconds using linear splines.
Table Velocity as a
function of time
t (s)
v(t ) (m/s)
0
10
15
20
22.5
30
0
227.04
362.78
517.35
602.97
901.67
Figure. Velocity vs. time data
for the rocket example
Linear Interpolation
t 0 15,
v (t 0 ) 362.78
t1 20,
v (t1 ) 517.35
v (t ) v(t 0 )
v(t 1 ) v (t 0 )
(t t 0 )
t1 t 0
362.78
517.35 362.78
(t 15)
20 15
517.35
550
500
ys
f ( range)
f x desired
450
400
At t 16,
v (16) 362.78 30.913(16 15)
393.7
362.78
350
10
12
x s 10
m/s
14
16
18
x s range x desired
20
22
24
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 ,
Find a i , bi , ci , i 1, 2, , n
10
x n 1 x x n
Quadratic Interpolation
(contd)
Each quadratic spline goes through two consecutive data points
2
a1 x 0 b1 x 0 c1 f ( x0 )
a1 x1 b1 x1 c1 f ( x1 )
2
.
.
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 n1 bn x n 1 c n f ( xn 1 )
2
a n x n bn xn cn f ( x n )
This condition gives 2n equations
11
2 a1 x b1
2 a2 x b2
12
13
x0 x x1
x1 x x 2
.
.
.
a n x 2 bn x c n ,
14
x n 1 x x n
t (s)
v(t ) (m/s)
0
10
15
20
22.5
30
0
227.04
362.78
517.35
602.97
901.67
Figure. Velocity vs. time data
for the rocket example
15
Solution
v(t ) a1t b1t c1 ,
2
0 t 10
a 2 t b2 t c 2 , 10 t 15
2
a3t b3t c3 , 15 t 20
2
a 4 t b4 t c 4 , 20 t 22.5
2
a5 t b5 t c5 ,
2
16
22.5 t 30
17
http://numericalmethods.eng.usf.edu
18
v(t)
m/s
10
227.04
15
362.78
20
517.35
22.5
602.97
30
901.67
d
2
a1t b1t c1
dt
t 10
d
2
a2t b2t c2
dt
2a1t b1 t 10 2a2t b2 t 10
2a1 10 b1 2a2 10 b2
20a1 b1 20a2 b2 0
19
t 10
At t=15
At t=20
At t=22.5
20
21
Coefficients of Spline
i
1
2
3
4
5
22
ai
bi
ci
0
22.704
0
0.8888
4.928 88.88
0.1356 35.66 141.6
1
1.6048 33.95 554.55
6
0.20889 28.86 152.1
3
Quadratic Spline
Interpolation
Part 2 of 2
23
v(t ) 22.704t ,
24
Final Solution
0 t 10
10 t 15
15 t 20
20 t 22.5
22.5 t 30
v(t ) 22.704t ,
10 t 15
15 t 20
20 t 22.5
22.5 t 30
25
t=a:2:b;
t=a:0.5:b;
29
30