NAG Library Function Document

1Purpose

nag_monotonic_deriv (e01bgc) evaluates a piecewise cubic Hermite interpolant and its first derivative at a set of points.

2Specification

 #include #include
 void nag_monotonic_deriv (Integer n, const double x[], const double f[], const double d[], Integer m, const double px[], double pf[], double pd[], NagError *fail)

3Description

nag_monotonic_deriv (e01bgc) evaluates a piecewise cubic Hermite interpolant, as computed by the NAG function nag_monotonic_interpolant (e01bec), at the points ${\mathbf{px}}\left[\mathit{i}\right]$, for $\mathit{i}=0,1,\dots ,m-1$. The first derivatives at the points are also computed. If any point lies outside the interval from ${\mathbf{x}}\left[0\right]$ to ${\mathbf{x}}\left[n-1\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, nag_monotonic_evaluate (e01bfc) should be used.
The function is derived from routine PCHFD in Fritsch (1982).
Fritsch F N (1982) PCHIP final specifications Report UCID-30194 Lawrence Livermore National Laboratory

5Arguments

1:    $\mathbf{n}$IntegerInput
On entry: n must be unchanged from the previous call of nag_monotonic_interpolant (e01bec).
2:    $\mathbf{x}\left[{\mathbf{n}}\right]$const doubleInput
3:    $\mathbf{f}\left[{\mathbf{n}}\right]$const doubleInput
4:    $\mathbf{d}\left[{\mathbf{n}}\right]$const doubleInput
On entry: x, f and d must be unchanged from the previous call of nag_monotonic_interpolant (e01bec).
5:    $\mathbf{m}$IntegerInput
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]$const doubleInput
On entry: the $m$ values of $x$ at which the interpolant is to be evaluated.
7:    $\mathbf{pf}\left[{\mathbf{m}}\right]$doubleOutput
On exit: ${\mathbf{pf}}\left[i\right]$ contains the value of the interpolant evaluated at the point ${\mathbf{px}}\left[\mathit{i}\right]$, for $\mathit{i}=0,1,\dots ,m-1$.
8:    $\mathbf{pd}\left[{\mathbf{m}}\right]$doubleOutput
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}=0,1,\dots ,m-1$.
9:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6Error Indicators and Warnings

NE_INT_ARG_LT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 1$.
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{\text{value}}〉$ : ${\mathbf{x}}\left[r-1\right]=〈\mathit{\text{value}}〉$, ${\mathbf{x}}\left[r\right]=〈\mathit{\text{value}}〉$.
The values of ${\mathbf{x}}\left[\mathit{r}\right]$, for $\mathit{r}=0,1,\dots ,n-1$, are not in strictly increasing order.
NW_EXTRAPOLATE
Warning – some points in array px lie outside the range ${\mathbf{x}}\left[0\right]\dots {\mathbf{x}}\left[n-1\right]$. Values at these points are unreliable as they have been computed by extrapolation.

7Accuracy

The computational errors in the arrays pf and pd should be negligible in most practical situations.

8Parallelism and Performance

nag_monotonic_deriv (e01bgc) is not threaded in any implementation.

The time taken by nag_monotonic_deriv (e01bgc) 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 nag_monotonic_deriv (e01bgc) with $m>1$ is more efficient than several calls with $m=1$.

10Example

This example program reads in values of n, x, f and d and calls nag_monotonic_deriv (e01bgc) to compute the values of the interpolant and its derivative at equally spaced points.

10.1Program Text

Program Text (e01bgce.c)

10.2Program Data

Program Data (e01bgce.d)

10.3Program Results

Program Results (e01bgce.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017