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(x)$s\left(x\right)$ between the limits x = a$x=a$ and x = b$x=b$, where a$a$ and b$b$ are respectively the lower and upper limits of the range over which s(x)$s\left(x\right)$ is defined. It is assumed that s(x)$s\left(x\right)$ is represented in terms of its B-spline coefficients ci${c}_{i}$, for i = 1,2,,n + 3$\mathit{i}=1,2,\dots ,\stackrel{-}{n}+3$ and (augmented) ordered knot set λi${\lambda }_{i}$, for i = 1,2,,n + 7$\mathit{i}=1,2,\dots ,\stackrel{-}{n}+7$, with λi = a${\lambda }_{i}=a$, for i = 1,2,3,4$\mathit{i}=1,2,3,4$ and λi = b${\lambda }_{i}=b$, for i = n + 4,,n + 7$\mathit{i}=\stackrel{-}{n}+4,\dots ,\stackrel{-}{n}+7$, (see nag_fit_1dspline_knots (e02ba)), i.e.,
 q s(x) = ∑ ciNi(x). i = 1
$s(x)=∑i=1qciNi(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}$.
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:     lamda(ncap7) – double array
ncap7, the dimension of the array, must satisfy the constraint ncap78${\mathbf{ncap7}}\ge 8$.
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)$ and satisfy lamda(1) = lamda(2) = lamda(3) = lamda(4)${\mathbf{lamda}}\left(1\right)={\mathbf{lamda}}\left(2\right)={\mathbf{lamda}}\left(3\right)={\mathbf{lamda}}\left(4\right)$ and lamda(ncap73) = lamda(ncap72) = lamda(ncap71) = ${\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:     c(ncap7) – double array
ncap7, the dimension of the array, must satisfy the constraint ncap78${\mathbf{ncap7}}\ge 8$.
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.

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 a$a$ to b$b$) over which the spline is defined.
Constraint: ncap78${\mathbf{ncap7}}\ge 8$.

None.

Output Parameters

1:     dint – double scalar
The value of the definite integral of s(x)$s\left(x\right)$ between the limits x = a$x=a$ and x = b$x=b$, where a = λ4$a={\lambda }_{4}$ and b = λn + 4$b={\lambda }_{\stackrel{-}{n}+4}$.
2:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
ncap7 < 8${\mathbf{ncap7}}<8$, i.e., the number of intervals is not positive.
ifail = 2${\mathbf{ifail}}=2$
At least one of the following restrictions on the knots is violated:
• lamda(ncap73) > lamda(4)${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)>{\mathbf{lamda}}\left(4\right)$,
• lamda(j)lamda(j1)${\mathbf{lamda}}\left(j\right)\ge {\mathbf{lamda}}\left(j-1\right)$,
for j = 2,3,,ncap7$j=2,3,\dots ,{\mathbf{ncap7}}$, with equality in the cases j = 2,3,4,ncap72,ncap71$j=2,3,4,{\mathbf{ncap7}}-2,{\mathbf{ncap7}}-1$, and ncap7

Accuracy

The rounding errors are such that the computed value of the integral is exact for a slightly perturbed set of B-spline coefficients ci${c}_{i}$ differing in a relative sense from those supplied by no more than 2.2 × (n + 3) × machine precision.

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

Example

```function nag_fit_1dspline_integ_example
lamda = [0;
0;
0;
0;
1;
3;
3;
3;
4;
4;
6;
6;
6;
6];
c = [10;
12;
13;
15;
22;
26;
24;
18;
14;
12;
0;
0;
0;
0];
[dint, ifail] = nag_fit_1dspline_integ(lamda, c)
```
```

dint =

100

ifail =

0

```
```function e02bd_example
lamda = [0;
0;
0;
0;
1;
3;
3;
3;
4;
4;
6;
6;
6;
6];
c = [10;
12;
13;
15;
22;
26;
24;
18;
14;
12;
0;
0;
0;
0];
[dint, ifail] = e02bd(lamda, c)
```
```

dint =

100

ifail =

0

```