E01 Chapter Contents
E01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentE01BEF

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

E01BEF computes a monotonicity-preserving piecewise cubic Hermite interpolant to a set of data points.

## 2  Specification

 SUBROUTINE E01BEF ( N, X, F, D, IFAIL)
 INTEGER N, IFAIL REAL (KIND=nag_wp) X(N), F(N), D(N)

## 3  Description

E01BEF estimates first derivatives at the set of data points $\left({x}_{\mathit{r}},{f}_{\mathit{r}}\right)$, for $\mathit{r}=1,2,\dots ,n$, which determine a piecewise cubic Hermite interpolant to the data, that preserves monotonicity over ranges where the data points are monotonic. If the data points are only piecewise monotonic, the interpolant will have an extremum at each point where monotonicity switches direction. The estimates of the derivatives are computed by a formula due to Brodlie, which is described in Fritsch and Butland (1984), with suitable changes at the boundary points.
The routine is derived from routine PCHIM in Fritsch (1982).
Values of the computed interpolant, and of its first derivative and definite integral, can subsequently be computed by calling E01BFF, E01BGF and E01BHF, as described in Section 8.

## 4  References

Fritsch F N (1982) PCHIP final specifications Report UCID-30194 Lawrence Livermore National Laboratory
Fritsch F N and Butland J (1984) A method for constructing local monotone piecewise cubic interpolants SIAM J. Sci. Statist. Comput. 5 300–304

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of data points.
Constraint: ${\mathbf{N}}\ge 2$.
2:     X(N) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{X}}\left(\mathit{r}\right)$ must be set to ${x}_{\mathit{r}}$, the $\mathit{r}$th value of the independent variable (abscissa), for $\mathit{r}=1,2,\dots ,n$.
Constraint: ${\mathbf{X}}\left(r\right)<{\mathbf{X}}\left(r+1\right)$.
3:     F(N) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{F}}\left(\mathit{r}\right)$ must be set to ${f}_{\mathit{r}}$, the $\mathit{r}$th value of the dependent variable (ordinate), for $\mathit{r}=1,2,\dots ,n$.
4:     D(N) – REAL (KIND=nag_wp) arrayOutput
On exit: estimates of derivatives at the data points. ${\mathbf{D}}\left(r\right)$ contains the derivative at ${\mathbf{X}}\left(r\right)$.
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$
 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.

## 7  Accuracy

The computational errors in the array D should be negligible in most practical situations.

The time taken by E01BEF is approximately proportional to $n$.
The values of the computed interpolant at the points ${\mathbf{PX}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{M}}$, may be obtained in the real array PF, of length at least M, by the call:
```CALL E01BFF(N,X,F,D,M,PX,PF,IFAIL)
```
where N, X and F are the input parameters to E01BEF and D is the output parameter from E01BEF.
The values of the computed interpolant at the points ${\mathbf{PX}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{M}}$, together with its first derivatives, may be obtained in the real arrays PF and PD, both of length at least M, by the call:
```CALL E01BGF(N,X,F,D,M,PX,PF,PD,IFAIL)
```
where N, X, F and D are as described above.
The value of the definite integral of the interpolant over the interval A to B can be obtained in the real variable PINT by the call:
```CALL E01BHF(N,X,F,D,A,B,PINT,IFAIL)
```
where N, X, F and D are as described above.

## 9  Example

This example reads in a set of data points, calls E01BEF to compute a piecewise monotonic interpolant, and then calls E01BFF to evaluate the interpolant at equally spaced points.

### 9.1  Program Text

Program Text (e01befe.f90)

### 9.2  Program Data

Program Data (e01befe.d)

### 9.3  Program Results

Program Results (e01befe.r)