NAG Library Routine Document
e02bbf (dim1_spline_eval)
1
Purpose
e02bbf evaluates a cubic spline from its Bspline representation.
2
Specification
Fortran Interface
Integer, Intent (In)  ::  ncap7  Integer, Intent (Inout)  ::  ifail  Real (Kind=nag_wp), Intent (In)  ::  lamda(ncap7), c(ncap7), x  Real (Kind=nag_wp), Intent (Out)  ::  s 

C Header Interface
#include <nagmk26.h>
void 
e02bbf_ (const Integer *ncap7, const double lamda[], const double c[], const double *x, double *s, Integer *ifail) 

3
Description
e02bbf evaluates the cubic spline
$s\left(x\right)$ at a prescribed argument
$x$ from its augmented knot set
${\lambda}_{\mathit{i}}$, for
$\mathit{i}=1,2,\dots ,n+7$, (see
e02baf) and from the coefficients
${c}_{\mathit{i}}$, for
$\mathit{i}=1,2,\dots ,q$in its Bspline representation
Here
$q=\stackrel{}{n}+3$, where
$\stackrel{}{n}$ is the number of intervals of the spline, and
${N}_{i}\left(x\right)$ denotes the normalized Bspline of degree
$3$ defined upon the knots
${\lambda}_{i},{\lambda}_{i+1},\dots ,{\lambda}_{i+4}$. The prescribed argument
$x$ must satisfy
${\lambda}_{4}\le x\le {\lambda}_{\stackrel{}{n}+4}$.
It is assumed that ${\lambda}_{\mathit{j}}\ge {\lambda}_{\mathit{j}1}$, for $\mathit{j}=2,3,\dots ,\stackrel{}{n}+7$, and ${\lambda}_{\stackrel{}{n}+4}>{\lambda}_{4}$.
If
$x$ is a point at which
$4$ knots coincide,
$s\left(x\right)$ is discontinuous at
$x$; in this case,
s contains the value defined as
$x$ is approached from the right.
The method employed is that of evaluation by taking convex combinations due to
de Boor (1972). For further details of the algorithm and its use see
Cox (1972) and
Cox and Hayes (1973).
It is expected that a common use of
e02bbf will be the evaluation of the cubic spline approximations produced by
e02baf. A generalization of
e02bbf which also forms the derivative of
$s\left(x\right)$ is
e02bcf.
e02bcf takes about
$50\%$ longer than
e02bbf.
4
References
Cox M G (1972) The numerical evaluation of Bsplines J. Inst. Math. Appl. 10 134–149
Cox M G (1978) The numerical evaluation of a spline from its Bspline representation J. Inst. Math. Appl. 21 135–143
Cox M G and Hayes J G (1973) Curve fitting: a guide and suite of algorithms for the nonspecialist user NPL Report NAC26 National Physical Laboratory
de Boor C (1972) On calculating with Bsplines J. Approx. Theory 6 50–62
5
Arguments
 1: $\mathbf{ncap7}$ – IntegerInput

