Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_fit_1dspline_deriv_vector (e02bf)

## Purpose

nag_fit_1dspline_deriv_vector (e02bf) evaluates a cubic spline and up to its first three derivatives from its B-spline representation at a vector of points. nag_fit_1dspline_deriv_vector (e02bf) can be used to compute the values and derivatives of cubic spline fits and interpolants produced by reference to nag_interp_1d_spline (e01ba), nag_fit_1dspline_knots (e02ba) and nag_fit_1dspline_auto (e02be).

## Syntax

[s, ixloc, iwrk, ifail] = e02bf(start, lamda, c, deriv, xord, x, ixloc, iwrk, 'ncap7', ncap7, 'nx', nx, 'liwrk', liwrk)
[s, ixloc, iwrk, ifail] = nag_fit_1dspline_deriv_vector(start, lamda, c, deriv, xord, x, ixloc, iwrk, 'ncap7', ncap7, 'nx', nx, 'liwrk', liwrk)

## Description

nag_fit_1dspline_deriv_vector (e02bf) evaluates the cubic spline s(x)$s\left(x\right)$ and optionally derivatives up to order 3$3$ for a vector of points xj${x}_{\mathit{j}}$, for j = 1,2,,nx$\mathit{j}=1,2,\dots ,{n}_{x}$. It is assumed that s(x)$s\left(x\right)$ is represented in terms of its B-spline coefficients ci${c}_{\mathit{i}}$, for i = 1,2,,n + 3$\mathit{i}=1,2,\dots ,\stackrel{-}{n}+3$, and (augmented) ordered knot set λi${\lambda }_{\mathit{i}}$, for i = 1,2,,n + 7$\mathit{i}=1,2,\dots ,\stackrel{-}{n}+7$, (see nag_fit_1dspline_knots (e02ba) and nag_fit_1dspline_auto (e02be)), i.e.,
 q s(x) = ∑ ciNi(x). i = 1
$s(x) = ∑ i=1q ci Ni(x) .$
Here q = n + 3$q=\stackrel{-}{n}+3$, n$\stackrel{-}{n}$ is the number of intervals of the spline and Ni(x)${N}_{i}\left(x\right)$ denotes the normalized B-spline of degree 3$3$ (order 4$4$) defined upon the knots λi,λi + 1,,λi + 4${\lambda }_{i},{\lambda }_{i+1},\dots ,{\lambda }_{i+4}$.
Only abscissae satisfying,
 λ4 ≤ xj ≤ λn + 4 , $λ4 ≤ xj ≤ λn-+4 ,$
will be evaluated. At a simple knot λi${\lambda }_{i}$ (i.e., one satisfying λi1 < λi < λi + 1${\lambda }_{i-1}<{\lambda }_{i}<{\lambda }_{i+1}$), 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 x = u$x=u$ where (exactly) r$r$ knots coincide (such a point is termed a knot of multiplicity r$r$), the values of the derivatives of order 4j$4-\mathit{j}$, for j = 1,2,,r$\mathit{j}=1,2,\dots ,r$, are, in general, discontinuous. (Here 1r4$1\le r\le 4$; r > 4$r>4$ is not meaningful.) The maximum order of the derivatives to be evaluated must be specified (|deriv|$|{\mathbf{deriv}}|$), as must their left- (deriv < 0${\mathbf{deriv}}<0$) or right- (deriv > 0${\mathbf{deriv}}>0$) handedness when evaluated at the knots.
Each abscissa (point at which the spline is to be evaluated) xj${x}_{j}$ contained in X has an associated enclosing interval number, ixlocj${\mathit{ixloc}}_{j}$ either supplied or returned in ixloc (see parameter x). A simple call to nag_fit_1dspline_deriv_vector (e02bf) would set start to zero and the contents of ixloc 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
ixlocj =
 ≤ 0 xj < λ1 4 λ4 = xj k λk < xj < λk + 1 k λ4 < λk = xj left derivatives k xj = λk + 1 < λn + 4 right derivatives or no derivatives n + 4 λn + 4 = xj > n + 7 xj > λn + 7
