Overview: Interpolation and Approximation
Many functions in this chapter produce cubic piecewise polynomial or general spline functions that either interpolate or approximate given data or are support functions for the evaluation and integration of these functions. Three major subdivisions of functions are provided. The cubic spline functions begin with the prefix CS and use the piecewise polynomial representation. The spline functions begin with the prefix BS and use the B-spline representation. The third major subdivision includes functions that operate on the output of both the cubic spline and B-spline functions. Most spline functions are based on routines documented by de Boor (1978).
General purpose routines also are provided for general least-squares fit to data and routines to interpolate or approximate scattered data in Rn for n ≥ 1.
Piecewise Polynomials
A univariate piecewise polynomial function, p, is specified by giving its breakpoint sequence
, the order k (degree k – 1) of its polynomial pieces, and the k x (n – 1) matrix C of its local polynomial coefficients. In terms of this information, the piecewise polynomial (ppoly) function is given by the following equation:

The breakpoint sequence ξ is assumed to be strictly increasing, and the ppoly function is extended to the entire real axis by extrapolation from the first and last intervals. This representation is redundant when the ppoly function is known to be smooth. For example, if p is known to be continuous, then c1, i+1 can be computed from the cji as follows:

For smooth ppoly, the nonredundant representation is used in terms of the "basis" or B-splines, at least when such a function is first to be determined.
Splines and B-splines
B-splines provide a particularly convenient and suitable basis for a given class of smooth ppoly functions. Such a class is specified by giving its breakpoint sequence, its order k, and the required smoothness across each of the interior breakpoints. The corresponding B-spline basis is specified by giving its knot sequence
. The specification rule is the following: If the class is to have all derivatives up to and including the j-th derivative continuous across the interior breakpoint ξi, then the number ξi should occur k – j – 1 times in the knot sequence. Assuming that ξ1 and ξn are the endpoints of the interval of interest, choose the first k knots equal to ξ1 and the last k knots equal to ξn. This can be done since the B-splines are defined to be right continuous near ξ1 and left continuous near ξn.
When the above construction is completed, a knot sequence t of length M is generated and m: = M – k B-splines of order k (for example, B0, ..., Bm – 1) span the ppoly functions on the interval with the indicated smoothness. That is, each ppoly function in this class has a unique representation:
as a linear combination of B-splines. A B-spline is a particularly compact ppoly function. The function Bi is a nonnegative function that is nonzero only on the interval [ti, ti + k ]. More precisely, the support of the i-th B-spline is [ti, ti + k ]. No ppoly function in the same class (other than the zero function) has smaller support (i.e., vanishes on more intervals) than a B-spline. This makes B-splines particularly attractive basis functions since the influence of any particular B-spline coefficient extends only over a few intervals. When it is necessary to emphasize the dependence of the B-spline on its parameters, the notation:
Bi, k, t
is used to denote the i-th B-spline of order k for the knot sequence t.
Cubic Splines
Cubic splines are smooth (i.e., C1 or C2), fourth-order ppoly functions. For historical and other reasons, cubic splines are the most frequently used ppoly functions. Therefore, special functions are provided for their construction and evaluation. These routines use the ppoly representation as described above for general ppoly functions (with k = 4).
Two cubic spline interpolation functions, IMSL_CSINTERP and IMSL_CSSHAPE, are provided. The IMSL_CSINTERP function allows the user to specify various endpoint conditions (such as the value of the first or second derivative at the right and left points). This means that the natural cubic spline can be obtained using this function by setting the second derivative to zero at both endpoints. The IMSL_CSSHAPE function is designed so that the shape of the curve matches the shape of the data. In particular, one option of this function preserves the convexity of the data while the default attempts to minimize oscillations.
It is possible that the cubic spline interpolation functions will produce unsatisfactory results. For example, the interpolant may not have the shape required by the user, or the data may be noisy and require a least-squares fit. The IMSL_BSINTERP interpolation function is more flexible, as it allows the user to choose the knots and order of the spline interpolant. The user is encouraged to use this routine and exploit the flexibility provided.
Tensor-product Splines
The simplest method of obtaining multivariate interpolation and approximation functions is to take univariate methods and form a multivariate method via tensor products. In the case of two-dimensional spline interpolation, the derivation proceeds as follows: Let tx be a knot sequence for splines of order kx and ty be a knot sequence for splines of order ky. Let Nx + kx be the length of tx and Ny + ky be the length of ty. Then, the tensor-product spline has the following form:

Given two sets of points:
and
for which the corresponding univariate interpolation problem can be solved, the tensor-product interpolation problem finds the coefficients cnm, so that the following is true:

