E01 Chapter Contents
E01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE01BGF

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

E01BGF evaluates a piecewise cubic Hermite interpolant and its first derivative at a set of points.

## 2  Specification

 SUBROUTINE E01BGF ( N, X, F, D, M, PX, PF, PD, IFAIL)
 INTEGER N, M, IFAIL REAL (KIND=nag_wp) X(N), F(N), D(N), PX(M), PF(M), PD(M)

## 3  Description

E01BGF evaluates a piecewise cubic Hermite interpolant, as computed by E01BEF, at the points ${\mathbf{PX}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,m$. The first derivatives at the points are also computed. If any point lies outside the interval from ${\mathbf{X}}\left(1\right)$ to ${\mathbf{X}}\left({\mathbf{N}}\right)$, values of the interpolant and its derivative are extrapolated from the nearest extreme cubic, and a warning is returned.
If values of the interpolant only, and not of its derivative, are required, E01BFF should be used.
The routine is derived from routine PCHFD in Fritsch (1982).

## 4  References

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:     M – INTEGERInput
On entry: $m$, the number of points at which the interpolant is to be evaluated.
Constraint: ${\mathbf{M}}\ge 1$.
6:     PX(M) – REAL (KIND=nag_wp) arrayInput
On entry: the $m$ values of $x$ at which the interpolant is to be evaluated.
7:     PF(M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{PF}}\left(\mathit{i}\right)$ contains the value of the interpolant evaluated at the point ${\mathbf{PX}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,m$.
8:     PD(M) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{PD}}\left(\mathit{i}\right)$ contains the first derivative of the interpolant evaluated at the point ${\mathbf{PX}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,m$.
9:     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, ${\mathbf{M}}<1$.
${\mathbf{IFAIL}}=4$
At least one of the points ${\mathbf{PX}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{M}}$, lies outside the interval [${\mathbf{X}}\left(1\right),{\mathbf{X}}\left({\mathbf{N}}\right)$], and extrapolation was performed at all such points. Values computed at these points may be very unreliable.

## 7  Accuracy

The computational errors in the arrays PF and PD should be negligible in most practical situations.

The time taken by E01BGF is approximately proportional to the number of evaluation points, $m$. The evaluation will be most efficient if the elements of PX are in nondecreasing order (or, more generally, if they are grouped in increasing order of the intervals $\left[{\mathbf{X}}\left(r-1\right),{\mathbf{X}}\left(r\right)\right]$). A single call of E01BGF with $m>1$ is more efficient than several calls with $m=1$.

## 9  Example

This example reads in values of N, X, F and D, and calls E01BGF to compute the values of the interpolant and its derivative at equally spaced points.

### 9.1  Program Text

Program Text (e01bgfe.f90)

### 9.2  Program Data

Program Data (e01bgfe.d)

### 9.3  Program Results

Program Results (e01bgfe.r)