# naginterfaces.library.numdiff.rcomm¶

naginterfaces.library.numdiff.rcomm(xval, fval)[source]

rcomm calculates a set of derivatives (up to order ) of a function at a point with respect to a single variable. A corresponding set of error estimates is also returned. Derivatives are calculated using an extension of the Neville algorithm. This function differs from fwd(), in that the abscissae and corresponding function values must be calculated before this function is called. The abscissae may be generated using sample().

For full information please refer to the NAG Library document for d04ba

https://www.nag.com/numeric/nl/nagdoc_29/flhtml/d04/d04baf.html

Parameters
xvalfloat, array-like, shape

The abscissae at which the function has been evaluated, as described in Notes. These can be generated by calling sample(). The order of the abscissae is irrelevant.

fvalfloat, array-like, shape

must contain the function value at , for .

Returns
derfloat, ndarray, shape

The derivative estimates.

erestfloat, ndarray, shape

The error estimates for the derivatives.

Raises
NagValueError
(errno )

The derived is below tolerance.

Derived is required. Derived .

(errno )

On entry, the values of are not correctly spaced.

Derived .

Notes

rcomm provides a set of approximations:

to the derivatives:

of a real valued function at a real abscissa , together with a set of error estimates:

which hopefully satisfy:

The results and are based on function values:

The abscissae and the corresponding function values should be passed into rcomm as the vectors and respectively. The step size is derived from the abscissae in . See Further Comments for a discussion of how the derived value of may affect the results of rcomm. The order in which the abscissae and function values are stored in and is irrelevant, provided that the function value at any given index corresponds to the value of the abscissa at the same index. Abscissae may be automatically generated using sample() if desired. For each derivative rcomm employs an extension of the Neville Algorithm (see Lyness and Moler (1969)) to obtain a selection of approximations.

For example, for odd derivatives, this function calculates a set of numbers:

each of which is an approximation to . A specific approximation is of polynomial degree and is based on polynomial interpolation using function values , for . In the absence of round-off error, the better approximations would be associated with the larger values of and of . However, round-off error in function values has an increasingly contaminating effect for successively larger values of . This function proceeds to make a judicious choice between all the approximations in the following way.

For a specified value of , let:

where and , for , and let be such that , for .

This function returns:

and

where is a safety factor which has been assigned the values:

 Kj=1, j≤9 Kj=1.5, j=10,11 Kj=2 j≥12,

on the basis of performance statistics.

The even order derivatives are calculated in a precisely analogous manner.

References

Lyness, J N and Moler, C B, 1969, Generalised Romberg methods for integrals of derivatives, Numer. Math. (14), 1–14