# NAG FL Interfacee01bef (dim1_​monotonic)

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine e01bef ( n, x, f, d,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(n), f(n) Real (Kind=nag_wp), Intent (Out) :: d(n)
#include <nag.h>
 void e01bef_ (const Integer *n, const double x[], const double f[], double d[], Integer *ifail)
The routine may be called by the names e01bef or nagf_interp_dim1_monotonic.

## 3Description

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

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of data points.
Constraint: ${\mathbf{n}}\ge 2$.
2: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{f}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
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: $\mathbf{d}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: estimates of derivatives at the data points. ${\mathbf{d}}\left(r\right)$ contains the derivative at ${\mathbf{x}}\left(r\right)$.
5: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 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}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

e01bef is not threaded in any implementation.

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 arguments to e01bef and d is the output argument 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.

## 10Example

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.

### 10.1Program Text

Program Text (e01befe.f90)

### 10.2Program Data

Program Data (e01befe.d)

### 10.3Program Results

Program Results (e01befe.r)