On entry: $\stackrel{}{n}+7$, where $\stackrel{}{n}$ is the number of intervals (one greater than the number of interior knots, i.e., the knots strictly within the range ${\lambda}_{4}$ to ${\lambda}_{\stackrel{}{n}+4}$) over which the spline is defined.
Constraint:
${\mathbf{ncap7}}\ge 8$.
 2: $\mathbf{lamda}\left({\mathbf{ncap7}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: ${\mathbf{lamda}}\left(\mathit{j}\right)$ must be set to the value of the $\mathit{j}$th member of the complete set of knots, ${\lambda}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,\stackrel{}{n}+7$.
Constraint:
the ${\mathbf{lamda}}\left(j\right)$ must be in nondecreasing order with ${\mathbf{lamda}}\left({\mathbf{ncap7}}3\right)>\phantom{\rule{0ex}{0ex}}{\mathbf{lamda}}\left(4\right)$.
 3: $\mathbf{c}\left({\mathbf{ncap7}}\right)$ – Real (Kind=nag_wp) arrayInput

On entry: the coefficient
${c}_{\mathit{i}}$ of the Bspline ${N}_{\mathit{i}}\left(x\right)$, for $\mathit{i}=1,2,\dots ,\stackrel{}{n}+3$. The remaining elements of the array are not referenced.
 4: $\mathbf{x}$ – Real (Kind=nag_wp)Input

On entry: the argument $x$ at which the cubic spline is to be evaluated.
Constraint:
${\mathbf{lamda}}\left(4\right)\le {\mathbf{x}}\le {\mathbf{lamda}}\left({\mathbf{ncap7}}3\right)$.
 5: $\mathbf{s}$ – Real (Kind=nag_wp)Output

On exit: the value of the spline, $s\left(x\right)$.
 6: $\mathbf{ifail}$ – IntegerInput/Output

On entry:
ifail must be set to
$0$,
$1\text{or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
$0$.
When the value $\mathbf{1}\text{or}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit:
${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
${\mathbf{ifail}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
 ${\mathbf{ifail}}=1$

On entry, ${\mathbf{x}}=\u2329\mathit{\text{value}}\u232a$, ${\mathbf{ncap7}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{lamda}}\left({\mathbf{ncap7}}3\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{x}}\le {\mathbf{lamda}}\left({\mathbf{ncap7}}3\right)$.
On entry, ${\mathbf{x}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{lamda}}\left(4\right)=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{x}}\ge {\mathbf{lamda}}\left(4\right)$.
 ${\mathbf{ifail}}=2$

On entry, ${\mathbf{ncap7}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{ncap7}}\ge 8$.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The computed value of
$s\left(x\right)$ has negligible error in most practical situations. Specifically, this value has an
absolute error bounded in modulus by
$18\times {c}_{\mathrm{max}}\times \mathit{machineprecision}$, where
${c}_{\mathrm{max}}$ is the largest in modulus of
${c}_{j},{c}_{j+1},{c}_{j+2}$ and
${c}_{j+3}$, and
$j$ is an integer such that
${\lambda}_{j+3}\le x\le {\lambda}_{j+4}$. If
${c}_{j},{c}_{j+1},{c}_{j+2}$ and
${c}_{j+3}$ are all of the same sign, then the computed value of
$s\left(x\right)$ has a
relative error not exceeding
$20\times \mathit{machineprecision}$ in modulus. For further details see
Cox (1978).
8
Parallelism and Performance
e02bbf is not threaded in any implementation.
The time taken is approximately
${\mathbf{c}}\times \left(1+0.1\times \mathrm{log}\left(\stackrel{}{n}+7\right)\right)$ seconds, where
c is a machinedependent constant.
Note: the routine does not test all the conditions on the knots given in the description of
lamda in
Section 5, since to do this would result in a computation time approximately linear in
$\stackrel{}{n}+7$ instead of
$\mathrm{log}\left(\stackrel{}{n}+7\right)$. All the conditions are tested in
e02baf, however.
10
Example
Evaluate at nine equallyspaced points in the interval $1.0\le x\le 9.0$ the cubic spline with (augmented) knots $1.0$, $1.0$, $1.0$, $1.0$, $3.0$, $6.0$, $8.0$, $9.0$, $9.0$, $9.0$, $9.0$ and normalized cubic Bspline coefficients $1.0$, $2.0$, $4.0$, $7.0$, $6.0$, $4.0$, $3.0$.
The example program is written in a general form that will enable a cubic spline with $\stackrel{}{n}$ intervals, in its normalized cubic Bspline form, to be evaluated at $m$ equallyspaced points in the interval ${\mathbf{lamda}}\left(4\right)\le x\le {\mathbf{lamda}}\left(\stackrel{}{n}+4\right)$. The program is selfstarting in that any number of datasets may be supplied.
10.1
Program Text
Program Text (e02bbfe.f90)
10.2
Program Data
Program Data (e02bbfe.d)
10.3
Program Results
Program Results (e02bbfe.r)