NAG Library Function Document
nag_numdiff_1d_real_eval (d04bac)
1 Purpose
nag_numdiff_1d_real_eval (d04bac) 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
nag_numdiff_1d_real (d04aac), in that the abscissae and corresponding function values must be calculated before this function is called. The abscissae may be generated using
nag_numdiff_1d_real_absci (d04bbc).
2 Specification
#include <nag.h> |
#include <nagd04.h> |
void |
nag_numdiff_1d_real_eval (const double xval[],
const double fval[],
double der[],
double erest[],
NagError *fail) |
|
3 Description
nag_numdiff_1d_real_eval (d04bac) 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 nag_numdiff_1d_real_eval (d04bac) as the vectors
xval and
fval respectively. The step size
is derived from the abscissae in
xval. See
Section 9 for a discussion of how the derived value of
may affect the results of nag_numdiff_1d_real_eval (d04bac). The order in which the abscissae and function values are stored in
xval and
fval 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
nag_numdiff_1d_real_absci (d04bbc) if desired. For each derivative nag_numdiff_1d_real_eval (d04bac) 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:
, |
|
, |
|
|
, |
on the basis of performance statistics.
The even order derivatives are calculated in a precisely analogous manner.
4 References
Lyness J N and Moler C B (1969) Generalised Romberg methods for integrals of derivatives Numer. Math. 14 1–14
5 Arguments
- 1:
– const doubleInput
-
On entry: the abscissae at which the function has been evaluated, as described in
Section 3. These can be generated by calling
nag_numdiff_1d_real_absci (d04bbc). The order of the abscissae is irrelevant.
Constraint:
the values in
xval must span the set
, for
.
- 2:
– const doubleInput
-
On entry: must contain the function value at , for .
- 3:
– doubleOutput
-
On exit: the 14 derivative estimates.
- 4:
– doubleOutput
-
On exit: the 14 error estimates for the derivatives.
- 5:
– NagError *Input/Output
-
The NAG error argument (see
Section 2.7 in How to Use the NAG Library and its Documentation).
6 Error Indicators and Warnings
- NE_ALLOC_FAIL
-
Dynamic memory allocation failed.
See
Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
- NE_BAD_PARAM
-
On entry, argument had an illegal value.
- 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.
An unexpected error has been triggered by this function. Please contact
NAG.
See
Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
- NE_NO_LICENCE
-
Your licence key may have expired or may not have been installed correctly.
See
Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
- NE_SPACING_INCORRECT
-
On entry, the values of
xval are not correctly spaced.
Derived
.
- NE_TOO_SMALL
-
The derived is below tolerance.
Derived is required. Derived .
7 Accuracy
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 nag_numdiff_1d_real_eval (d04bac) 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 step length
(see
Section 9). The only hard and fast rule is that for a given objective function and
, 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.
8 Parallelism and Performance
nag_numdiff_1d_real_eval (d04bac) is not threaded in any implementation.
The results depend very critically on the choice of the step length . The overall accuracy is diminished as becomes small (because of the effect of round-off error) and as becomes large (because the discretization error also becomes large). If this function is used four or five times with different values of one can find a reasonably good value. A process in which the value of is successively halved (or doubled) is usually quite effective. Experience has shown that in cases in which the Taylor series for the objective function about 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.
As mentioned, the order of the abscissae in
xval does not matter, provided the corresponding values of
fval are ordered identically. If the abscissae are generated by
nag_numdiff_1d_real_absci (d04bbc), then they will be in ascending order. In particular, the target abscissa
will be stored in
.
10 Example
This example evaluates the derivatives of the polygamma function, calculated using
nag_real_polygamma (s14aec), and compares the first
derivatives calculated to those found using
nag_real_polygamma (s14aec).
10.1 Program Text
Program Text (d04bace.c)
10.2 Program Data
None.
10.3 Program Results
Program Results (d04bace.r)