# naginterfaces.library.fit.dim1_​spline_​deriv_​vector¶

naginterfaces.library.fit.dim1_spline_deriv_vector(start, lamda, c, deriv, xord, x, ixloc, iwrk=None)[source]

dim1_spline_deriv_vector evaluates a cubic spline and up to its first three derivatives from its B-spline representation at a vector of points. dim1_spline_deriv_vector can be used to compute the values and derivatives of cubic spline fits and interpolants produced by reference to interp.dim1_spline, dim1_spline_knots() and dim1_spline_auto().

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

https://www.nag.com/numeric/nl/nagdoc_28.6/flhtml/e02/e02bff.html

Parameters
startint

Indicates the completion state of the first phase of the algorithm.

The enclosing interval numbers for the abscissae contained in have not been determined, and you wish to use the sorted mode of vectorization.

The enclosing interval numbers have been determined and are provided in , however the required permutation and interval related information has not been determined and you wish to use the sorted mode of vectorization.

You wish to use the sorted mode of vectorization, and the entire first phase has been completed, with the enclosing interval numbers supplied in , and the required permutation and interval related information provided in (from a previous call to dim1_spline_deriv_vector).

The enclosing interval numbers for the abscissae contained in have not been determined, and you wish to use the unsorted mode of vectorization.

The enclosing interval numbers for the abscissae contained in have been supplied in , and you wish to use the unsorted mode of vectorization.

Additional: or should be used unless you are sure that the knot set is unchanged between calls.

lamdafloat, array-like, shape

must be set to the value of the th member of the complete set of knots, , for .

cfloat, array-like, shape

The coefficient of the B-spline , for . The remaining elements of the array are not referenced.

derivint

Determines the maximum order of derivatives required, .

If left derivatives are calculated, otherwise right derivatives are calculated. For abscissae satisfying or only right-handed or left-handed computation will be used respectively.

For abscissae which do not coincide exactly with a knot, the handedness of the computation is immaterial.

No derivatives required.

Only and its first derivative are required.

Only and its first and second derivatives are required.

and its first, second and third derivatives are required.

Note: if is greater than only the derivatives up to and including will be returned.

xordint

Indicates whether is supplied in a sufficiently ordered manner. If is sufficiently ordered dim1_spline_deriv_vector will complete faster.

The abscissae in are ordered at least by ascending interval, in that any two abscissae contained in the same interval are only separated by abscissae in the same interval, and the intervals are arranged in ascending order. For example, , for .

The abscissae in are not sufficiently ordered.

xfloat, array-like, shape

The abscissae , for . If or then evaluations will only be performed for these satisfying . Otherwise evaluation will be performed unless the corresponding element of contains an invalid interval number. Please note that if the is a valid interval number then no check is made that actually lies in that interval.

ixlocint, array-like, shape

If , or , if you wish to be evaluated, must be the enclosing interval number of the abscissae (see [equation]). If you do not wish to be evaluated, you may set the interval number to be either less than or greater than .

Otherwise, need not be set.

iwrkNone or int, array-like, shape , optional

If , must be unchanged from a previous call to dim1_spline_deriv_vector with or .

Otherwise, need not be set.

Returns
ixlocint, ndarray, shape

If , or , is unchanged on exit.

Otherwise, , contains the enclosing interval number , for the abscissa supplied in , for .

Evaluations will only be performed for abscissae satisfying .

If evaluation is not performed is set to if or if .

sfloat, ndarray, shape

If is valid, will contain the ()th derivative of , for , for . In particular, will contain the approximation of for all legal values in .

iwrkNone or int, ndarray, shape

If or , is unchanged on exit.

Otherwise, contains the required permutation of elements of , if any, and information related to the division of the abscissae between the intervals derived from .

Raises
NagValueError
(errno )

On entry, all elements of had enclosing interval numbers in outside the domain allowed by the provided spline.

entries of were indexed below the lower bound .

entries of were indexed above the upper bound .

(errno )

On entry, .

Constraint: , , , or .

(errno )

On entry, and is not consistent with the previous call to dim1_spline_deriv_vector.

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, , and .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

Warns
NagAlgorithmicWarning
(errno )

On entry, at least one element of has an enclosing interval number in outside the set allowed by the provided spline. The spline has been evaluated for all with enclosing interval numbers inside the allowable set.

entries of were indexed below the lower bound .

entries of were indexed above the upper bound .

