0% found this document useful (0 votes)
9 views5 pages

spline

The document discusses spline functions, defining them as piecewise polynomial functions that are continuous up to a certain degree. It focuses on linear and cubic splines, detailing algorithms for interpolation using these splines, including methods for evaluating and constructing natural cubic splines. The document also outlines the necessary conditions and algorithms for solving spline equations and provides MATLAB tools for spline operations.

Uploaded by

SAKET SAURABH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

spline

The document discusses spline functions, defining them as piecewise polynomial functions that are continuous up to a certain degree. It focuses on linear and cubic splines, detailing algorithms for interpolation using these splines, including methods for evaluating and constructing natural cubic splines. The document also outlines the necessary conditions and algorithms for solving spline equations and provides MATLAB tools for spline operations.

Uploaded by

SAKET SAURABH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Approximation By Spline Functions

Def. A function S is called a spline of degree k if

• The domain of S is an interval [a, b].

• S, S 0 , . . . S (k−1) are continuous on [a, b].

• There are points ti (the knots of S) such that a = t0 < t1 < · · · < tn = b and such
that S is a polynomial of degree at most k on each [ti , ti+1 ].

When k = 1, the splines are called linear splines, when k = 2, the splines are called
quadratic splines, when k = 3, the splines are called cubic splines. Here we are mainly
interested in linear splines and cubic splines.
Interpolation by Linear Splines
Problem: Given n + 1 points (t0 , y0 ), (t1 , y1 ),. . . ,(tn , yn ), where without loss of generality
we assume t0 < t1 < · · · < tn . Seek a linear spline S(x) such that S(ti ) = yi for 0 ≤ i ≤ n
and ti are the knots of S(x).
Obviously we can write


 S0 (x), t0 ≤ x ≤ t1
 S1 (x), t1 ≤ x ≤ t2

S(x) = ..


 .
 S (x), t
n−1 n−1 ≤x≤t n

where Si (x) = yi + mi (x − ti ), ti ≤ x ≤ ti+1 , with slope mi = (yi+1 − yi )/(ti+1 − ti ). So


S(x) is a piecewise linear polynomial.
Algorithm for evaluating S(x) (given x, ti , yi and mi , i = 0, 1, . . . , n):

for i = 0 : n − 1
if x − ti+1 ≤ 0,
exit loop
end
end
S ← yi + mi (x − ti )

Remarks:

• When x < t0 , the algorithm gives S = y0 + m0 (x − t0 ); when x > tn , it gives


S = yn−1 + mn−1 (x − tn−1 ).

• A binary search can be used to find the desired interval which consists of x. Averagely,
this is more efficient.

1
Interpolation by Cubic Splines
For a linear spline, generally S 0 is not continuous, so its graph lacks of smoothness. For
a quadratic spline, generally S 00 is not continuous, so the curvature of its graph changes
abruptly at each knot. So in practice, the most frequently used splines are cubic splines.
Problem: Given n + 1 points (t0 , y0 ), (t1 , y1 ),. . . ,(tn , yn ), where without loss of generality
we assume t0 < t1 < · · · < tn . Seek a cubic spline S(x) such that S(ti ) = yi for 0 ≤ i ≤ n
and ti are the knots of S(x).
Obviously we can write


 S0 (x), t0 ≤ x ≤ t1
 S1 (x), t1 ≤ x ≤ t2

S(x) = ..


 .
n−1 ≤ x ≤ tn
 S (x), t
n−1

were Si is a cubic polynomial on [ti , ti+1 ].


Number of unknowns:
Each Si has 4 unknowns. So there are a total of 4n unknowns.
Number of conditions:
(k) (k)
S(ti ) = yi for i = 0, 1, . . . , n result in n + 1 conditions. Si−1 (ti ) = Si (ti ) for k = 0, 1, 2
and i = 1, . . . n − 1 lead to 3(n − 1) conditions. So there are a total of 4n − 2 conditions.
In order to get a unique solution, we need 2 more extra conditions. Here we impose the
following two conditions:
S 00 (t0 ) = S 00 (tn ) = 0.
The resulting spline function is called a natural cubic spline.
Constructing a Natural Cubic Spline
Let zi = S 00 (ti ) (0 ≤ i ≤ n). On [ti , ti+1 ], Si00 (x) is a linear polynomial and Si00 (ti ) = zi and
Si00 (ti+1 ) = zi+1 . So we can write
x − ti+1 x − ti
Si00 (x) = zi + zi+1 .
ti − ti+1 ti+1 − ti

