spline
spline
• 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
for i = 0 : n − 1
if x − ti+1 ≤ 0,
exit loop
end
end
S ← yi + mi (x − ti )
Remarks:
• 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
2
This gives
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
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
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 )
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.