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

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_fit_1dspline_eval (e02bb)

## Purpose

nag_fit_1dspline_eval (e02bb) evaluates a cubic spline from its B-spline representation.

## Syntax

[s, ifail] = e02bb(lamda, c, x, 'ncap7', ncap7)
[s, ifail] = nag_fit_1dspline_eval(lamda, c, x, 'ncap7', ncap7)

## Description

nag_fit_1dspline_eval (e02bb) 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 nag_fit_1dspline_knots (e02ba)) and from the coefficients ${c}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,q$in its B-spline representation
 $sx=∑i=1qciNix.$
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 B-spline 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 nag_fit_1dspline_eval (e02bb) will be the evaluation of the cubic spline approximations produced by nag_fit_1dspline_knots (e02ba). A generalization of nag_fit_1dspline_eval (e02bb) which also forms the derivative of $s\left(x\right)$ is nag_fit_1dspline_deriv (e02bc). nag_fit_1dspline_deriv (e02bc) takes about $50%$ longer than nag_fit_1dspline_eval (e02bb).

## 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
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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{lamda}\left({\mathbf{ncap7}}\right)$ – double array
${\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)>{\mathbf{lamda}}\left(4\right)$.
2:     $\mathrm{c}\left({\mathbf{ncap7}}\right)$ – double array
The coefficient ${c}_{\mathit{i}}$ of the B-spline ${N}_{\mathit{i}}\left(x\right)$, for $\mathit{i}=1,2,\dots ,\stackrel{-}{n}+3$. The remaining elements of the array are not referenced.
3:     $\mathrm{x}$ – double scalar
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)$.

### Optional Input Parameters

1:     $\mathrm{ncap7}$int64int32nag_int scalar
Default: the dimension of the arrays lamda, c. (An error is raised if these dimensions are not equal.)
$\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$.

### Output Parameters

1:     $\mathrm{s}$ – double scalar
The value of the spline, $s\left(x\right)$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
The argument x does not satisfy ${\mathbf{lamda}}\left(4\right)\le {\mathbf{x}}\le {\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)$.
In this case the value of s is set arbitrarily to zero.
${\mathbf{ifail}}=2$
${\mathbf{ncap7}}<8$, i.e., the number of interior knots is negative.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## 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 , 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  in modulus. For further details see Cox (1978).

## Further Comments

The time taken is approximately ${\mathbf{c}}×\left(1+0.1×\mathrm{log}\left(\stackrel{-}{n}+7\right)\right)$ seconds, where c is a machine-dependent constant.
Note:  the function does not test all the conditions on the knots given in the description of lamda in Arguments, 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 nag_fit_1dspline_knots (e02ba), however.

## Example

Evaluate at nine equally-spaced 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 B-spline 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 B-spline form, to be evaluated at $m$ equally-spaced points in the interval ${\mathbf{lamda}}\left(4\right)\le x\le {\mathbf{lamda}}\left(\stackrel{-}{n}+4\right)$. The program is self-starting in that any number of datasets may be supplied.
```function e02bb_example

fprintf('e02bb example results\n\n');

knots = [3 6 8];
ncap = size(knots,2) + 1;
ncap7 = ncap + 7;

lamda = zeros(ncap7,1);
lamda(1:4) = 1;
lamda(5:7) = knots;
lamda(8:ncap7) = 9;

% B-spline coefficients
c = zeros(ncap7,1);
c(1:ncap+3) = [1  2  4   7   6    4    3];

% Evaluate spline at values in lamda range
a = lamda(4);
b = lamda(ncap+4);
for x = 1:9;
[s(x), ifail] = e02bb( ...
lamda, c, x);
end
fprintf('    x      spline at x\n');
fprintf('%7.2f%14.4f\n',[ [1:9]; s]);

fig1 = figure;
hold on
plot([1:9],s,'*')
plot([1:9],s);
xlabel('x');
title('Evaluation of cubic spline representation');
legend('Evaluation points','cubic spline','Location','NorthWest');
hold off;

```
```e02bb example results

x      spline at x
1.00        1.0000
2.00        2.3779
3.00        3.6229
4.00        4.8327
5.00        5.8273
6.00        6.3571
7.00        6.1905
8.00        5.1667
9.00        3.0000
```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015