NAG FL Interface
d01rgf (dim1_fin_gonnet_vec)
1
Purpose
d01rgf is a general purpose integrator which calculates an approximation to the integral of a function
over a finite interval
:
The routine is suitable as a general purpose integrator, and can be used when the integrand has singularities and infinities. In particular, the routine can continue if the subroutine
f explicitly returns a quiet or signalling NaN or a signed infinity.
2
Specification
Fortran Interface
Subroutine d01rgf ( |
a, b, f, epsabs, epsrel, dinest, errest, nevals, iuser, ruser, ifail) |
Integer, Intent (Inout) |
:: |
iuser(*), ifail |
Integer, Intent (Out) |
:: |
nevals |
Real (Kind=nag_wp), Intent (In) |
:: |
a, b, epsabs, epsrel |
Real (Kind=nag_wp), Intent (Inout) |
:: |
ruser(*) |
Real (Kind=nag_wp), Intent (Out) |
:: |
dinest, errest |
External |
:: |
f |
|
C Header Interface
#include <nag.h>
void |
d01rgf_ (const double *a, const double *b, void (NAG_CALL *f)(const double x[], const Integer *nx, double fv[], Integer *iflag, Integer iuser[], double ruser[]), const double *epsabs, const double *epsrel, double *dinest, double *errest, Integer *nevals, Integer iuser[], double ruser[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
d01rgf_ (const double &a, const double &b, void (NAG_CALL *f)(const double x[], const Integer &nx, double fv[], Integer &iflag, Integer iuser[], double ruser[]), const double &epsabs, const double &epsrel, double &dinest, double &errest, Integer &nevals, Integer iuser[], double ruser[], Integer &ifail) |
}
|
The routine may be called by the names d01rgf or nagf_quad_dim1_fin_gonnet_vec.
3
Description
d01rgf uses the algorithm described in
Gonnet (2010). It is an adaptive algorithm, similar to the QUADPACK routine QAGS (see
Piessens et al. (1983), see also
d01raf) but includes significant differences regarding how the integrand is represented, how the integration error is estimated and how singularities and divergent integrals are treated. The local error estimation is described in
Gonnet (2010).
d01rgf requires a subroutine to evaluate the integrand at an array of different points and is therefore amenable to parallel execution.
4
References
Gonnet P (2010) Increasing the reliability of adaptive quadrature using explicit interpolants ACM Trans. Math. software 37 26
Piessens R, de Doncker–Kapenga E, Überhuber C and Kahaner D (1983) QUADPACK, A Subroutine Package for Automatic Integration Springer–Verlag
5
Arguments
-
1:
– Real (Kind=nag_wp)
Input
-
On entry: , the lower limit of integration.
-
2:
– Real (Kind=nag_wp)
Input
-
On entry:
, the upper limit of integration. It is not necessary that
.
Note: if , the routine will immediately return , and .
-
3:
– Subroutine, supplied by the user.
External Procedure
-
f must return the value of the integrand
at a set of points.
The specification of
f is:
Fortran Interface
Integer, Intent (In) |
:: |
nx |
Integer, Intent (Inout) |
:: |
iflag, iuser(*) |
Real (Kind=nag_wp), Intent (In) |
:: |
x(nx) |
Real (Kind=nag_wp), Intent (Inout) |
:: |
ruser(*) |
Real (Kind=nag_wp), Intent (Out) |
:: |
fv(nx) |
|
C Header Interface
void |
f_ (const double x[], const Integer *nx, double fv[], Integer *iflag, Integer iuser[], double ruser[]) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
f_ (const double x[], const Integer &nx, double fv[], Integer &iflag, Integer iuser[], double ruser[]) |
}
|
-
1:
– Real (Kind=nag_wp) array
Input
-
On entry: the abscissae,
, for , at which function values are required.
-
2:
– Integer
Input
-
On entry: the number of abscissae at which a function value is required.
-
3:
– Real (Kind=nag_wp) array
Output
-
On exit:
fv must contain the values of the integrand
.
for all
.
-
4:
– Integer
Input/Output
-
On entry: .
On exit: set to force an immediate exit with .
-
5:
– Integer array
User Workspace
-
6:
– Real (Kind=nag_wp) array
User Workspace
-
f is called with the arguments
iuser and
ruser as supplied to
d01rgf. You should use the arrays
iuser and
ruser to supply information to
f.
f must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which
d01rgf is called. Arguments denoted as
Input must
not be changed by this procedure.
-
4:
– Real (Kind=nag_wp)
Input
-
On entry: the absolute accuracy required.
If
epsabs is negative,
is used. See
Section 7.
If , only the relative error will be used.
-
5:
– Real (Kind=nag_wp)
Input
-
On entry: the relative accuracy required.
If
epsrel is negative,
is used. See
Section 7.
If
, only the absolute error will be used otherwise the actual value of
epsrel used by
d01rgf is
.
Constraint:
at least one of
epsabs and
epsrel must be nonzero.
-
6:
– Real (Kind=nag_wp)
Output
-
On exit: the estimate of the definite integral
f.
-
7:
– Real (Kind=nag_wp)
Output
-
On exit: the error estimate of the definite integral
f.
-
8:
– Integer
Output
-
On exit: the total number of points at which the integrand, , has been evaluated.
-
9:
– Integer array
User Workspace
-
10:
– Real (Kind=nag_wp) array
User Workspace
-
iuser and
ruser are not used by
d01rgf, but are passed directly to
f and may be used to pass information to this routine.
-
11:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 4 in the Introduction to the NAG Library FL Interface 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, because for this routine the values of the output arguments may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
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
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
Note: in some cases d01rgf may return useful information.
-
The requested accuracy was not achieved. Consider using larger values of
epsabs and
epsrel.
-
The integral is probably divergent or slowly convergent.
-
Both and .
-
Exit requested from
f with
.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
d01rgf cannot guarantee, but in practice usually achieves, the following accuracy:
where
and
epsabs and
epsrel are user-specified absolute and relative error tolerances. Moreover, it returns the quantity
errest which, in normal circumstances, satisfies
8
Parallelism and Performance
d01rgf is currently neither directly nor indirectly threaded. In particular, the user-supplied subroutine
f is not called from within a parallel region initialized inside
d01rgf.
The user-supplied subroutine
f uses a vectorized interface, allowing for the required vector of function values to be evaluated in parallel; for example by placing appropriate OpenMP directives in the code for the user-supplied subroutine
f.
The time taken by d01rgf depends on the integrand and the accuracy required.
d01rgf is suitable for evaluating integrals that have singularities within the requested interval.
In particular,
d01rgf accepts non-finite values on return from the user-supplied subroutine
f, and will adapt the integration rule accordingly to eliminate such points. Non-finite values include NaNs and infinities.
10
Example
10.1
Program Text
10.2
Program Data
None.
10.3
Program Results