NAG Library Routine Document
D04AAF 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.
||XVAL, HBASE, DER(14), EREST(14), FUN
D04AAF 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 subroutine which evaluates
for all real
, and a step length
. The results
are based on
Internally D04AAF 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 routine 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, D04AAF 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
. In the absence of round-off error, the better approximations would be associated with the larger values of
. However, round-off error in function values has an increasingly contaminating effect for successively larger values of
. This routine proceeds to make a judicious choice between all the approximations in the following way.
For a specified value of
, and let
be such that
The routine returns:
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.
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
- 1: XVAL – REAL (KIND=nag_wp)Input
On entry: the point at which the derivatives are required, .
- 2: NDER – INTEGERInput
: must be set so that its absolute value is the highest order derivative required.
- All derivatives up to order are calculated.
- and NDER is even
- Only even order derivatives up to order are calculated.
- and NDER is odd
- Only odd order derivatives up to order are calculated.
- 3: HBASE – REAL (KIND=nag_wp)Input
: the initial step length which may be positive or negative. For advice on the choice of HBASE
see Section 8
- 4: DER() – REAL (KIND=nag_wp) arrayOutput
contains an approximation to the
th derivative of
, so long as the
th derivative is one of those requested by you when specifying NDER
. For other values of
- 5: EREST() – REAL (KIND=nag_wp) arrayOutput
: 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
- 6: FUN – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
must evaluate the function
at a specified point.
The specification of FUN
- 1: X – REAL (KIND=nag_wp)Input
: the value of the argument
If you have equally spaced tabular data, the following information may be useful:
||in any call of D04AAF the only values of for which will be required are and
, for ; and
|| is always computed, but it is disregarded when only odd order derivatives are required.
must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which D04AAF is called. Parameters denoted as Input
be changed by this procedure.
- 7: IFAIL – INTEGERInput/Output
must be set to
. If you are unfamiliar with this parameter you should refer to Section 3.3
in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
has a value zero on exit then D04AAF has terminated successfully, but before any use is made of a derivative
the value of
must be checked.
The accuracy of the results is problem dependent. An estimate of the accuracy of each result
is returned in
(see Sections 3
A basic feature of any floating point routine 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 routine 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 8
). The only hard and fast rule is that for a given
, 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.
The time taken by D04AAF 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 routine 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
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.
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:
||extreme choices of HBASE, either too large or too small, yield poor results;
||the quality of these results is adequately indicated by the values of EREST.
9.1 Program Text
Program Text (d04aafe.f90)
9.2 Program Data
9.3 Program Results
Program Results (d04aafe.r)