hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_interp_1d_monotonic (e01be)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_interp_1d_monotonic (e01be) computes a monotonicity-preserving piecewise cubic Hermite interpolant to a set of data points.

Syntax

[d, ifail] = e01be(x, f, 'n', n)
[d, ifail] = nag_interp_1d_monotonic(x, f, 'n', n)

Description

nag_interp_1d_monotonic (e01be) estimates first derivatives at the set of data points xr,fr, for r=1,2,,n, 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 function is derived from function PCHIM in Fritsch (1982).
Values of the computed interpolant, and of its first derivative and definite integral, can subsequently be computed by calling nag_interp_1d_monotonic_eval (e01bf), nag_interp_1d_monotonic_deriv (e01bg) and nag_interp_1d_monotonic_intg (e01bh), as described in Further Comments.

References

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

Parameters

Compulsory Input Parameters

1:     xn – double array
xr must be set to xr, the rth value of the independent variable (abscissa), for r=1,2,,n.
Constraint: xr<xr+1.
2:     fn – double array
fr must be set to fr, the rth value of the dependent variable (ordinate), for r=1,2,,n.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the arrays x, f. (An error is raised if these dimensions are not equal.)
n, the number of data points.
Constraint: n2.

Output Parameters

1:     dn – double array
Estimates of derivatives at the data points. dr contains the derivative at xr.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,n<2.
   ifail=2
The values of xr, for r=1,2,,n, are not in strictly increasing order.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

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

Further Comments

The time taken by nag_interp_1d_monotonic (e01be) is approximately proportional to n.
The values of the computed interpolant at the points pxi, for i=1,2,,m, may be obtained in the double array pf, of length at least m, by the call:
[pf, ifail] = e01bf(x, f, d, px);
where n, x and f are the input arguments to nag_interp_1d_monotonic (e01be) and d is the output argument from nag_interp_1d_monotonic (e01be).
The values of the computed interpolant at the points pxi, for i=1,2,,m, together with its first derivatives, may be obtained in the double arrays pf and pd, both of length at least m, by the call:
[pf, pd, ifail] = e01bg(x, f, d, px);
where n, x, f and d are as described above.
The value of the definite integral of the interpolant over the interval a to b can be obtained in the double variable pint by the call:
[pint, ifail] = e01bh(x, f, d, a, b);
where n, x, f and d are as described above.

Example

This example reads in a set of data points, calls nag_interp_1d_monotonic (e01be) to compute a piecewise monotonic interpolant, and then calls nag_interp_1d_monotonic_eval (e01bf) to evaluate the interpolant at equally spaced points.
function e01be_example


fprintf('e01be example results\n\n');

x = [7.99 8.09    8.19    8.7     9.2     10      12      15      20];
f = [0 2.7643e-05 0.04375 0.16918 0.46943 0.94374 0.99864 0.99992 0.99999];

[d, ifail] = e01be(x, f);

m = 11;
dx = (x(end)-x(1))/(m-1);
px = [x(1):dx:x(end)];

[pf, ifail] = e01bf(x, f, d, px);

fprintf('\n                Interpolated\n     Abscissa          Value\n');
fprintf('%13.4f  %13.4f\n', [px' pf]')


e01be example results


                Interpolated
     Abscissa          Value
       7.9900         0.0000
       9.1910         0.4640
      10.3920         0.9645
      11.5930         0.9965
      12.7940         0.9992
      13.9950         0.9998
      15.1960         0.9999
      16.3970         1.0000
      17.5980         1.0000
      18.7990         1.0000
      20.0000         1.0000

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015