$ixlocj = ≤0 xj < λ1 4 λ4 = xj k λk < xj < λk+1 k λ4 < λk = xj left derivatives k xj = λk+1 < λ n-+4 right derivatives or no derivatives n-+4 λn-+4 = xj >n-+7 xj > λn-+7$
(1)
The algorithm has two modes of vectorization, termed here sorted and unsorted, which are selectable by the parameter start. 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, ixlocj${\mathit{ixloc}}_{j}$ is determined for each xj${x}_{j}$ and a permutation is calculated to sort the xj${x}_{j}$ by interval number. The first phase may be either partially or completely by-passed using the parameter start if the enclosing segments and/or the subsequent ordering are already known a priori, for example if multiple spline coefficients c are to be evaluated over the same set of knots lamda.
In the second phase of the sorted mode, spline approximations are evaluated by segment, so that non-abscissae dependent calculations over a segment may be reused in the evaluation for all abscissa 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 the evaluation at an abscissa is independent of evaluations at other abscissae; also non-abscissae dependent calculations over a segment will be repeated for each abscissa in a segment. This may be quicker if the number of absicssae 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 nag_fit_1dspline_eval (e02bb) and nag_fit_1dspline_deriv (e02bc), although if the enclosing interval numbers ixlocj${\mathit{ixloc}}_{j}$ are known, these may again be provided.
If no derivatives are required, the spline evaluation is calculated by taking convex combinations due to de Boor (1972). Otherwise, the calculation of s(x)$s\left(x\right)$ and its derivatives is based upon,
 (i) evaluating the nonzero B-splines of orders 1$1$, 2$2$, 3$3$ and 4$4$ by recurrence (see Cox (1972) and Cox (1978)), (ii) computing all derivatives of the B-splines of order 4$4$ by applying a second recurrence to these computed B-spline values (see de Boor (1972)), (iii) multiplying the fourth-order B-spline values and their derivative by the appropriate B-spline coefficients, and summing, to yield the values of s(x)$s\left(x\right)$ and its derivatives.
The method of convex combinations is significantly faster than the recurrence based method. If higher derivatives of order 2$2$ or 3$3$ 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

## Parameters

### Compulsory Input Parameters