Integrating Si00 (x) twice, we obtain


zi zi+1
Si (x) = (ti+1 − x)3 + (x − ti )3 + cx + d, (1)
6hi 6hi
where hi ≡ ti+1 − ti , and c and d are constants of integration. We impose the conditions
Si (ti ) = yi and Si (ti+1 ) = yi+1 . Then we have
zi
h3i + cti + d = yi ,
6hi
zi+1
h3i + cti+1 + d = yi+1 ,
6hi

2
This gives

c = (yi+1 − yi )/hi − hi (zi+1 − zi )/6


d = (yi ti+1 − yi+1 ti )/hi + hi (ti zi+1 − ti+1 zi )/6.

Now we have to determine the zi and zi+1 in Si (x). In order to do this, we impose conditions
0
Si−1 (ti ) = Si0 (ti ). From eqn (1) we obtain

Si0 (x) = −(ti+1 − x)2 zi /(2hi ) + (x − ti )2 zi+1 /(2hi )


+(yi+1 − yi )/hi − (zi+1 − zi )hi /6

So
1 1
Si0 (ti ) = − hi zi − hi zi+1 + bi .
3 6
Analogously we can derive

0 1 1
Si−1 (ti ) = hi−1 zi−1 + hi−1 zi + bi−1 .
6 3
0
Thus Si−1 (ti ) = Si0 (ti ) leads to

hi−1 zi−1 + 2(hi−1 + hi )zi + hi zi+1 = 6(bi − bi−1 ),


i = 1, 2, . . . , n − 1.

Notice z0 = zn = 0. So we have the following tridiagonal system


    
2(h0 + h1 ) h1 z1 6(b1 − b0 )
 h1 2(h1 + h2 ) h2   z2   6(b2 − b1 ) 
    

 • • •  •  = 
   • 

 • • •   •   • 
hn−2 2(hn−2 + hn−1 ) zn−1 6(bn−1 − bn−2 )

Note that the matrix is strictly diagonally dominant by columns. So this can be reliably
solved by GENP.

3
Algorithm for finding zi , i = 0, . . . , n (given ti , yi , i = 0, . . . , n):

for i = 0 : n − 1
hi ← ti+1 − ti
bi ← (yi+1 − yi )/hi
end
% Forward elimination
u1 ← 2(h0 + h1 )
v1 ← 6(b1 − b0 )
for i = 2 : n − 1
ui ← 2(hi−1 + hi ) − h2i−1 /ui−1
vi ← 6(bi − bi−1 ) − hi−1 vi−1 /ui−1
end
% Back substitution
zn ← 0
for i = n − 1 : −1 : 1
zi ← (vi − hi zi+1 )/ui
end
z0 ← 0

Evaluation of S(x)
 
zi
3 3 zi+1 yi+1 − yi hi
Si (x) = (ti+1 − x) + (x − ti ) + − (zi+1 − zi ) x
6hi 6hi hi 6
yi ti+1 − yi+1 ti hi
+ + (ti zi+1 − ti+1 zi ).
hi 6
This is not the best computational form. As we want to utilize nested multiplication, we
write
Si (x) = Ai + Bi (x − ti ) + Ci (x − ti )2 + Di (x − ti )3 .
000
Notice Ai = Si (ti ), Bi = Si0 (ti ), Ci = 21 Si00 (ti ), Di = 16 Si (ti ). Then we can obtain

Ai = yi
Bi = −hi zi+1 /6 − hi zi /3 + (yi+1 − yi )/hi
Ci = zi /2
Di = (zi+1 − zi )/(6hi )

Si (x) = Ai + (x − ti )(Bi + (x − ti )(ci + (x − ti )Di )).

4
Algorithm for evaluating S(x) (given x, ti , yi and zi for i = 0, 1, . . . , n):

for i = 0 : n − 1
if x − ti+1 ≤ 0
exit loop
end
end
h ← ti+1 − ti
B ← −hzi+1 /6 − hzi /3 + (yi+1 − yi )/h
D ← (zi+1 − zi )/(6h)
S ← yi + (x − ti )(B + (x − ti )(zi /2 + (x − ti )D))

Note. You can use a binary search to find the desired interval consisting of x.

MATLAB Spline Tools: spline

You might also like