The IMSL_BSKNOTS function computes the knots for a spline interpolant.

Given the data points x = Xdata, the order of the spline k = ORDER, and the number n = N_ELEMENTS (Xdata) of elements in Xdata, the default action of IMSL_BSKNOTS returns a knot sequence that is appropriate for interpolation of data on x by splines of order k (the default order is k = 4). The knot sequence is contained in its n + k elements. If k is even and it is assumed that the entries in the input vector x are increasing, then the resulting knot sequence t is returned as follows:

ti = x0 for  i = 0, ..., k – 1

ti = xi – k/2 – 1 for  i = k, ..., n – 1 (1)

ti = xn – 1 for  i = n, ..., n + k – 1

There is some discussion concerning this selection of knots in de Boor (1978, p. 211). If k is odd, then t is returned as follows: It is not necessary to sort the values in Xdata.

If keyword OPTIMUM is set, then the knot sequence returned minimizes the constant c in the error estimate:

|| f – s || ≤ c || f (k) ||

where f  is any function in Ck and s is the spline interpolant to f at the abscissa x with knot sequence t.

The algorithm is based on a routine described by de Boor (1978, p. 204), which in turn is based on a theorem of Micchelli et al. (1976).

## Examples

### Example 1

In this example, knots for a cubic spline are generated and printed. Notice that the knots are stacked at the endpoints; also, the second and next-to-last data points are not knots.

`x = FINDGEN(6)`
`knots = IMSL_BSKNOTS(x)`
`PM, knots, FORMAT = '(f5.2)'`

IDL prints:

`   0.00`
`   0.00`
`   0.00`
`   0.00`
`   2.00`
`   3.00`
`   5.00`
`   5.00`
`   5.00`
`   5.00`

### Example 2

This example compares the default knots with the knots returned using keyword OPTIMIZE as shown in the figure that follows. The order is changed from the default value of 4 to 3.

`x = FINDGEN(11)/10`
`; Define the abscissa values. f = FLTARR(11)`
`; Define the function values. f(0:3) = .25`
`f(4:7) = .5`
`f(8:10) = .25`
`sp1 = IMSL_BSINTERP(x, f)`
`; Compute the default spline.`
`knots2 = IMSL_BSKNOTS(x, /OPTIMUM, ORDER = 3)`
`; Compute the optimum knots of order 3.`
`sp2 = IMSL_BSINTERP(x, f, XKNOTS = knots2, XORDER = 3)`
`; Compute the spline of order 3, with the optimum knots.`
`x2 = FINDGEN(100)/99`
`; Evaluate the two splines for plotting.`
`sp1eval = IMSL_SPVALUE(x2, sp1) `
`sp2eval = IMSL_SPVALUE(x2, sp2) `
`PLOT, x2, sp1eval, Linestyle = 2`
`; Plot the results. OPLOT, x2, sp2eval`
`OPLOT, x, f, PSYM = 6`
`XYOUTS, .25, .18, 'With optimum knots:', CHARSIZE = 1.5`
`OPLOT, [.65, .75], [.188, .188]`
`XYOUTS, .25, .135, 'With default knots:', CHARSIZE = 1.5`
`OPLOT, [.65, .75], [.143, .143], LINESTYLE = 2`
`XYOUTS, .3, .09, 'Original data', CHARSIZE = 1.5`
`OPLOT, [.70], [.098], PSYM = 6` ## Errors

### Warning Errors

MATH_NO_CONV_NEWTON: Newton’s method iteration did not converge.

### Fatal Errors

MATH_DUPLICATE_XDATA_VALUES: The xdata values must be distinct.

MATH_ILL_COND_LIN_SYS: Interpolation matrix is singular. The xdata values may be too close together.

## Syntax

Result = IMSL_BSKNOTS(Xdata [, /DOUBLE] [, ITMAX=value] [, ORDER=value] [, /OPTIMUM])

## Return Value

A one-dimensional array containing the computed knots.

## Arguments

### Xdata

One-dimensional array containing the abscissas of the interpolation problem.

## Keywords

### DOUBLE (optional)

If present and nonzero, then double precision is used.

### ITMAX (optional)

Integer value used to set the maximum number of iterations of Newton’s method. To use this keyword, the keyword OPTIMUM must also be set. Default: 10.

### ORDER (optional)

Order of the spline subspace for which the knots are desired. Default: 4, i.e., cubic splines.

### OPTIMUM (optional)

If present and nonzero, knots that satisfy an optimal criterion are computed.

## Version History

 6.4 Introduced