1:     start – int64int32nag_int scalar
Indicates the completion state of the first phase of the algorithm.
start = 0${\mathbf{start}}=0$
The enclosing interval numbers ixlocj${\mathit{ixloc}}_{j}$ for the abscissae xj${x}_{j}$ contained in x have not been determined, and you wish to use the sorted mode of vectorization.
start = 1${\mathbf{start}}=1$
The enclosing interval numbers ixlocj${\mathit{ixloc}}_{j}$ have been determined and are provided in ixloc, however the required permutation and interval related information has not been determined and you wish to use the sorted mode of vectorization.
start = 2${\mathbf{start}}=2$
You wish to use the sorted mode of vectorization, and the entire first phase has been completed, with the enclosing interval numbers supplied in ixloc, and the required permutation and interval related information provided in iwrk (from a previous call to nag_fit_1dspline_deriv_vector (e02bf)).
start = 10${\mathbf{start}}=10$
The enclosing interval numbers ixlocj${\mathit{ixloc}}_{j}$ for the abscissae xj${x}_{j}$ contained in x have not been determined, and you wish to use the unsorted mode of vectorization.
start = 11${\mathbf{start}}=11$
The enclosing interval numbers ixlocj${\mathit{ixloc}}_{j}$ for the abscissae xj${x}_{j}$ contained in x have been supplied in ixloc, and you wish to use the unsorted mode of vectorization.
Constraint: start = 0${\mathbf{start}}=0$, 1$1$, 2$2$, 10$10$ or 11$11$.
Additional: start = 0${\mathbf{start}}=0$ or 10$10$ should be used unless you are sure that the knot set is unchanged between calls.
2:     lamda(ncap7) – double array
ncap7, the dimension of the array, must satisfy the constraint ncap788${\mathbf{ncap7}}\ge 88$.
lamda(j)${\mathbf{lamda}}\left(\mathit{j}\right)$ must be set to the value of the j$\mathit{j}$th member of the complete set of knots, λj${\lambda }_{\mathit{j}}$, for j = 1,2,,n + 7$\mathit{j}=1,2,\dots ,\stackrel{-}{n}+7$.
Constraint: the lamda(j)${\mathbf{lamda}}\left(j\right)$ must be in nondecreasing order with
lamda(ncap73) > lamda(4)${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)>{\mathbf{lamda}}\left(4\right)$.
3:     c(ncap7) – double array
ncap7, the dimension of the array, must satisfy the constraint ncap788${\mathbf{ncap7}}\ge 88$.
The coefficient ci${c}_{\mathit{i}}$ of the B-spline Ni(x)${N}_{\mathit{i}}\left(x\right)$, for i = 1,2,,n + 3$\mathit{i}=1,2,\dots ,\stackrel{-}{n}+3$. The remaining elements of the array are not referenced.
4:     deriv – int64int32nag_int scalar
The order of derivatives required.
If deriv < 0${\mathbf{deriv}}<0$ left derivatives are calculated, otherwise right derivatives are calculated. For abscissae satisfying xj = λ4${x}_{j}={\lambda }_{4}$ or xj = λn + 4${x}_{j}={\lambda }_{\stackrel{-}{n}+4}$ only right or left derivatives will be computed respectively. For abscissae which do not coincide exactly with a knot, the sign of deriv is immaterial.
deriv = 0${\mathbf{deriv}}=0$
No derivatives required.
deriv = ± 1${\mathbf{deriv}}=±1$
Only s(x)$s\left(x\right)$ and its first derivative are required.
deriv = ± 2${\mathbf{deriv}}=±2$
Only s(x)$s\left(x\right)$ and its first and second derivatives are required.
deriv = ± 3${\mathbf{deriv}}=±3$
s(x)$s\left(x\right)$ and its first, second and third derivatives are required.
Note: if |deriv|$|{\mathbf{deriv}}|$ is greater than 3$3$ only the derivatives up to and including 3$3$ will be returned.
5:     xord – int64int32nag_int scalar
Indicates whether x is supplied in a sufficiently ordered manner. If x is sufficiently ordered nag_fit_1dspline_deriv_vector (e02bf) will complete faster.
xord = 1${\mathbf{xord}}=1$
The abscissae in x are ordered at least by interval, in that any two abscissae contained in the same interval are only separated by abscissae in the same interval. For example, xj < xj + 1${x}_{j}<{x}_{\mathit{j}+1}$, for j = 1,2,,nx1$\mathit{j}=1,2,\dots ,{\mathbf{nx}}-1$.
xord1${\mathbf{xord}}\ne 1$
The abscissae in x are not sufficiently ordered.
6:     x(nx) – double array
nx, the dimension of the array, must satisfy the constraint nx1${\mathbf{nx}}\ge 1$.
The abscissae xj${x}_{\mathit{j}}$, for j = 1,2,,nx$\mathit{j}=1,2,\dots ,{n}_{x}$. Evaluations will only be performed for those xj${x}_{j}$ satisfying λ4xjλ + 4${\lambda }_{4}\le {x}_{j}\le {\lambda }_{\stackrel{~}{n}+4}$.
Constraint: at least one abscissa must fall between lamda(4)${\mathbf{lamda}}\left(4\right)$ and lamda(ncap73)${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)$.
7:     ixloc(nx) – int64int32nag_int array
nx, the dimension of the array, must satisfy the constraint nx1${\mathbf{nx}}\ge 1$.
If start = 1${\mathbf{start}}=1$, 2$2$ or 11$11$, if you wish xj${x}_{j}$ to be evaluated, ixloc(j)${\mathbf{ixloc}}\left(j\right)$ must be the enclosing interval number ixlocj${\mathit{ixloc}}_{j}$ of the abscissae xj${x}_{j}$ (see (1)). If you do not wish xj${x}_{j}$ to be evaluated, you may set the interval number to be either less than 4$4$ or greater than n + 4$\stackrel{-}{n}+4$.
Otherwise, ixloc need not be set.
Constraint: if start = 1${\mathbf{start}}=1$, 2$2$ or 11$11$, at least one element of ixloc must be between 4$4$ and ncap73${\mathbf{ncap7}}-3$ .
8:     iwrk(liwrk) – int64int32nag_int array
liwrk, the dimension of the array, must satisfy the constraint liwrk3 + 3 × nx${\mathbf{liwrk}}\ge 3+3×{\mathbf{nx}}$.
If start = 2${\mathbf{start}}=2$, iwrk must be unchanged from a previous call to nag_fit_1dspline_deriv_vector (e02bf) with start = 0${\mathbf{start}}=0$ or 1$1$.
Otherwise, iwrk need not be set.

