E02 Chapter Contents
E02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE02BDF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

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

## 2  Specification

 SUBROUTINE E02BDF ( NCAP7, LAMDA, C, DINT, IFAIL)
 INTEGER NCAP7, IFAIL REAL (KIND=nag_wp) LAMDA(NCAP7), C(NCAP7), DINT

## 3  Description

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 ,\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 E02BAF), 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).
E02BDF can be used to determine the definite integrals of cubic spline fits and interpolants produced by E02BAF.

## 4  References

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

## 5  Parameters

1:     NCAP7 – INTEGERInput
On entry: $\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$.
2:     LAMDA(NCAP7) – 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)$ 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:     C(NCAP7) – REAL (KIND=nag_wp) arrayInput
On entry: 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.
4:     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 }_{\stackrel{-}{n}+4}$.
5:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction 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 parameter, 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}}={\mathbf{0}}$ or $-{\mathbf{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$
${\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.

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

## 8  Further Comments

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

## 9  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 Section 5) 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$

### 9.1  Program Text

Program Text (e02bdfe.f90)

### 9.2  Program Data

Program Data (e02bdfe.d)

### 9.3  Program Results

Program Results (e02bdfe.r)