|
NAG[e02bac] NAG[nag_1d_spline_fit_knots] - Least-squares curve cubic spline fit (including interpolation), one variable
|
|
Calling Sequence
e02bac(x, y, weights, ss, spline_data, 'm'=m, 'fail'=fail)
nag_1d_spline_fit_knots(. . .)
Parameters
|
x - Vector(1..m, datatype=float[8]);
|
|
|
On entry: the values of the independent variable (abscissa), for .
|
|
Constraint: . .
|
|
|
y - Vector(1..m, datatype=float[8]);
|
|
|
On entry: the values of the of the dependent variable (ordinate), for .
|
|
|
weights - Vector(1..m, datatype=float[8]);
|
|
|
On entry: the values of the weights, for . For advice on the choice of weights, see the the e02 Chapter Introduction.
|
|
Constraint: , for . .
|
|
|
ss - assignable;
|
|
|
Note: On exit the variable ss will have a value of type float.
|
|
On exit: the residual sum of squares, .
|
|
|
spline_data - table;
|
|
|
A Maple table, which should be generated using NAG[Nag_Spline], corresponding to the Nag_Spline structure.
|
|
Constraint: . .
|
|
|
'm'=m - integer; (optional)
|
|
|
Default value: the first dimension of the arrays x, y, weights.
|
|
On entry: the number of data points.
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_1d_spline_fit_knots (e02bac) computes a weighted least-squares approximation to an arbitrary set of data points by a cubic spline with knots prescribed by the user. Cubic spline interpolation can also be carried out.
|
|
Description
|
|
nag_1d_spline_fit_knots (e02bac) determines a least-squares cubic spline approximation to the set of data points with weights , for . The value of , where is the number of intervals of the spline (one greater than the number of interior knots), and the values of the knots , interior to the data interval, are prescribed by the user.
has the property that it minimizes , the sum of squares of the weighted residuals , for , where
The function produces this minimizing value of and the coefficients , where , in the B-spline representation
Here denotes the normalized B-spline of degree 3 defined upon the knots .
In order to define the full set of B-splines required, eight additional knots and , are inserted automatically by the function. The first four of these are set equal to the smallest and the last four to the largest .
The representation of in terms of B-splines is the most compact form possible in that only coefficients, in addition to the knots, fully define .
The method employed involves forming and then computing the least-squares solution of a set of linear equations in the coefficients . The equations are formed using a recurrence relation for B-splines that is unconditionally stable (Cox (1972a), De Boor (1972)), even for multiple (coincident) knots. The least-squares solution is also obtained in a stable manner by using orthogonal transformations, viz. a variant of Givens rotations (Gentleman (1974) and Gentleman (1973)). This requires only one equation to be stored at a time. Full advantage is taken of the structure of the equations, there being at most four non-zero values of for any value of and hence at most four coefficients in each equation.
For further details of the algorithm and its use see Cox (1974), Cox (1975b) and Cox and Hayes (1973).
Subsequent evaluation of from its B-spline representation may be carried out using e02bbc (nag_1d_spline_evaluate). If derivatives of are also required, e02bcc (nag_1d_spline_deriv) may be used. e02bdc (nag_1d_spline_intg) can be used to compute the definite integral of .
|
|
Error Indicators and Warnings
|
|
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_INT_ARG_LT"
On entry, n must not be less than 8: .
"NE_KNOTS_DISTINCT_ABSCI_CONS"
Too many knots for the number of distinct abscissae, : , . These must satisfy the constraint .
"NE_KNOTS_OUTSIDE_DATA_INTVL"
On entry, user-specified knots must be interior to the data interval, must be greater than and must be less than : , , , .
"NE_NOT_INCREASING"
The sequence lamda is not increasing: , . This condition on lamda applies to user-specified knots in the interval , . The sequence x is not increasing: , .
"NE_SW_COND_FAIL"
The conditions specified by Schoenberg and Whitney fail. The conditions specified by Schoenberg and Whitney (1953) fail to hold for at least one subset of the distinct data abscissae. That is, there is no subset of strictly increasing values, , , among the abscissae such that
|
,
|
|
,
|
|
.
|
This means that there is no unique solution: there are regions containing too many knots compared with the number of data points.
"NE_WEIGHTS_NOT_POSITIVE"
On entry, the weights are not strictly positive: .
|
|
Further Comments
|
|
The time taken by nag_1d_spline_fit_knots (e02bac) is approximately seconds, where is a machine-dependent constant.
Multiple knots are permitted as long as their multiplicity does not exceed 4, i.e., the complete set of knots must satisfy , for , (see Section [Error Indicators and Warnings]). At a knot of multiplicity one (the usual case), and its first two derivatives are continuous. At a knot of multiplicity two, and its first derivative are continuous. At a knot of multiplicity three, is continuous, and at a knot of multiplicity four, is generally discontinuous.
The function can be used efficiently for cubic spline interpolation, i.e., if . The abscissae must then of course satisfy . Recommended values for the knots in this case are , for .
|
|
|
Examples
|
|
>
|
m := 14:
ncap,wght := 5, 2:
ncap7 := ncap + 7:
spline_data := NAG:-Nag_Spline():
spline_data['n'] := ncap7:
spline_data['lamda'] := Vector[row](ncap7,[0,0,0,0,1.5,2.6,4.0,8.0,0,0,0,0],datatype=float[8]):
x := Vector([0.2, 0.47, 0.74, 1.09, 1.6, 1.9, 2.6, 3.1, 4, 5.15, 6.17, 8, 10, 12], datatype=float[8]):
y := Vector([0, 2, 4, 6, 8, 8.619999999999999, 9.1, 8.9, 8.15, 7, 6, 4.54, 3.39, 2.56], datatype=float[8]):
weights := Vector([0.2, 0.2, 0.3, 0.7, 0.9, 1, 1, 1, 0.8, 0.5, 0.7, 1, 1, 1], datatype=float[8]):
NAG:-e02bac(x, y, weights, ss, spline_data, 'm' = m):
|
|
|
See Also
|
|
Cox M G (1972a) The numerical evaluation of B-splines J. Inst. Math. Appl. 10 134–149
Cox M G (1974) A data-fitting package for the non-specialist user Software for Numerical Mathematics (ed D J Evans) Academic Press
Cox M G (1975b) Numerical methods for the interpolation and approximation of data by spline functions PhD Thesis City University, London
Cox M G and Hayes J G (1973) Curve fitting: a guide and suite of algorithms for the non-specialist user NPL Report NAC26 National Physical Laboratory
De Boor C (1972) On calculating with B-splines J. Approx. Theory 6 50–62
Gentleman W M (1973) Least-squares computations by Givens transformations without square roots J. Inst. Math. Applic. 12 329–336
Gentleman W M (1974) Algorithm AS 75. Basic procedures for large sparse or weighted linear least-squares problems Appl. Statist. 23 448–454
Schoenberg I J and Whitney A (1953) On Polya frequency functions III Trans. Amer. Math. Soc. 74 246–259
e02 Chapter Introduction.
NAG Toolbox Overview.
NAG Web Site.
|
|