E01 Chapter Contents
E01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE01BHF

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

E01BHF evaluates the definite integral of a piecewise cubic Hermite interpolant over the interval $\left[a,b\right]$.

## 2  Specification

 SUBROUTINE E01BHF ( N, X, F, D, A, B, PINT, IFAIL)
 INTEGER N, IFAIL REAL (KIND=nag_wp) X(N), F(N), D(N), A, B, PINT

## 3  Description

E01BHF evaluates the definite integral of a piecewise cubic Hermite interpolant, as computed by E01BEF, over the interval $\left[a,b\right]$.
If either $a$ or $b$ lies outside the interval from ${\mathbf{X}}\left(1\right)$ to ${\mathbf{X}}\left({\mathbf{N}}\right)$ computation of the integral involves extrapolation and a warning is returned.
The routine is derived from routine PCHIA in Fritsch (1982).
Fritsch F N (1982) PCHIP final specifications Report UCID-30194 Lawrence Livermore National Laboratory

## 5  Parameters

1:     N – INTEGERInput
2:     X(N) – REAL (KIND=nag_wp) arrayInput
3:     F(N) – REAL (KIND=nag_wp) arrayInput
4:     D(N) – REAL (KIND=nag_wp) arrayInput
On entry: N, X, F and D must be unchanged from the previous call of E01BEF.
5:     A – REAL (KIND=nag_wp)Input
6:     B – REAL (KIND=nag_wp)Input
On entry: the interval $\left[a,b\right]$ over which integration is to be performed.
7:     PINT – REAL (KIND=nag_wp)Output
On exit: the value of the definite integral of the interpolant over the interval $\left[a,b\right]$.
8:     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$
 On entry, ${\mathbf{N}}<2$.
${\mathbf{IFAIL}}=2$
The values of ${\mathbf{X}}\left(\mathit{r}\right)$, for $\mathit{r}=1,2,\dots ,{\mathbf{N}}$, are not in strictly increasing order.
${\mathbf{IFAIL}}=3$
On entry, at least one of A or B lies outside the interval [${\mathbf{X}}\left(1\right),{\mathbf{X}}\left({\mathbf{N}}\right)$], and extrapolation was performed to compute the integral. The value returned is therefore unreliable.

## 7  Accuracy

The computational error in the value returned for PINT should be negligible in most practical situations.

The time taken by E01BHF is approximately proportional to the number of data points included within the interval $\left[a,b\right]$.

## 9  Example

This example reads in values of N, X, F and D. It then reads in pairs of values for A and B, and evaluates the definite integral of the interpolant over the interval $\left[{\mathbf{A}},{\mathbf{B}}\right]$ until end-of-file is reached.

### 9.1  Program Text

Program Text (e01bhfe.f90)

### 9.2  Program Data

Program Data (e01bhfe.d)

### 9.3  Program Results

Program Results (e01bhfe.r)