### Optional Input Parameters

1:     ncap7 – int64int32nag_int scalar
Default: The dimension of the arrays lamda, c. (An error is raised if these dimensions are not equal.)
n + 7$\stackrel{-}{n}+7$, where n$\stackrel{-}{n}$ is the number of intervals of the spline (which is one greater than the number of interior knots, i.e., the knots strictly within the range λ4${\lambda }_{4}$ to λn + 4${\lambda }_{\stackrel{-}{n}+4}$ over which the spline is defined). Note that if nag_fit_1dspline_auto (e02be) was used to generate the knots and spline coefficients then ncap7 should contain the same value as returned in n by nag_fit_1dspline_auto (e02be).
Constraint: ncap788${\mathbf{ncap7}}\ge 88$.
2:     nx – int64int32nag_int scalar
Default: The dimension of the array x and the dimension of the array ixloc. (An error is raised if these dimensions are not equal.)
nx${n}_{x}$, the total number of abscissae contained in x, including any that will not be evaluated.
Constraint: nx1${\mathbf{nx}}\ge 1$.
3:     liwrk – int64int32nag_int scalar
Default: The dimension of the array iwrk.
The dimension of the array iwrk as declared in the (sub)program from which nag_fit_1dspline_deriv_vector (e02bf) is called.
Constraint: liwrk3 + 3 × nx${\mathbf{liwrk}}\ge 3+3×{\mathbf{nx}}$.

lds

### Output Parameters

1:     s(lds, : $:$) – double array
The first dimension of the array s will be nx${\mathbf{nx}}$, regardless of the acceptability of the elements of x
The second dimension of the array will be min (|deriv|,3) + 1 $\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(|{\mathbf{deriv}}|,3\right)+1$
ldsnx$\mathit{lds}\ge {\mathbf{nx}}$, regardless of the acceptability of the elements of x.
If xj${x}_{j}$ is valid, s(j,d)${\mathbf{s}}\left(\mathit{j},\mathit{d}\right)$ will contain the (d1$\mathit{d}-1$)th derivative of s(x)$s\left(x\right)$, for d = 1,2,,min (|deriv|,3) + 1$\mathit{d}=1,2,\dots ,\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(|{\mathbf{deriv}}|,3\right)+1$ and j = 1,2,,nx$\mathit{j}=1,2,\dots ,{n}_{x}$. In particular, s(j,1)${\mathbf{s}}\left(j,1\right)$ will contain the approximation of s(xj)$s\left({x}_{j}\right)$ for all legal values in x.
2:     ixloc(nx) – int64int32nag_int array
If start = 1${\mathbf{start}}=1$, 2$2$ or 11$11$, ixloc is unchanged on exit.
Otherwise, ixloc(j)${\mathbf{ixloc}}\left(\mathit{j}\right)$, for j = 1,2,,nx$\mathit{j}=1,2,\dots ,{n}_{x}$, contains the enclosing interval number ixlocj${\mathit{ixloc}}_{\mathit{j}}$, supplied in x, for j = 1,2,,nx$\mathit{j}=1,2,\dots ,{n}_{x}$. Evaluations will only take place for abscissae xj${x}_{j}$ with 4ixlocjn + 4$4\le {\mathit{ixloc}}_{j}\le \stackrel{-}{n}+4$.
3:     iwrk(liwrk) – int64int32nag_int array
If start = 10${\mathbf{start}}=10$ or 11$11$, iwrk is unchanged on exit.
Otherwise, iwrk contains the required permutation of elements of x, if any, and information related to the division of the abscissae xj${x}_{j}$ between the intervals derived from lamda.
4:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Note: nag_fit_1dspline_deriv_vector (e02bf) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
On entry, at least one element of x has an enclosing interval number in ixloc outside the set allowed by the provided spline.
ifail = 2${\mathbf{ifail}}=2$
On entry, all elements of x had enclosing interval numbers in ixloc outside the domain allowed by the provided spline.
ifail = 11${\mathbf{ifail}}=11$
Constraint: start = 0${\mathbf{start}}=0$, 1$1$, 2$2$, 10$10$ or 11$11$.
ifail = 12${\mathbf{ifail}}=12$
ifail = 21${\mathbf{ifail}}=21$
Constraint: ncap78${\mathbf{ncap7}}\ge 8$.
ifail = E02BFF_IERR_LAMDA${\mathbf{ifail}}=\mathbf{E02BFF_IERR_LAMDA}$
Constraint: lamda(4) < lamda(ncap73)${\mathbf{lamda}}\left(4\right)<{\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)$.
ifail = 91${\mathbf{ifail}}=91$
Constraint: nx1${\mathbf{nx}}\ge 1$.
ifail = 111${\mathbf{ifail}}=111$
ldsnx is too small.
ifail = 131${\mathbf{ifail}}=131$
liwrknx is too small.