This problem can be solved efficiently by repeatedly solving univariate interpolation problems as described in de Boor (1978, p. 347). Three-dimensional interpolation can be handled in an analogous manner. This chapter provides functions that compute the two-dimensional, tensor-product spline coefficients given two-dimensional interpolation data (IMSL_BSINTERP) and functions that compute the two-dimensional, tensor-product spline coefficients for a tensor-product, least-squares problem (IMSL_BSLSQ). In addition, evaluation, differentiation, and integration routines (IMSL_SPVALUE and IMSL_SPINTEG) are provided for the two-dimensional, tensor-product spline functions.
Scattered-data Interpolation and Approximation
IDL Advanced Math and Stats provides functions to interpolate and approximate scattered data in Rn for n ≥ 1. The IMSL_SCAT2DINTERP function interpolates scattered data in the plane and is based on work by Akima (1978), which uses C1 piecewise quintics on a triangular mesh. The IMSL_RADBF function can be used to either interpolate or approximate scattered data in Rn for n ≥ 1. The IMSL_RADBF function computes approximations based on radial-basis functions. The fit computed by IMSL_RADBF can be evaluated using the IMSL_RADBE function.
Least Squares
IDL Advanced Math and Stats includes functions for smoothing noisy data. The IMSL_FCNLSQ function computes regressions with user-supplied functions. The IMSL_BSLSQ function computes a one- or two-dimensional, least-squares fit using splines with fixed knots or variable knots. This function produces cubic-spline, least-squares fit by default. Keywords allow the user to choose the order and the knot sequence.
IDL Advanced Math and Stats contains many functions that provide for polynomial regression and general linear regression.
Smoothing by Cubic Splines
One "smoothing spline" function is provided. The default action of IMSL_CSSMOOTH estimates a smoothing parameter by cross-validation, then returns the cubic spline that smooths the data. If the user chooses to supply a smoothing parameter, this function returns the appropriate cubic spline.
Structures for Splines and Piecewise Polynomials
This section is optional and is intended for users interested in more details concerning the structures for splines and piecewise polynomials.
A spline can be viewed as a mapping with domain Rd and target Rr, where d and r are positive integers. For this version of the IDL Advanced Math and Stats module, only r = 1 is supported. Thus, if s is a spline, then the following is true for some d and r:
This implies that such a spline s must have d knot sequences and orders (one for each domain dimension). Thus, associated with s, knots and orders are as follows:
t0, ..., td – 1
k0, ..., kd – 1
The precise form of the spline follows:
s(x) = (s0(x), ..., sr – 1(x))
where:

Note that ni is the number of knots in ti minus the order ki.
All the information for a spline is stored in a structure. Since the components of this structure are generally of varying lengths, an anonymous structure is defined for each spline. An example of the information returned by the HELP command with the keyword STRUCTURES set and an argument containing a spline structure follows:
x = FINDGEN(10) y = IMSL_RANDOM(10) spline = IMSL_BSINTERP(x, y) HELP, spline, /Structure ** Structure $1, 7 tags, 116 length: DOMAIN_DIM LONG 1 TARGET_DIM LONG 1 ORDER LONG 4 NUM_COEF LONG 10 NUM_KNOTS LONG 14 KNOTS FLOAT Array(14) COEF FLOAT Array(10)
For ppoly functions, a ppoly is viewed as a mapping with domain Rd and target Rr, where d and r are positive integers. Thus, if p is a ppoly, then the following is true for some d and r:
For this version of the IDL Advanced Math and Stats module, only r = 1 is supported. This implies that such a ppoly p must have d breakpoint sequences and orders (one for each domain dimension). Thus, associated with p, breakpoints and orders are as follows:
ξ1, ..., ξd
k1, ..., kd
The precise form of the ppoly follows:
p(x) = (p0(x), ..., pr(x)) ![]()
where:

with:
L j :=max {1, min{M j, nj – 1}}
where M j is chosen so that:

(with
and
).
Note that nj is the number of breakpoints in ξ j.
All the information for a spline is stored in a structure. Since the components of this structure are generally of varying lengths, an anonymous structure is defined for each spline. An example of the information returned by the HELP command with the keyword STRUCTURES set and an argument containing a spline structure is as follows:
x = FINDGEN(10) y = IMSL_RANDOM(10) ppoly = IMSL_CSINTERP(x, y) HELP, ppoly, /Structure Structure <103bc00>, 7 tags, length=204, data length=204, refs=1: DOMAIN_DIM LONG 1 TARGET_DIM LONG 1 ORDER LONG Array[1] NUM_COEF LONG Array[1] NUM_BREAKPOINTS LONG Array[1] BREAKPOINTS FLOAT Array[10] COEF FLOAT Array[36]