NAG FL Interface
e01bff (dim1_​monotonic_​eval)

Settings help

FL Name Style:


FL Specification Language:


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 <nag.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)
The routine may be called by the names e01bff or nagf_interp_dim1_monotonic_eval.

3 Description

e01bff evaluates a piecewise cubic Hermite interpolant, as computed by e01bef, at the points px(i), for i=1,2,,m. If any point lies outside the interval from x(1) to x(n), 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 Integer Input
2: x(n) Real (Kind=nag_wp) array Input
3: f(n) Real (Kind=nag_wp) array Input
4: d(n) Real (Kind=nag_wp) array Input
On entry: n, x, f and d must be unchanged from the previous call of e01bef.
5: m Integer Input
On entry: m, the number of points at which the interpolant is to be evaluated. If any point lies outside the interval from x(1)) to x(n), 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: px(m) Real (Kind=nag_wp) array Input
On entry: the m values of x at which the interpolant is to be evaluated.
7: pf(m) Real (Kind=nag_wp) array Output
On exit: pf(i) contains the value of the interpolant evaluated at the point px(i), for i=1,2,,m.
8: 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 -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=value.
Constraint: n2.
ifail=2
On entry, r=value, x(r-1)=value and x(r)=value.
Constraint: x(r-1)<x(r) for all r.
ifail=3
On entry, m=value.
Constraint: m1.
ifail=4
Warning – some points in array px lie outside the range x(1)x(n). Values at these points are unreliable because computed by extrapolation.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
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.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

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

8 Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
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 [x(r-1),x(r)]). 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.
  1. (i) Flat extrapolation
    • For x<x1 choose f = f(1);
    • for x>xn choose f=f(n).
  2. (ii) Linear extrapolation
    • For x<x1 , call e01bgf using px(1) = x(1) to obtain pd(1) , then choose f = pd(1) × (x-x(1)) + f(1) ;
    • for x>xn, call e01bgf using px(1) = x(n) to obtain pd(n) , then choose f= pd(n) × (x-x(n)) + f(n) .
  3. (iii) Quadratic extrapolation
    • For x<x1 , call e01bgf to obtain derivative values pd(1) and pd(2) at x1 and x2,
      • if |pd(2)| |pd(1)| revert to linear extrapolation (ii),
      • otherwise let l1(x) = (x-x1) , l2(x) = (x-x2) and c=1/ (x1-x2) , then choose f(x) = pd(1) × l1 (x) × l2 (x) × c-f(1) × l2(x) × (l1(x)+l1(x2)) × c2 + f(2) × [l1(x)×c] 2 ;
    • for x>xn, call e01bgf to obtain derivative values pd(n) and pd(n-1) at xn and xn-1,
      • if |pd(n-1)| |pd(n)| revert to linear extrapolation (ii),
      • otherwise let ln(x) = (x-xn) , ln-1 (x) = (x-xn-1) and c=1/ (xn-xn-1) , then choose f(x) = pd(n) × ln (x) × ln-1 (x) × c-f(n) × ln-1 (x) × (ln(x)+ln(xn-1)) × c2 + f(n-1) × [ln(x)×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)