## Accuracy

The computed value of s(x)$s\left(x\right)$ has negligible error in most practical situations. Specifically, this value has an absolute error bounded in modulus by 18 × cmax × machine precision, where cmax$\mathit{cmax}$ is the largest in modulus of cj${c}_{j}$, cj + 1${c}_{j}+1$, cj + 2${c}_{j}+2$ and cj + 3${c}_{j}+3$, and j$j$ is an integer such that λj + 3 < xλj + 4${\lambda }_{j}+3. If cj${c}_{j}$, cj + 1${c}_{j}+1$, cj + 2${c}_{j}+2$ and cj + 3${c}_{j}+3$ are all of the same sign, then the computed value of s(x)$s\left(x\right)$ has relative error bounded by 20 × machine precision. For full details see Cox (1978).
No complete error analysis is available for the computation of the derivatives of s(x)$s\left(x\right)$. However, for most practical purposes the absolute errors in the computed derivatives should be small. Note that this is in comparison to the derivatives of the spline, which may or may not be comparable to the derivatives of the function that has been approximated by the spline.

If using the sorted mode of vectorization, the time required for the first phase to determine the enclosing intervals is approximately proportional to O(nxlog(n))$\mathit{O}\left({n}_{x}\mathrm{log}\left(\stackrel{-}{n}\right)\right)$. The time required to then generate the required permutations and interval information is O(nx)$\mathit{O}\left({n}_{x}\right)$ if x is ordered sufficiently, or at worst O(nxmin (nx,n)log(min (nx,n))) $\mathit{O}\left({n}_{x}\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({n}_{x},\stackrel{-}{n}\right)\mathrm{log}\left(\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({n}_{x},\stackrel{-}{n}\right)\right)\right)$ if x is not ordered. The time required by the second phase is then proportional to O(nx)$\mathit{O}\left({n}_{x}\right)$.
If using the unsorted mode of vectorization, the time required is proportional to O(nxlog(n)) $\mathit{O}\left({n}_{x}\mathrm{log}\left(\stackrel{-}{n}\right)\right)$ if the enclosing interval numbers are not provided, or O(nx) $\mathit{O}\left({n}_{x}\right)$ if they are provided. However, the repeated calculation of various quantities will typically make this slower than the sorted mode when the ratio of abscissae to knots is high, or the abscissae are densely distributed over a relatively small subset of the intervals of the spline.
Note: the function does not test all the conditions on the knots given in the description of lamda in Section [Parameters], since to do this would result in a computation time with a linear dependency upon n$\stackrel{-}{n}$ instead of log(n)$\mathrm{log}\left(\stackrel{-}{n}\right)$. All the conditions are tested in nag_fit_1dspline_knots (e02ba) and nag_fit_1dspline_auto (e02be), however.

## Example

