# naginterfaces.library.numdiff.fwd¶

naginterfaces.library.numdiff.fwd(xval, nder, hbase, f, data=None)[source]

fwd calculates a set of derivatives (up to order ) of a function of one real variable at a point, together with a corresponding set of error estimates, using an extension of the Neville algorithm.

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

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

Parameters
xvalfloat

The point at which the derivatives are required, .

nderint

Must be set so that its absolute value is the highest order derivative required.

All derivatives up to order are calculated.

and is even

Only even order derivatives up to order are calculated.

and is odd

Only odd order derivatives up to order are calculated.

hbasefloat

The initial step length which may be positive or negative. For advice on the choice of see Further Comments.

fcallable retval = f(x, data=None)

must evaluate the function at a specified point.

Parameters
xfloat

The value of the argument .

If you have equally spaced tabular data, the following information may be useful:

1. in any call of fwd the only values of for which will be required are and , for ; and

2. is always computed, but it is disregarded when only odd order derivatives are required.

dataarbitrary, optional, modifiable in place

User-communication data for callback functions.

Returns
retvalfloat

The value of at the specified point.

dataarbitrary, optional

User-communication data for callback functions.

Returns
derfloat, ndarray, shape

contains an approximation to the th derivative of at , so long as the th derivative is one of those requested by you when specifying . For other values of , is unused.

erestfloat, ndarray, shape

An estimate of the absolute error in the corresponding result so long as the th derivative is one of those requested by you when specifying . The sign of is positive unless the result is questionable. It is set negative when or when for some other reason there is doubt about the validity of the result (see Exceptions). For other values of , is unused.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

Notes

fwd 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:

You must provide the value of , a value of (which is reduced to should it exceed ), a function which evaluates for all real , and a step length . The results and are based on function values:

Internally fwd calculates the odd order derivatives and the even order derivatives separately. There is an option you can use for restricting the calculation to only odd (or even) order derivatives. For each derivative the function employs an extension of the Neville Algorithm (see Lyness and Moler (1969)) to obtain a selection of approximations.

For example, for odd derivatives, based on function values, fwd 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 .

The 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, 1966, van der Monde systems and numerical differentiation, Numer. Math. (8), 458–464

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