# NAG CL Interfacee01bec (dim1_​monotonic)

Settings help

CL Name Style:

## 1Purpose

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

## 2Specification

 #include
 void e01bec (Integer n, const double x[], const double f[], double d[], NagError *fail)
The function may be called by the names: e01bec, nag_interp_dim1_monotonic or nag_monotonic_interpolant.

## 3Description

e01bec estimates first derivatives at the set of data points $\left({x}_{\mathit{r}},{f}_{\mathit{r}}\right)$, for $\mathit{r}=0,1,\dots ,n-1$, 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 algorithm is derived from routine PCHIM in Fritsch (1982).
Values of the computed interpolant can subsequently be computed by calling e01bfc.

## 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]$const double 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}=0,1,\dots ,n-1$.
Constraint: ${\mathbf{x}}\left[r\right]<{\mathbf{x}}\left[r+1\right]$.
3: $\mathbf{f}\left[{\mathbf{n}}\right]$const double 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}=0,1,\dots ,n-1$.
4: $\mathbf{d}\left[{\mathbf{n}}\right]$double 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{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_INT_ARG_LT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
NE_NOT_MONOTONIC
On entry, ${\mathbf{x}}\left[r-1\right]\ge {\mathbf{x}}\left[r\right]$ for $r=⟨\mathit{value}⟩$: ${\mathbf{x}}\left[r-1\right]$, ${\mathbf{x}}\left[r\right]=⟨\mathit{values}⟩$.
The values of ${\mathbf{x}}\left[\mathit{r}\right]$, for $\mathit{r}=0,1,\dots ,n-1$, are not in strictly increasing order.

## 7Accuracy

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

## 8Parallelism and Performance

e01bec is not threaded in any implementation.

The time taken by e01bec is approximately proportional to $n$.
The values of the computed interpolant at the points $\left[\mathit{i}\right]$, for $\mathit{i}=0,1,\dots ,m-1$, may be obtained in the real array pf, of length at least $m$, by the call:
e01bfc (n, x, f, d, m, px, pf, &fail)
where n, x and f are the input arguments to e01bec and d is the output argument from e01bec.

## 10Example

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

### 10.1Program Text

Program Text (e01bece.c)

### 10.2Program Data

Program Data (e01bece.d)

### 10.3Program Results

Program Results (e01bece.r)