# NAG FL Interfacee02bdf (dim1_​spline_​integ)

## 1Purpose

e02bdf computes the definite integral of a cubic spline from its B-spline representation.

## 2Specification

Fortran Interface
 Subroutine e02bdf ( c, dint,
 Integer, Intent (In) :: ncap7 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: lamda(ncap7), c(ncap7) Real (Kind=nag_wp), Intent (Out) :: dint
#include <nag.h>
 void e02bdf_ (const Integer *ncap7, const double lamda[], const double c[], double *dint, Integer *ifail)
The routine may be called by the names e02bdf or nagf_fit_dim1_spline_integ.

## 3Description

e02bdf 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 ,\overline{n}+3$ and (augmented) ordered knot set ${\lambda }_{i}$, for $\mathit{i}=1,2,\dots ,\overline{n}+7$, with ${\lambda }_{i}=a$, for $\mathit{i}=1,2,3,4$ and ${\lambda }_{i}=b$, for $\mathit{i}=\overline{n}+4,\dots ,\overline{n}+7$, (see e02baf), i.e.,
 $sx=∑i=1qciNix.$
Here $q=\overline{n}+3$, $\overline{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).
e02bdf can be used to determine the definite integrals of cubic spline fits and interpolants produced by e02baf.

## 4References

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

## 5Arguments

1: $\mathbf{ncap7}$Integer Input
On entry: $\overline{n}+7$, where $\overline{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$.
2: $\mathbf{lamda}\left({\mathbf{ncap7}}\right)$Real (Kind=nag_wp) array Input
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 ,\overline{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)$ 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)=\phantom{\rule{0ex}{0ex}}{\mathbf{lamda}}\left({\mathbf{ncap7}}-1\right)={\mathbf{lamda}}\left({\mathbf{ncap7}}\right)$.
3: $\mathbf{c}\left({\mathbf{ncap7}}\right)$Real (Kind=nag_wp) array Input
On entry: the coefficient ${c}_{\mathit{i}}$ of the B-spline ${N}_{\mathit{i}}\left(x\right)$, for $\mathit{i}=1,2,\dots ,\overline{n}+3$. The remaining elements of the array are not referenced.
4: $\mathbf{dint}$Real (Kind=nag_wp) Output
On exit: 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 }_{\overline{n}+4}$.
5: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value 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 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).

## 6Error 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{ncap7}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ncap7}}\ge 8$.
${\mathbf{ifail}}=2$
On entry, $J=〈\mathit{\text{value}}〉$, ${\mathbf{lamda}}\left(J\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left(J-1\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left(J\right)\ge {\mathbf{lamda}}\left(J-1\right)$.
On entry, ${\mathbf{lamda}}\left(1\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left(2\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left(1\right)={\mathbf{lamda}}\left(2\right)$.
On entry, ${\mathbf{lamda}}\left(2\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left(3\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left(2\right)={\mathbf{lamda}}\left(3\right)$.
On entry, ${\mathbf{lamda}}\left(3\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left(4\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left(3\right)={\mathbf{lamda}}\left(4\right)$.
On entry, ${\mathbf{lamda}}\left(4\right)=〈\mathit{\text{value}}〉$, $\mathrm{NCAP4}=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left(\mathrm{NCAP4}\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left(4\right)<{\mathbf{lamda}}\left(\mathrm{NCAP4}\right)$.
On entry, ${\mathbf{ncap7}}=〈\mathit{\text{value}}〉$, ${\mathbf{lamda}}\left({\mathbf{ncap7}}-1\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left({\mathbf{ncap7}}\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left({\mathbf{ncap7}}-1\right)={\mathbf{lamda}}\left({\mathbf{ncap7}}\right)$.
On entry, ${\mathbf{ncap7}}=〈\mathit{\text{value}}〉$, ${\mathbf{lamda}}\left({\mathbf{ncap7}}-2\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left({\mathbf{ncap7}}-1\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left({\mathbf{ncap7}}-2\right)={\mathbf{lamda}}\left({\mathbf{ncap7}}-1\right)$.
On entry, ${\mathbf{ncap7}}=〈\mathit{\text{value}}〉$, ${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{lamda}}\left({\mathbf{ncap7}}-3\right)={\mathbf{lamda}}\left({\mathbf{ncap7}}-2\right)$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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 .

## 8Parallelism and Performance

e02bdf is not threaded in any implementation.

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

## 10Example

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 Section 5) comprise the following values in the order indicated:
 $\overline{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$

### 10.1Program Text

Program Text (e02bdfe.f90)

### 10.2Program Data

Program Data (e02bdfe.d)

### 10.3Program Results

Program Results (e02bdfe.r)