# NAG Library Routine Document

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e01bhf ( n, x, f, d, a, b, pint,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(n), f(n), d(n), a, b Real (Kind=nag_wp), Intent (Out) :: pint
#include <nagmk26.h>
 void e01bhf_ (const Integer *n, const double x[], const double f[], const double d[], const double *a, const double *b, double *pint, Integer *ifail)

## 3Description

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

## 4References

Fritsch F N (1982) PCHIP final specifications Report UCID-30194 Lawrence Livermore National Laboratory

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
2:     $\mathbf{x}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
3:     $\mathbf{f}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
4:     $\mathbf{d}\left({\mathbf{n}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: n, x, f and d must be unchanged from the previous call of e01bef.
5:     $\mathbf{a}$ – Real (Kind=nag_wp)Input
6:     $\mathbf{b}$ – Real (Kind=nag_wp)Input
On entry: the interval $\left[a,b\right]$ over which integration is to be performed.
7:     $\mathbf{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:     $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=2$
On entry, $r=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left(r-1\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{x}}\left(r\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{x}}\left(r-1\right)<{\mathbf{x}}\left(r\right)$ for all $r$.
${\mathbf{ifail}}=3$
Warning – either a or b is outside the range ${\mathbf{x}}\left(1\right)\cdots {\mathbf{x}}\left({\mathbf{n}}\right)$. The result has been computed by extrapolation and is unreliable. ${\mathbf{a}}=〈\mathit{\text{value}}〉$ ${\mathbf{b}}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

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

## 8Parallelism and Performance

e01bhf is not threaded in any implementation.

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

## 10Example

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.

### 10.1Program Text

Program Text (e01bhfe.f90)

### 10.2Program Data

Program Data (e01bhfe.d)

### 10.3Program Results

Program Results (e01bhfe.r)