Contents Previous Next Subchapters

Evaluate A Cubic Spline
Syntax cubeval(xdabcp)
See Also cubespl , interp , lagrange

Description
Evaluates the cubic spline defined by x, d, and abc at the points specified by p. If a, b, and c are the first, second, and third columns of the matrix abc, the cubic spline is defined as a function of z by
                      3              2
     f(z) = a (z - x )  +  b (z - x )  +  c (z - x )  +  d
             i      i       i      i       i      i       i
for all z between x(i) and x(i+1). The column vector x is real or double-precision and x(i) < x(i + 1) for all i. The vector d has the same type and dimension as x. The matrix abc has one fewer row than x, has three columns, and has the same type as x. The column vector p has the same type as x and specifies the values of z at which to evaluate the cubic spline. The return value is a column vector with the same dimension as p, and its i-th element is the value of f(z) at z = p(i). The return value has the same type and dimension as p.

Example
The program below evaluates a cubic spline that is equal to
      3            3             2
     z  = 1 (z - 1)  +  3 (z - 1)  +  3 (z - 1) + 1
                                                  
                   3             2
        = 1 (z - 2)  +  6 (z - 2)  + 12 (z - 2) + 8
        
at the points 1.5 and 2.5. The corresponding value are their cubes namely 3.375 and 15.625.

clear
#
x    = {1., 2., 3.}
d    = {1., 8., 27.}
a    = {1., 1.}
b    = {3., 6.}
c    = {3., 12.}
abc  = [a, b, c]
p    = {1.5, 2.5}
cubeval(x, d, abc, p)