d01uaf computes an estimate of the definite integral of a function of known analytical form, using a Gaussian quadrature formula with a specified number of abscissae. Formulae are provided for a finite interval (Gauss–Legendre), a semi-infinite interval (Gauss–Laguerre, rational Gauss), and an infinite interval (Gauss–Hermite).
The routine may be called by the names d01uaf or nagf_quad_dim1_gauss_vec.
3Description
3.1General
d01uaf evaluates an estimate of the definite integral of a function , over a finite or infinite range, by -point Gaussian quadrature (see Davis and Rabinowitz (1975), Fröberg (1970), Ralston (1965) or Stroud and Secrest (1966)). The integral is approximated by a summation of the product of a set of weights and a set of function evaluations at a corresponding set of abscissae . For adjusted weights, the function values correspond to the values of the integrand , and hence the sum will be
where the are called the weights, and the the abscissae. A selection of values of is available. (See Section 5.)
Where applicable, normal weights may instead be used, in which case the corresponding weight function is factored out of the integrand as and hence the sum will be
where the normal weights are computed internally.
d01uaf uses a vectorized f to evaluate the integrand or normalized integrand at a set of abscissae, , for . If adjusted weights are used, the integrand must be evaluated otherwise the normalized integrand must be evaluated.
3.2Both Limits Finite
The Gauss–Legendre weights and abscissae are used, and the formula is exact for any function of the form:
The formula is appropriate for functions which can be well approximated by such a polynomial over . It is inappropriate for functions with algebraic singularities at one or both ends of the interval, such as on .
3.3One Limit Infinite
Two quadrature formulae are available for these integrals.
(a)The Gauss–Laguerre formula is exact for any function of the form:
This formula is appropriate for functions decaying exponentially at infinity; the argument should be chosen if possible to match the decay rate of the function.
If the adjusted weights are selected, the complete integrand should be provided through f.
If the normal form is selected, the contribution of is accounted for internally, and f should only return , where .
If is supplied, the interval of integration will be . Otherwise if is supplied, the interval of integration will be .
(b)The rational Gauss formula is exact for any function of the form:
This formula is likely to be more accurate for functions having only an inverse power rate of decay for large . Here the choice of a suitable value of may be more difficult; unfortunately a poor choice of can make a large difference to the accuracy of the computed integral.
Only the adjusted form of the rational Gauss formula is available, and as such, the complete integrand must be supplied in f.
If , the interval of integration will be . Otherwise if , the interval of integration will be .
3.4Both Limits Infinite
The Gauss–Hermite weights and abscissae are used, and the formula is exact for any function of the form:
where . Again, for general functions not of this exact form, the argument should be chosen to match if possible the decay rate at .
If the adjusted weights are selected, the complete integrand should be provided through f.
If the normal form is selected, the contribution of is accounted for internally, and f should only return , where .
4References
Davis P J and Rabinowitz P (1975) Methods of Numerical Integration Academic Press
Fröberg C E (1970) Introduction to Numerical Analysis Addison–Wesley
Ralston A (1965) A First Course in Numerical Analysis pp. 87–90 McGraw–Hill
Stroud A H and Secrest D (1966) Gaussian Quadrature Formulas Prentice–Hall
5Arguments
1: – IntegerInput
On entry: indicates the quadrature formula.
Gauss–Legendre quadrature on a finite interval, using normal weights.
Gauss–Laguerre quadrature on a semi-infinite interval, using normal weights.
Gauss–Laguerre quadrature on a semi-infinite interval, using adjusted weights.
Gauss–Hermite quadrature on an infinite interval, using normal weights.
Gauss–Hermite quadrature on an infinite interval, using adjusted weights.
Rational Gauss quadrature on a semi-infinite interval, using adjusted weights.
Constraint:
, , , , or .
2: – Real (Kind=nag_wp)Input
3: – Real (Kind=nag_wp)Input
On entry: the quantities and as described in the appropriate subsection of Section 3.
Constraints:
Rational Gauss: ;
Gauss–Laguerre: ;
Gauss–Hermite: .
4: – IntegerInput
On entry: , the number of abscissae to be used.
Constraint:
, , , , , , , , , , , , , , or .
If the soft fail option is used, the answer is evaluated for the largest valid value of n less than the requested value.
5: – Subroutine, supplied by the user.External Procedure
f must return the value of the integrand , or the normalized integrand , at a set of points.
On entry: the abscissae,
, for at which function values are required.
2: – IntegerInput
On entry: , the number of abscissae.
3: – Real (Kind=nag_wp) arrayOutput
On exit: if adjusted weights are used, the values of the integrand .
, for .
Otherwise the values of the normalized integrand .
, for .
4: – IntegerInput/Output
On entry: .
On exit: set if you wish to force an immediate exit from d01uaf with .
5: – Integer arrayUser Workspace
6: – Real (Kind=nag_wp) arrayUser Workspace
f is called with the arguments iuser and ruser as supplied to d01uaf. 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 d01uaf is called. Arguments denoted as Input must not be changed by this procedure.
Note:f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d01uaf. If your code inadvertently does return any NaNs or infinities, d01uaf is likely to produce unexpected results.
Some points to bear in mind when coding f are mentioned in Section 7.
6: – Real (Kind=nag_wp)Output
On exit: the estimate of the definite integral.
7: – Integer arrayUser Workspace
8: – Real (Kind=nag_wp) arrayUser Workspace
iuser and ruser are not used by d01uaf, but are passed directly to f and may be used to pass information to this routine.
9: – IntegerInput/Output
On entry: ifail must be set to , or to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value or is recommended. If message printing is undesirable, then the value is recommended. Otherwise, the value is recommended since useful values can be provided in some output arguments even when on exit. When the value or 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).
6Error 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 d01uaf may return useful information.
The -point rule is not among those stored. On entry: . -point rule used: .
Underflow occurred in calculation of normal weights. Reduce n or use adjusted weights: .
No nonzero weights were generated for the provided parameters.
On entry, . Constraint: , , , , or .
The value of a and/or b is invalid for the chosen key. Either:
The value of a and/or b is invalid. On entry, . On entry, and . Constraint: .
The value of a and/or b is invalid. On entry, . On entry, and . Constraint: .
The value of a and/or b is invalid. On entry, . On entry, and . Constraint: .
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.
7Accuracy
The accuracy depends on the behaviour of the integrand, and on the number of abscissae used. No tests are carried out in d01uaf to estimate the accuracy of the result. If such an estimate is required, the routine may be called more than once, with a different number of abscissae each time, and the answers compared. It is to be expected that for sufficiently smooth functions a larger number of abscissae will give improved accuracy.
Alternatively, the range of integration may be subdivided, the integral estimated separately for each sub-interval, and the sum of these estimates compared with the estimate over the whole range.
The coding of f may also have a bearing on the accuracy. For example, if a high-order Gauss–Laguerre formula is used, and the integrand is of the form
it is possible that the exponential term may underflow for some large abscissae. Depending on the machine, this may produce an error, or simply be assumed to be zero. In any case, it would be better to evaluate the expression with
Another situation requiring care is exemplified by
The integrand here assumes very large values; for example, when , the peak value exceeds . Now, if the machine holds floating-point numbers to an accuracy of significant decimal digits, we could not expect such terms to cancel in the summation leaving an answer of much less than (the weights being of order unity); that is, instead of zero we obtain a rather large answer through rounding error. Such situations are characterised by great variability in the answers returned by formulae with different values of .
In general, you should be aware of the order of magnitude of the integrand, and should judge the answer in that light.
8Parallelism and Performance
d01uaf is currently neither directly nor indirectly threaded. In particular, the user-supplied argument f is not called from within a parallel region initialized inside d01uaf.
The user-supplied argument 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 argument f.
9Further Comments
The time taken by d01uaf depends on the complexity of the expression for the integrand and on the number of abscissae required.
10Example
This example evaluates the integrals
by Gauss–Legendre quadrature;
by rational Gauss quadrature with ;
by Gauss–Laguerre quadrature with ; and
by Gauss–Hermite quadrature with and .
The formulae with and are used in each case. Both adjusted and normal weights are used for Gauss–Laguerre and Gauss–Hermite quadrature.