Notes

dim1_spline_deriv_vector evaluates the cubic spline and optionally derivatives up to order for a vector of points , for . It is assumed that is represented in terms of its B-spline coefficients , for , and (augmented) ordered knot set , for , (see dim1_spline_knots() and dim1_spline_auto()), i.e.,

Here , is the number of intervals of the spline and denotes the normalized B-spline of degree (order ) defined upon the knots . The knots are the interior knots. The remaining knots, , , , and , , , are the exterior knots. The knots and are the boundaries of the spline.

Only abscissae satisfying,

will be evaluated. At a simple knot (i.e., one satisfying ), the third derivative of the spline is, in general, discontinuous. At a multiple knot (i.e., two or more knots with the same value), lower derivatives, and even the spline itself, may be discontinuous. Specifically, at a point where (exactly) knots coincide (such a point is termed a knot of multiplicity ), the values of the derivatives of order , for , are, in general, discontinuous. (Here ; is not meaningful.) The maximum order of the derivatives to be evaluated , and the left- or right-handedness of the computation when an abscissa corresponds exactly to an interior knot, are determined by the value of .

Each abscissa (point at which the spline is to be evaluated) contained in has an associated enclosing interval number, either supplied or returned in (see argument ). A simple call to dim1_spline_deriv_vector would set and the contents of need never be set nor referenced, and the following description on modes of operation can be ignored. However, where efficiency is an important consideration, the following description will help to choose the appropriate mode of operation.

The interval numbers are used to determine which B-splines must be evaluated for a given abscissa, and are defined as

The algorithm has two modes of vectorization, termed here sorted and unsorted, which are selectable by the argument .

Furthermore, if the supplied abscissae are sufficiently ordered, as indicated by the argument , the algorithm will take advantage of significantly faster methods for the determination of both the interval numbers and the subsequent spline evaluations.

The sorted mode has two phases, a sorting phase and an evaluation phase. This mode is recommended if there are many abscissae to evaluate relative to the number of intervals of the spline, or the abscissae are distributed relatively densely over a subsection of the spline. In the first phase, is determined for each and a permutation is calculated to sort the by interval number. The first phase may be either partially or completely by-passed using the argument if the enclosing segments and/or the subsequent ordering are already known a priori, for example if multiple spline coefficients are to be evaluated over the same set of knots .

In the second phase of the sorted mode, spline approximations are evaluated by segment, so that non-abscissa dependent calculations over a segment may be reused in the evaluation for all abscissae belonging to a specific segment. For example, all third derivatives of all abscissae in the same segment will be identical.

In the unsorted mode of vectorization, no a priori segment sorting is performed, and if the abscissae are not sufficiently ordered, the evaluation at an abscissa will be independent of evaluations at other abscissae; also non-abscissa dependent calculations over a segment will be repeated for each abscissa in a segment. This may be quicker if the number of abscissa is small in comparison to the number of knots in the spline, and they are distributed sparsely throughout the domain of the spline. This is effectively a direct vectorization of dim1_spline_eval() and dim1_spline_deriv(), although if the enclosing interval numbers are known, these may again be provided.

If the abscissae are sufficiently ordered, then once the first abscissa in a segment is known, an efficient algorithm will be used to determine the location of the final abscissa in this segment. The spline will subsequently be evaluated in a vectorized manner for all the abscissae indexed between the first and last of the current segment.

If no derivatives are required, the spline evaluation is calculated by taking convex combinations due to de Boor (1972). Otherwise, the calculation of and its derivatives is based upon,

1. evaluating the nonzero B-splines of orders , , and by recurrence (see Cox (1972) and Cox (1978)),

2. computing all derivatives of the B-splines of order by applying a second recurrence to these computed B-spline values (see de Boor (1972)),

3. multiplying the fourth-order B-spline values and their derivative by the appropriate B-spline coefficients, and summing, to yield the values of and its derivatives.

The method of convex combinations is significantly faster than the recurrence based method. If higher derivatives of order or are not required, as much computation as possible is avoided.

References

Cox, M G, 1972, The numerical evaluation of B-splines, J. Inst. Math. Appl. (10), 134–149

Cox, M G, 1978, The numerical evaluation of a spline from its B-spline representation, J. Inst. Math. Appl. (21), 135–143

de Boor, C, 1972, On calculating with B-splines, J. Approx. Theory (6), 50–62