d04aac 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.
The function may be called by the names: d04aac, nag_numdiff_fwd or nag_numdiff_1d_real.
3Description
d04aac 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 d04aac 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, d04aac 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:
,
,
,
on the basis of performance statistics.
The even order derivatives are calculated in a precisely analogous manner.
4References
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
5Arguments
1: – doubleInput
On entry: the point at which the derivatives are required, .
2: – IntegerInput
On entry: must be set so that its absolute value is the highest order derivative required.
Only odd order derivatives up to order are calculated.
3: – doubleInput
On entry: the initial step length which may be positive or negative. For advice on the choice of hbase see Section 9.
Constraint:
.
4: – doubleOutput
On exit: contains an approximation to the th derivative of at , so long as the th derivative is one of those requested by you when specifying nder. For other values of , is unused.
5: – doubleOutput
On exit: 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 nder. 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 Section 6). For other values of , is unused.
6: – function, supplied by the userExternal Function
f must evaluate the function at a specified point.
If you have equally spaced tabular data, the following information may be useful:
(i)in any call of d04aac the only values of for which will be required are and
, for ; and
(ii) is always computed, but it is disregarded when only odd order derivatives are required.
2: – Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to f.
user – double *
iuser – Integer *
p – Pointer
The type Pointer will be void *. Before calling d04aac you may allocate memory and initialize these pointers with various quantities for use by f when called from d04aac (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
Note:f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d04aac. If your code inadvertently does return any NaNs or infinities, d04aac is likely to produce unexpected results.
7: – Nag_Comm *
The NAG communication argument (see Section 3.1.1 in the Introduction to the NAG Library CL Interface).
8: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument had an illegal value.
NE_INT
On entry, .
Constraint: .
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_REAL
On entry, .
Constraint: .
7Accuracy
The accuracy of the results is problem dependent. An estimate of the accuracy of each result is returned in (see Sections 3, 5 and 9).
A basic feature of any floating-point function for numerical differentiation based on real function values on the real axis is that successively higher order derivative approximations are successively less accurate. It is expected that in most cases will be unusable. As an aid to this process, the sign of is set negative when the estimated absolute error is greater than the approximate derivative itself, i.e., when the approximate derivative may be so inaccurate that it may even have the wrong sign. It is also set negative in some other cases when information available to the function indicates that the corresponding value of is questionable.
The actual values in erest depend on the accuracy of the function values, the properties of the machine arithmetic, the analytic properties of the function being differentiated and the user-supplied step length hbase (see Section 9). The only hard and fast rule is that for a given and hbase, the values of increase with increasing . The limit of is dictated by experience. Only very rarely can one obtain meaningful approximations for higher order derivatives on conventional machines.
8Parallelism and Performance
d04aac is not threaded in any implementation.
9Further Comments
The time taken by d04aac depends on the time spent for function evaluations. Otherwise the time is roughly equivalent to that required to evaluate the function times and calculate a finite difference table having about entries in total.
The results depend very critically on the choice of the user-supplied step length hbase. The overall accuracy is diminished as hbase becomes small (because of the effect of round-off error) and as hbase becomes large (because the discretization error also becomes large). If the function is used four or five times with different values of hbase one can find a reasonably good value. A process in which the value of hbase is successively halved (or doubled) is usually quite effective. Experience has shown that in cases in which the Taylor series for about xval has a finite radius of convergence , the choices of are not likely to lead to good results. In this case some function values lie outside the circle of convergence.
10Example
This example evaluates the odd-order derivatives of the function:
up to order at the point . Several different values of hbase are used, to illustrate that:
(i)extreme choices of hbase, either too large or too small, yield poor results;
(ii)the quality of these results is adequately indicated by the values of erest.