e02 Chapter Contents
e02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_1d_spline_intg (e02bdc)

## 1  Purpose

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

## 2  Specification

 #include #include
 void nag_1d_spline_intg (Nag_Spline *spline, double *integral, NagError *fail)

## 3  Description

nag_1d_spline_intg (e02bdc) 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_1d_spline_fit_knots (e02bac)), 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_1d_spline_intg (e02bdc) can be used to determine the definite integrals of cubic spline fits and interpolants produced by nag_1d_spline_interpolant (e01bac), nag_1d_spline_fit_knots (e02bac) and nag_1d_spline_fit (e02bec).

## 4  References

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

## 5  Arguments

1:     splineNag_Spline *
Pointer to structure of type Nag_Spline with the following members:
nIntegerInput
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{spline}\mathbf{\to }\mathbf{n}\ge 8$.
On entry: a pointer to which memory of size $\mathbf{spline}\mathbf{\to }\mathbf{n}$ must be allocated. $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[j-1\right]$ must be set to the value of the $j$th member of the complete set of knots, ${\lambda }_{j}$ for $j=1,2,\dots ,\stackrel{-}{n}+7$.
Constraint: the ${\lambda }_{j}$ must be in non-decreasing order with $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{n}-4\right]>\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]$ and satisfy
$\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[0\right]=\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[1\right]=\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[2\right]=\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]$
and
$\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{n}-4\right]=\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{n}-3\right]=\text{}\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{n}-2\right]=\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{n}-1\right]$
cdouble *Input
On entry: a pointer to which memory of size $\mathbf{spline}\mathbf{\to }\mathbf{n}-4$ must be allocated. $\mathbf{spline}\mathbf{\to }\mathbf{c}$ holds the coefficient ${c}_{i}$ of the B-spline ${N}_{i}\left(x\right)$, for $i=1,2,\dots ,\stackrel{-}{n}+3$.
2:     integraldouble *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}$.
3:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_INT_ARG_LT
On entry, $\mathbf{spline}\mathbf{\to }\mathbf{n}=〈\mathit{\text{value}}〉$.
Constraint: $\mathbf{spline}\mathbf{\to }\mathbf{n}\ge 8$.
NE_KNOTS_CONS
On entry, the knots must satisfy the following constraints:
$\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[\mathbf{spline}\mathbf{\to }\mathbf{n}-4\right]>\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[3\right]$, $\mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[j\right]\ge \mathbf{spline}\mathbf{\to }\mathbf{lamda}\left[j-1\right]$, for $j=1,2,\dots ,\mathbf{spline}\mathbf{\to }\mathbf{n}-1$, with equality in the cases $j=1,2,3$, $\mathbf{spline}\mathbf{\to }\mathbf{n}-3$, $\mathbf{spline}\mathbf{\to }\mathbf{n}-2$ and $\mathbf{spline}\mathbf{\to }\mathbf{n}-1$.

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

Under normal usage, the call to nag_1d_spline_intg (e02bdc) will follow a call to nag_1d_spline_interpolant (e01bac), nag_1d_spline_fit_knots (e02bac) or nag_1d_spline_fit (e02bec). In that case, the structure spline will have been set up correctly for input to nag_1d_spline_intg (e02bdc).
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}+7$ ${\mathbf{spline}}\mathbf{.}\mathbf{lamda}\left[j-1\right]$, for $j=1,2,\dots ,{\mathbf{spline}}\mathbf{.}\mathbf{n}$ ${\mathbf{spline}}\mathbf{.}\mathbf{c}\left[j-1\right]$, for $j=1,2,\dots ,{\mathbf{spline}}\mathbf{.}\mathbf{n}-3$
The example program is written in a general form that will enable the definite integral of a cubic spline having an arbitrary number of knots to be computed. Any number of datasets may be supplied. The only changes required to the program relate to the size of ${\mathbf{spline}}\mathbf{.}\mathbf{lamda}$ and the storage allocated to ${\mathbf{spline}}\mathbf{.}\mathbf{c}$ within the structure spline.

### 9.1  Program Text

Program Text (e02bdce.c)

### 9.2  Program Data

Program Data (e02bdce.d)

### 9.3  Program Results

Program Results (e02bdce.r)