Contents Previous Next Subchapters

Compute Cubic Spline Coefficients
Syntax cubespl(xdb1bn)
See Also cubeval , interp , lagrange

Description
Returns a matrix, with one less row than x and three columns, that defines a cubic spline through the data pairs (x(i), d(i)).

Let a, b, and c, be the first, second, and third columns of the return value. If z is between x(i) and x(i + 1), the cubic spline's value at z is equal to
               3              2
     a (z - x )  +  b (z - x )  +  c (z - x )  +  d
      i      i       i      i       i      i       i
The column vector x must be either real or double-precision and x(i) < x(i+1) for all i. The vector d must have the same type and dimension as x. The scalars b1 and bn must have the same type as x. The second derivative of the spline at x(1) b1 and at x(n) is bn, where n is the row dimension of x.

The return value has the same type as x.

Example
The following program fits a cubic spline though the function
      3            3             2
     z  = 1 (z - 1)  +  3 (z - 1)  +  3 (z - 1) + d
                                                   1
                   3             2
        = 1 (z - 2)  +  6 (z - 2)  + 12 (z - 2) + d
                                                   2
Note that the second derivative of this function is z. It follows from the equalities above that, the values of a, b, and c, are 1, 3, 3 in the first interval and 1, 6, 12 in the second interval.

clear
#
x   = {1., 2., 3.}
d   = x^3
b1  = 6 * x(1) / 2
bn  = 6 * x(3) / 2
cubespl(x, d, b1, bn)