```function nag_fit_1dspline_deriv_vector_example
xdata = [0; 0.5; 1; 1.5; 2; 2.5; 3; 4; 4.5; 5; 5.5; 6; 7; 7.5; 8];
ydata = [-1.1; -0.372; 0.431; 1.69; 2.11; 3.1; 4.23; 4.35; 4.81; 4.61; 4.79; ...
5.23; 6.35; 7.19; 7.97];
wdata = [1; 1; 1.5; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
cstart = 'c';
sfac  = 0.001;
x     = [6.5178; 7.2463; 1.0159; 7.3070; 5.0589; 0.7803; 2.2280; 4.3751; ...
7.6601; 7.7191; 1.2609; 7.7647; 7.6573; 3.8830; 6.4022; 1.1351; ...
3.3741; 7.3259; 6.3377; 7.6759];
nest  = int64(numel(xdata) + 4);
ixloc = zeros(numel(x), 1, 'int64');
wrk   = zeros(4*numel(xdata) + 16*nest + 41, 1);
iwrk1 = zeros(nest, 1, 'int64');
iwrk2 = zeros(3+3*numel(x), 1, 'int64');
lamda = zeros(nest, 1);
xord  = int64(0);
start = int64(0);
deriv = int64(3);

% Determine the spline approximation
[n, lamda, c, fp, wrk, iwrk1, ifail] = ...
nag_fit_1dspline_auto(cstart, xdata, ydata, wdata, sfac, nest, lamda, wrk, iwrk1);

% Evaluate the spline and derivatives
[s, ixloc, iwrk2, ifail] = nag_fit_1dspline_deriv_vector(start, lamda, c, deriv, xord, x, ixloc, iwrk2);

% Output the results
fprintf('\n        x   ixloc         s(x)        ds/dx      d2s/dx2      d3s/dx3\n');
sd2 = min(abs(deriv),3) + 1;
for r = 1:numel(x)
if ixloc(r) >= 4 && ixloc(r) <= n
fprintf(' %8.4f   %5d %12.4e %12.4e %12.4e %12.4e\n', x(r), ixloc(r), s(r, 1:sd2));
else
fprintf(' %8.4f   %5d\n', x(r), ixloc(r));
end
end
```
```

x   ixloc         s(x)        ds/dx      d2s/dx2      d3s/dx3
6.5178      14   5.7418e+00   1.0741e+00   5.6736e-01   1.3065e+00
7.2463      15   6.7486e+00   1.7074e+00   4.9054e-01  -2.8697e+00
1.0159       5   4.7469e-01   2.4179e+00   3.8175e+00  -2.2171e+01
7.3070      15   6.8531e+00   1.7319e+00   3.1634e-01  -2.8697e+00
5.0589      12   4.6105e+00  -1.0363e-01   2.9075e+00  -4.4467e+00
0.7803       4   6.6885e-03   1.6216e+00   2.5007e+00   7.5980e+00
2.2280       7   2.4751e+00   1.9559e+00   3.0615e+00  -6.6690e+00
4.3751      10   4.7199e+00   8.5194e-01  -3.0718e+00  -1.9866e+01
7.6601      15   7.4633e+00   1.6647e+00  -6.9696e-01  -2.8697e+00
7.7191      15   7.5602e+00   1.6186e+00  -8.6627e-01  -2.8697e+00
1.2609       5   1.1273e+00   2.6878e+00  -1.6146e+00  -2.2171e+01
7.7647      15   7.6330e+00   1.5761e+00  -9.9713e-01  -2.8697e+00
7.6573      15   7.4586e+00   1.6667e+00  -6.8892e-01  -2.8697e+00
3.8830       9   4.3152e+00   1.6458e-01   3.1754e+00   1.0296e+01
6.4022      14   5.6211e+00   1.0172e+00   4.1633e-01   1.3065e+00
1.1351       5   7.8376e-01   2.7154e+00   1.1746e+00  -2.2171e+01
3.3741       9   4.4165e+00  -1.1809e-01  -2.0644e+00   1.0296e+01
7.3259      15   6.8859e+00   1.7374e+00   2.6211e-01  -2.8697e+00
6.3377      14   5.5563e+00   9.9310e-01   3.3206e-01   1.3065e+00
7.6759      15   7.4895e+00   1.6534e+00  -7.4230e-01  -2.8697e+00

```
```function e02bf_example
xdata = [0; 0.5; 1; 1.5; 2; 2.5; 3; 4; 4.5; 5; 5.5; 6; 7; 7.5; 8];
ydata = [-1.1; -0.372; 0.431; 1.69; 2.11; 3.1; 4.23; 4.35; 4.81; 4.61; 4.79; ...
5.23; 6.35; 7.19; 7.97];
wdata = [1; 1; 1.5; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
cstart = 'c';
sfac  = 0.001;
x     = [6.5178; 7.2463; 1.0159; 7.3070; 5.0589; 0.7803; 2.2280; 4.3751; ...
7.6601; 7.7191; 1.2609; 7.7647; 7.6573; 3.8830; 6.4022; 1.1351; ...
3.3741; 7.3259; 6.3377; 7.6759];
nest  = int64(numel(xdata) + 4);
ixloc = zeros(numel(x), 1, 'int64');
wrk   = zeros(4*numel(xdata) + 16*nest + 41, 1);
iwrk1 = zeros(nest, 1, 'int64');
iwrk2 = zeros(3+3*numel(x), 1, 'int64');
lamda = zeros(nest, 1);
xord  = int64(0);
start = int64(0);
deriv = int64(3);

% Determine the spline approximation
[n, lamda, c, fp, wrk, iwrk1, ifail] = ...
e02be(cstart, xdata, ydata, wdata, sfac, nest, lamda, wrk, iwrk1);

% Evaluate the spline and derivatives
[s, ixloc, iwrk2, ifail] = e02bf(start, lamda, c, deriv, xord, x, ixloc, iwrk2);

% Output the results
fprintf('\n        x   ixloc         s(x)        ds/dx      d2s/dx2      d3s/dx3\n');
sd2 = min(abs(deriv),3) + 1;
for r = 1:numel(x)
if ixloc(r) >= 4 && ixloc(r) <= n
fprintf(' %8.4f   %5d %12.4e %12.4e %12.4e %12.4e\n', x(r), ixloc(r), s(r, 1:sd2));
else
fprintf(' %8.4f   %5d\n', x(r), ixloc(r));
end
end
```
```

x   ixloc         s(x)        ds/dx      d2s/dx2      d3s/dx3
6.5178      14   5.7418e+00   1.0741e+00   5.6736e-01   1.3065e+00
7.2463      15   6.7486e+00   1.7074e+00   4.9054e-01  -2.8697e+00
1.0159       5   4.7469e-01   2.4179e+00   3.8175e+00  -2.2171e+01
7.3070      15   6.8531e+00   1.7319e+00   3.1634e-01  -2.8697e+00
5.0589      12   4.6105e+00  -1.0363e-01   2.9075e+00  -4.4467e+00
0.7803       4   6.6885e-03   1.6216e+00   2.5007e+00   7.5980e+00
2.2280       7   2.4751e+00   1.9559e+00   3.0615e+00  -6.6690e+00
4.3751      10   4.7199e+00   8.5194e-01  -3.0718e+00  -1.9866e+01
7.6601      15   7.4633e+00   1.6647e+00  -6.9696e-01  -2.8697e+00
7.7191      15   7.5602e+00   1.6186e+00  -8.6627e-01  -2.8697e+00
1.2609       5   1.1273e+00   2.6878e+00  -1.6146e+00  -2.2171e+01
7.7647      15   7.6330e+00   1.5761e+00  -9.9713e-01  -2.8697e+00
7.6573      15   7.4586e+00   1.6667e+00  -6.8892e-01  -2.8697e+00
3.8830       9   4.3152e+00   1.6458e-01   3.1754e+00   1.0296e+01
6.4022      14   5.6211e+00   1.0172e+00   4.1633e-01   1.3065e+00
1.1351       5   7.8376e-01   2.7154e+00   1.1746e+00  -2.2171e+01
3.3741       9   4.4165e+00  -1.1809e-01  -2.0644e+00   1.0296e+01
7.3259      15   6.8859e+00   1.7374e+00   2.6211e-01  -2.8697e+00
6.3377      14   5.5563e+00   9.9310e-01   3.3206e-01   1.3065e+00
7.6759      15   7.4895e+00   1.6534e+00  -7.4230e-01  -2.8697e+00

```