NAG Library Routine Document

e01bff  (dim1_monotonic_eval)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

e01bff evaluates a piecewise cubic Hermite interpolant at a set of points.

2
Specification

Fortran Interface
Subroutine e01bff ( n, x, f, d, m, px, pf, ifail)
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)
C Header Interface
#include nagmk26.h
void  e01bff_ ( const Integer *n, const double x[], const double f[], const double d[], const Integer *m, const double px[], double pf[], Integer *ifail)

3
Description

e01bff evaluates a piecewise cubic Hermite interpolant, as computed by e01bef, at the points pxi, for i=1,2,,m. If any point lies outside the interval from x1 to xn, a value is extrapolated from the nearest extreme cubic, and a warning is returned.
The routine is derived from routine PCHFE in Fritsch (1982).

4
References

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

5
Arguments

1:     n – IntegerInput
2:     xn – Real (Kind=nag_wp) arrayInput
3:     fn – Real (Kind=nag_wp) arrayInput
4:     dn – Real (Kind=nag_wp) arrayInput
On entry: n, x, f and d must be unchanged from the previous call of e01bef.
5:     m – IntegerInput
On entry: m, the number of points at which the interpolant is to be evaluated. If any point lies outside the interval from x1) to xn, a value is extrapolated from the nearest extreme cubic, and a warning is returned. The extrapolation simply extends the final cubic at each end.
Constraint: m1.
6:     pxm – Real (Kind=nag_wp) arrayInput
On entry: the m values of x at which the interpolant is to be evaluated.
7:     pfm – Real (Kind=nag_wp) arrayOutput
On exit: pfi contains the value of the interpolant evaluated at the point pxi, for i=1,2,,m.
8:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 argument, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6
Error Indicators and Warnings

If on entry 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:
ifail=1
On entry,n<2.
ifail=2
The values of xr, for r=1,2,,n, are not in strictly increasing order.
ifail=3
On entry,m<1.
ifail=4
At least one of the points pxi, for i=1,2,,m, lies outside the interval [x1,xn], and extrapolation was performed at all such points. Values computed at such points may be very unreliable.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
ifail=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
ifail=-999
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

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

8
Parallelism and Performance

e01bff is not threaded in any implementation.

9
Further Comments

The time taken by e01bff 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 xr-1,xr). A single call of e01bff with m>1 is more efficient than several calls with m=1.
As documented above, this routine will use extrapolation if presented with evaluation points outside the region x1,xn . Since such extrapolated values are computed simply by extending the cubic approximation at each end interval, the values may not be suitable for all purposes. If you need more control over how values outside the original region are calculated, consider the following possible procedures for degree 0, 1 and 2 extrapolation.
(i) Flat extrapolation
  • For x<x1 choose f = f1;
  • for x>xn choose f=fn.
(ii) Linear extrapolation
  • For x<x1 , call e01bgf using px1 = x1  to obtain pd1 , then choose f = pd1 × x- x1 + f1 ;
  • for x>xn, call e01bgf using px1 = xn  to obtain pdn , then choose f= pd n × x- xn + fn .
(iii) Quadratic extrapolation
  • For x<x1 , call e01bgf to obtain derivative values pd1 and pd2 at x1 and x2,
    • if pd2 pd1  revert to linear extrapolation (ii),
    • otherwise let l1x = x-x1 , l2x = x-x2  and c=1/ x1 - x2 , then choose fx = pd1 × l1 x × l2 x × c-f1 × l2x × l1x + l1 x2 × c2 + f2 × l1x × c 2 ;
  • for x>xn, call e01bgf to obtain derivative values pdn and pdn-1 at xn and xn-1,
    • if pdn-1 pdn  revert to linear extrapolation (ii),
    • otherwise let lnx = x-xn , ln-1 x = x - xn-1  and c=1/ xn- xn-1 , then choose fx = pdn × ln x × ln-1 x × c-fn × ln-1 x × ln x + ln xn-1 × c2 + fn-1 × lnx × c 2 .

10
Example

This example reads in values of n, x, f and d, and then calls e01bff to evaluate the interpolant at equally spaced points.

10.1
Program Text

Program Text (e01bffe.f90)

10.2
Program Data

Program Data (e01bffe.d)

10.3
Program Results

Program Results (e01bffe.r)

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