Applied Mathematics and Computation 117 (2001) 251±255 www.elsevier.com/locate/amc
An explicit solution for the cubic spline interpolation for functions of a single variable B.S. Moon Korea Atomic Energy Research Institute, P.O. Box 105, Yusong, Taejon 305-600, South Korea
Abstract An algorithm for computing the cubic spline interpolation coecients without solving the matrix equation involved is presented in this paper. It requires only O
n multiplication or division operations for computing the inverse of the matrix compared to O
n2 or larger number of operations in the Gauss elimination method. Ó 2001 Elsevier Science Inc. All rights reserved. Keywords: Explicit solution; Cubic spline interpolation; B-splines; Inverse matrix
1. Introduction Consider the problem of ®nding one-dimensional approximates on equally spaced points ti of the interval a; b with functions S
t c1 B1
t c2 B2
t cn Bn
t;
a 6 t 6 b;
1
where Bj
t's are the cubic B-spline functions [1] de®ned on tiÿ2 ; ti2 by 8 3
t ÿ tiÿ2 if t 2 tiÿ2 ; tiÿ1 > > > 3 2 3 2 > 3h
t ÿ t 3h
t ÿ t ÿ 3
t ÿ t if t 2 tiÿ1 ; ti h < iÿ1 iÿ1 iÿ1 1 Bi
t 2 h3 3h2
ti1 ÿ t 3h
ti1 ÿ t2 ÿ 3
ti1 ÿ t3 if t 2 ti ; ti1 > 6h > 3 > if t 2 ti1 ; ti2 > :
ti2 ÿ t 0; otherwise
2 for i 1; 2; . . . ; n with h
b ÿ a=
n ÿ 3, ti a
i ÿ 1h. E-mail address:
[email protected] (B.S. Moon). 0096-3003/01/$ - see front matter Ó 2001 Elsevier Science Inc. All rights reserved. PII: S 0 0 9 6 - 3 0 0 3 ( 9 9 ) 0 0 1 7 8 - 2
252
B.S. Moon / Appl. Math. Comput. 117 (2001) 251±255
Given a set of
n ÿ 2 points f
ti ; yi j i 1; 2; . . . ; n ÿ 2g and the derivatives y 0
a and y 0
b at the two end points, it is desired to ®nd ci 's for i 1; 2; . . . ; n such that S 0
a y 0
a, S 0
b y 0
b, and S
ti yi for i 1; 2; . . . ; n ÿ 2. This comprises a set of n linear equations Ac b, where c
c1 ; c2 ; . . . ; cn T , b
y 0
a; y1 ; y2 ; . . . ; ynÿ2 ; y 0
bT , and the coecient matrix A of size n n is given by 3 2 ÿ3=h 0 3=h 0 0 0 : : 6 1 4 1 0 0 0 : :7 7 6 6 0 1 4 1 0 0 : :7 7 6 6 0 0 1 4 1 0 : :7 7: 6
3 A6 : : : : : : : :7 7 6 6 0 0 0 0 0 1 4 17 7 6 4 1 4 1 0 0 ÿ3=h 0 3=h 5 When the derivative constraints are deleted, i.e. the ®rst and the last rows of A are left out, there is an easy and fast inversion algorithm [2]. In the following, we describe an algorithm to compute the inverse of A with the two rows included.
2. An algorithm for computing the inverse In this section, we describe an algorithm to compute the inverse of the n n matrix A in (3). Note that if we multiply the ®rst and the last rows by ÿh=3, compute the inverse of the resulting matrix, and multiply the ®rst and the last columns of the computed inverse by ÿ3=h, then we would obtain the desired inverse. Thus, we assume that the ®rst row of A is replaced by
1; 0; ÿ1; 0; . . . ; 0 and the last row by
0; 0; . . . ; 1; 0; ÿ1. To compute the inverse of the revised matrix A, ®rst we de®ne a sequence of numbers bj 's by b1 2; b2 4; bj2 4bj1 ÿ bj
4
for j 1; 2; . . . ; n ÿ 2. Next, we compute a matrix B
bij by b11 bnÿ1 ;
b12 ÿbnÿ3 ;
b1j
ÿ1j1
bnÿj1 bjnÿjÿ2j1 ; b1;nÿ1 b1;n
ÿ1n b2 and for i 2; 3; . . . ; n ÿ 1;
j 3; 4; . . . ; n ÿ 2;
5
B.S. Moon / Appl. Math. Comput. 117 (2001) 251±255
bi1
ÿ1i1 bnÿi ;
253
bi2
ÿ1i2 bnÿi ;
ij
bij
ÿ1
bnÿjiÿjjÿ2 bjnÿiÿj1j1 ;
j 3; 4; . . . ; n ÿ 2;
6
bi;nÿ1 bi;n
ÿ1niÿ1 biÿ1 and for i n, bn;1
ÿ1n1 b2 ;
bn;2
ÿ1n2 b2 ;
bn;j
ÿ1nj
bj bjÿ2 ; bn;nÿ1
ÿ1
2nÿ1
bnÿ3 ;
3 6 j 6 n ÿ 2;
bn;n
ÿ1
2nÿ1
7
bnÿ1 :
Note that the signs are alternating in rows and in columns except for the last column where the elements have the same sign as the corresponding adjacent elements in the
n ÿ 1th column. In the following, we will show that Aÿ1
1=dB where d 2
bnÿ1 ÿ 2bnÿ2 . To compute
1=dB, one can simply replace bj by b0j bj =d in (5)±(7) to obtain a matrix B0 which is the same as
1=dB. ÿ bjÿ2 for j P 2 Lemma 1. The solution for the difference equation p jÿ1 bj 4bpjÿ1 jÿ1 for j 1; 2; with b1 2; b2 4 is given as bj
2 3
2 ÿ 3 . . . ; n. Proof. The characteristic equation for the p above dierence p equation is z2 ÿ 4z 1 0 whose solutions are z 2 3 and z 2 ÿ 3. Therefore, the solution of the dierence equation is p p bj c1
2 3jÿ1 c2
2 ÿ 3jÿ1 : By substituting b1 2 and b2 4 into the above relation, we obtain c1 c2 1. p jÿ1 p jÿ1 Lemma 2. If bj
2 3
2 ÿ 3 for j 1; 2; . . . ; n, then bj 's satisfy bk bl bklÿ1 bjkÿlj1 . A routine trivial proof of the above is omitted. Note that the relation in the middle of (6) can be written as (
ÿ1ij bnÿj biÿ1 for i 6 j < n ÿ 2;
6a bi;j
ÿ1ij bnÿi bjÿ1 for j 6 i < n ÿ 1: Lemma 3. Let d and bj 's be as defined above. Then bj 's, 3 6 j 6 n ÿ 3 satisfy bnÿj bjÿ2 ÿ 4bnÿj bjÿ1 bnÿjÿ1 bjÿ1 d:
254
B.S. Moon / Appl. Math. Comput. 117 (2001) 251±255
Proof. The left-hand side is equal to bnÿj
bjÿ2 ÿ 4bjÿ1 bnÿjÿ1 bjÿ1 which is equal to ÿbnÿj bj bnÿjÿ1 bjÿ1 . Therefore, it is equivalent to prove ÿbnÿj bj bnÿjÿ1 bjÿ1 d for 2 6 j 6 n ÿ 3. For j 2, the left-hand side is equal to ÿ4bnÿ2 2bnÿ3 ÿ4bnÿ2 2
bnÿ1 ÿ 4bnÿ2 d; which is the right-hand side. Assume that the relation is true for all j with j 6 r < n ÿ 3, then for j r 1, the left-hand side is ÿbr1 bnÿ
r1 br bnÿrÿ2 ÿ
4br ÿ brÿ1 bnÿrÿ1 br bnÿrÿ2 ÿbr
4bnÿrÿ1 ÿ bnÿrÿ2 brÿ1 bnÿrÿ1 ÿbr bnÿr brÿ1 bnÿrÿ1 ; which is equal to d by induction hypothesis.
Theorem 1. Let B
bij where bij 's are as defined above. Then
1=dB is the inverse of A, i.e. BA dI where I being the identity matrix. Proof. Let C
cij be the product matrix BA. We are to show C dB. For elements in the ®rst row of C with 3 < j 6 n ÿ 2, we have c1;j b1;jÿ1 4b1;j b1;j1
ÿ1j
bnÿj2 bnÿj ÿ 4bnÿj1 ÿ 4bnÿjÿ1 bnÿj bnÿjÿ2
ÿ1j
bnÿj2 ÿ 4bnÿj1 bnÿj
ÿ1j
bnÿj ÿ 4bnÿjÿ1 bnÿjÿ2 0: For those elements satisfying 3 < i < j < n ÿ 2, we use (6a) to write ci;j bi;jÿ1 4bi;j bi;j1
ÿ1
ijÿ1
biÿ1
bnÿj1 ÿ 4bnÿj bnÿjÿ1 0:
Similarly, for elements satisfying 3 < j < i < n ÿ 1, we have ci;j bi;jÿ1 4bi;j bi;j1
ÿ1
ijÿ1
bnÿ1
bjÿ2 ÿ 4bjÿ1 bj 0
and for the diagonal elements with 3 < j < n ÿ 2, cj;j bj;jÿ1 4bj;j bj;j1
ÿ1
2jÿ1
bnÿj bjÿ2 ÿ 4bnÿj bjÿ1 bnÿjÿ1 bjÿ1 d:
A routine check for the rest of the elements is omitted.
3. Conclusion In the above, we showed that for computing the inverse of the matrix, we need to compute bj 's by using (4) which requires at most n multiplications and another n multiplications to compute b0j b=d. The matrix B is formed using b0j
B.S. Moon / Appl. Math. Comput. 117 (2001) 251±255
255
without any multiplication or division operation. To adjust the ®rst and the last columns by the factor ÿ3=h, we need another 2n multiplications. Thus, we need altogether 4n multiplications at most to compute the inverse. The algorithm is tested with an example of n 67, we found that kAB ÿ Ik1 0:22 10ÿ15 for both the Gauss elimination method and the proposed method. References [1] P.M. Prenter, Splines and Variational Methods, Wiley, New York, 1975, pp. 78±81. [2] F. Yamaguchi, A new curve ®tting method using a CRT computer display, Computer Graphics and Image Processing 7 (1978) 425±437.