​spline_​auto, x, y, w, s, n, lamda, comm)[source]

dim1_spline_auto computes a cubic spline approximation to an arbitrary set of data points. The knots of the spline are located automatically, but a single argument must be specified to control the trade-off between closeness of fit and smoothness of fit.

For full information please refer to the NAG Library document for e02be

startstr, length 1

Must be set to ‘C’ or ‘W’.

The function will build up the knot set starting with no interior knots. No values need be assigned to the arguments , , [‘wrk’] or [‘iwrk’].

The function will restart the knot-placing strategy using the knots found in a previous call of the function. In this case, the arguments , , [‘wrk’], and [‘iwrk’] must be unchanged from that previous call. This warm start can save much time in searching for a satisfactory value of .

xfloat, array-like, shape

The values of the independent variable (abscissa) , for .

yfloat, array-like, shape

The values of the dependent variable (ordinate) , for .

wfloat, array-like, shape

The values of the weights, for . For advice on the choice of weights, see the E02 Introduction.


The smoothing factor, .

If , the function returns an interpolating spline.

If is smaller than machine precision, it is assumed equal to zero.

For advice on the choice of , see Notes and Further Comments.


If the warm start option is used, the value of must be left unchanged from the previous call.

lamdafloat, array-like, shape

If the warm start option is used, the values must be left unchanged from the previous call.

commdict, communication object, modified in place

Communication structure.

On initial entry: need not be set.


The total number, , of knots of the computed spline.

lamdafloat, ndarray, shape

The knots of the spline, i.e., the positions of the interior knots as well as the positions of the additional knots


needed for the B-spline representation.

cfloat, ndarray, shape

The coefficient of the B-spline in the spline approximation , for .


The sum of the squared weighted residuals, , of the computed spline approximation. If , this is an interpolating spline. should equal within a relative tolerance of unless when the spline has no interior knots and so is simply a cubic polynomial. For knots to be inserted, must be set to a value below the value of produced in this case.

(errno )

On entry, and .

Constraint: for all .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: when .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, or : .

(errno )

On entry, and .

Constraint: for all .

(errno )

On entry, , and .

Constraint: for all .

(errno )

The number of knots needed is greater than : . Possibly is too small: .

(errno )

The iterative process has failed to converge. Possibly is too small: .


In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.

dim1_spline_auto determines a smooth cubic spline approximation to the set of data points , with weights , for .

The spline is given in the B-spline representation

where denotes the normalized cubic B-spline defined upon the knots .

The total number of these knots and their values are chosen automatically by the function. The knots are the interior knots; they divide the approximation interval into sub-intervals. The coefficients are then determined as the solution of the following constrained minimization problem:


subject to the constraint


stands for the discontinuity jump in the third order derivative of at the interior knot ,

denotes the weighted residual ,


is a non-negative number to be specified by you.

The quantity can be seen as a measure of the (lack of) smoothness of , while closeness of fit is measured through . By means of the argument , ‘the smoothing factor’, you can then control the balance between these two (usually conflicting) properties. If is too large, the spline will be too smooth and signal will be lost (underfit); if is too small, the spline will pick up too much noise (overfit). In the extreme cases the function will return an interpolating spline if is set to zero, and the weighted least squares cubic polynomial if is set very large. Experimenting with values between these two extremes should result in a good compromise. (See Choice of S for advice on choice of .)

The method employed is outlined in Outline of Method Used and fully described in Dierckx (1975), Dierckx (1981) and Dierckx (1982). It involves an adaptive strategy for locating the knots of the cubic spline (depending on the function underlying the data and on the value of ), and an iterative method for solving the constrained minimization problem once the knots have been determined.

Values of the computed spline, or of its derivatives or definite integral, can subsequently be computed by calling dim1_spline_eval(), dim1_spline_deriv() or dim1_spline_integ(), as described in Evaluation of Computed Spline.


Dierckx, P, 1975, An algorithm for smoothing, differentiating and integration of experimental data using spline functions, J. Comput. Appl. Math. (1), 165–184

Dierckx, P, 1981, An improved algorithm for curve fitting with spline functions, Report TW54, Department of Computer Science, Katholieke Univerciteit Leuven

Dierckx, P, 1982, A fast algorithm for smoothing data on a rectangular grid while using spline functions, SIAM J. Numer. Anal. (19), 1286–1304

Reinsch, C H, 1967, Smoothing by spline functions, Numer. Math. (10), 177–183