# NAG FL Interfacee01bgf (dim1_​monotonic_​deriv)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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

## 2Specification

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

## 3Description

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

## 4References

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

## 5Arguments

1: $\mathbf{n}$Integer Input
2: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
3: $\mathbf{f}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
4: $\mathbf{d}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: n, x, f and d must be unchanged from the previous call of e01bef.
5: $\mathbf{m}$Integer Input
On entry: $m$, the number of points at which the interpolant is to be evaluated.
Constraint: ${\mathbf{m}}\ge 1$.
6: $\mathbf{px}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Input
On entry: the $m$ values of $x$ at which the interpolant is to be evaluated.
7: $\mathbf{pf}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
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: $\mathbf{pd}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
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: $\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}}=3$
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
${\mathbf{ifail}}=4$
Warning – some points in array px lie outside the range ${\mathbf{x}}\left(1\right)\cdots {\mathbf{x}}\left({\mathbf{n}}\right)$. Values at these points are unreliable because computed by extrapolation.
${\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 arrays pf and pd should be negligible in most practical situations.

## 8Parallelism and Performance

e01bgf is not threaded in any implementation.

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

## 10Example

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.

### 10.1Program Text

Program Text (e01bgfe.f90)

### 10.2Program Data

Program Data (e01bgfe.d)

### 10.3Program Results

Program Results (e01bgfe.r)