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_integ (e02bd)

## Purpose

nag_fit_1dspline_integ (e02bd) computes the definite integral of a cubic spline from its B-spline representation.

## Syntax

[dint, ifail] = e02bd(lamda, c, 'ncap7', ncap7)
[dint, ifail] = nag_fit_1dspline_integ(lamda, c, 'ncap7', ncap7)

## Description

nag_fit_1dspline_integ (e02bd) computes the definite integral of the cubic spline $s\left(x\right)$ between the limits $x=a$ and $x=b$, where $a$ and $b$ are respectively the lower and upper limits of the range over which $s\left(x\right)$ is defined. It is assumed that $s\left(x\right)$ is represented in terms of its B-spline coefficients ${c}_{i}$, for $\mathit{i}=1,2,\dots ,\stackrel{-}{n}+3$ and (augmented) ordered knot set ${\lambda }_{i}$, for $\mathit{i}=1,2,\dots ,\stackrel{-}{n}+7$, with ${\lambda }_{i}=a$, for $\mathit{i}=1,2,3,4$ and ${\lambda }_{i}=b$, for $\mathit{i}=\stackrel{-}{n}+4,\dots ,\stackrel{-}{n}+7$, (see nag_fit_1dspline_knots (e02ba)), i.e.,
 $sx=∑i=1qciNix.$
Here $q=\stackrel{-}{n}+3$, $\stackrel{-}{n}$ is the number of intervals of the spline and ${N}_{i}\left(x\right)$ denotes the normalized B-spline of degree $3$ (order $4$) defined upon the knots ${\lambda }_{i},{\lambda }_{i+1},\dots ,{\lambda }_{i+4}$.
The method employed uses the formula given in Section 3 of Cox (1975).
nag_fit_1dspline_integ (e02bd) can be used to determine the definite integrals of cubic spline fits and interpolants produced by nag_fit_1dspline_knots (e02ba).

## References

Cox M G (1975) An algorithm for spline interpolation J. Inst. Math. Appl. 15 95–108

## 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)$ and satisfy ${\mathbf{lamda}}\left(1\right)={\mathbf{lamda}}\left(2\right)={\mathbf{lamda}}\left(3\right)={\mathbf{lamda}}\left(4\right)$ and ${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)={\mathbf{lamda}}\left({\mathbf{ncap7}}-2\right)={\mathbf{lamda}}\left({\mathbf{ncap7}}-1\right)={\mathbf{lamda}}\left({\mathbf{ncap7}}\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.

### 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 of the spline (which is one greater than the number of interior knots, i.e., the knots strictly within the range $a$ to $b$) over which the spline is defined.
Constraint: ${\mathbf{ncap7}}\ge 8$.

### Output Parameters

1:     $\mathrm{dint}$ – double scalar
The value of the definite integral of $s\left(x\right)$ between the limits $x=a$ and $x=b$, where $a={\lambda }_{4}$ and $b={\lambda }_{\stackrel{-}{n}+4}$.
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$
${\mathbf{ncap7}}<8$, i.e., the number of intervals is not positive.
${\mathbf{ifail}}=2$
At least one of the following restrictions on the knots is violated:
• ${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)>{\mathbf{lamda}}\left(4\right)$,
• ${\mathbf{lamda}}\left(j\right)\ge {\mathbf{lamda}}\left(j-1\right)$,
for $j=2,3,\dots ,{\mathbf{ncap7}}$, with equality in the cases $j=2,3,4,{\mathbf{ncap7}}-2,{\mathbf{ncap7}}-1$, and ncap7
${\mathbf{ifail}}=-99$
${\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 rounding errors are such that the computed value of the integral is exact for a slightly perturbed set of B-spline coefficients ${c}_{i}$ differing in a relative sense from those supplied by no more than .

The time taken is approximately proportional to $\stackrel{-}{n}+7$.

## Example

This example determines the definite integral over the interval $0\le x\le 6$ of a cubic spline having $6$ interior knots at the positions $\lambda =1$, $3$, $3$, $3$, $4$, $4$, the $8$ additional knots $0$, $0$, $0$, $0$, $6$, $6$, $6$, $6$, and the $10$ B-spline coefficients $10$, $12$, $13$, $15$, $22$, $26$, $24$, $18$, $14$, $12$.
The input data items (using the notation of Arguments) comprise the following values in the order indicated:
 $\stackrel{-}{n}$ ${\mathbf{lamda}}\left(j\right)$, for $j=1,2,\dots ,{\mathbf{ncap7}}$ ${\mathbf{c}}\left(j\right)$, for $j=1,2,\dots ,{\mathbf{ncap7}}-3$
```function e02bd_example

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

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

lamda = zeros(ncap7,1);
lamda(5:ncap+3) = knots;
lamda(ncap+4:ncap7) = 6;

% B-spline coefficients
c = zeros(ncap7,1);
c(1:ncap+3) = [10  12  13  15  22  26  24  18  14  12];

[dint, ifail] = e02bd( ...
lamda, c);

fprintf('Definite integral = %10.3e\n',dint);

```
```e02bd example results

Definite integral =  1.000e+02
```