PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_quad_2d_fin (d01da)
Purpose
nag_quad_2d_fin (d01da) attempts to evaluate a double integral to a specified absolute accuracy by repeated applications of the method described by
Patterson (1968) and
Patterson (1969).
Syntax
Description
nag_quad_2d_fin (d01da) attempts to evaluate a definite integral of the form
where
and
are constants and
and
are functions of the variable
.
The integral is evaluated by expressing it as
Both the outer integral
and the inner integrals
are evaluated by the method, described by
Patterson (1968) and
Patterson (1969), of the optimum addition of points to Gauss quadrature formulae.
This method uses a family of interlacing common point formulae. Beginning with the -point Gauss rule, formulae using , , , , and finally points are derived. Each new formula contains all the points of the earlier formulae so that no function evaluations are wasted. Each integral is evaluated by applying these formulae successively until two results are obtained which differ by less than the specified absolute accuracy.
References
Patterson T N L (1968) On some Gauss and Lobatto based integration formulae Math. Comput. 22 877–881
Patterson T N L (1969) The optimum addition of points to quadrature formulae, errata Math. Comput. 23 892
Parameters
Compulsory Input Parameters
- 1:
– double scalar
-
, the lower limit of the integral.
- 2:
– double scalar
-
, the upper limit of the integral. It is not necessary that .
- 3:
– function handle or string containing name of m-file
-
phi1 must return the lower limit of the inner integral for a given value of
.
[result] = phi1(y)
Input Parameters
- 1:
– double scalar
-
The value of for which the lower limit must be evaluated.
Output Parameters
- 1:
– double scalar
-
The lower limit of the inner integral for the given value of .
- 4:
– function handle or string containing name of m-file
-
phi2 must return the upper limit of the inner integral for a given value of
.
[result] = phi2(y)
Input Parameters
- 1:
– double scalar
-
The value of for which the upper limit must be evaluated.
Output Parameters
- 1:
– double scalar
-
The upper limit of the inner integral for the given value of .
- 5:
– function handle or string containing name of m-file
-
f must return the value of the integrand
at a given point.
[result] = f(x, y)
Input Parameters
- 1:
– double scalar
- 2:
– double scalar
-
The coordinates of the point at which the integrand must be evaluated.
Output Parameters
- 1:
– double scalar
-
The value of
evaluated at
x.
- 6:
– double scalar
-
The absolute accuracy requested.
Optional Input Parameters
None.
Output Parameters
- 1:
– double scalar
-
The estimated value of the integral.
- 2:
– int64int32nag_int scalar
-
The total number of function evaluations.
- 3:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_quad_2d_fin (d01da) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
- W
-
This indicates that
points have been used in the outer integral and convergence has not been obtained. All the inner integrals have, however, converged. In this case
ans may still contain an approximate estimate of the integral.
- W
-
This indicates that the outer integral has converged but
inner integrals have failed to converge with the use of
points. In this case
ans may still contain an approximate estimate of the integral, but its reliability will decrease as
increases.
- W
-
This indicates that both the outer integral and
of the inner integrals have not converged.
ans may still contain an approximate estimate of the integral, but its reliability will decrease as
increases.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The absolute accuracy is specified by the variable
absacc. If, on exit,
then the result is most likely correct to this accuracy. Even if
ifail is nonzero
on exit, it is still possible that the calculated result could differ from the true value by less than the given accuracy.
Further Comments
The time taken by nag_quad_2d_fin (d01da) depends upon the complexity of the integrand and the accuracy requested.
With Patterson's method accidental convergence may occasionally occur, when two estimates of an integral agree to within the requested accuracy, but both estimates differ considerably from the true result. This could occur in either the outer integral or in one or more of the inner integrals.
If it occurs in the outer integral then apparent convergence is likely to be obtained with considerably fewer integrand evaluations than may be expected. If it occurs in an inner integral, the incorrect value could make the function appear to be badly behaved, in which case a very large number of pivots may be needed for the overall evaluation of the integral. Thus both unexpectedly small and unexpectedly large numbers of integrand evaluations should be considered as indicating possible trouble. If accidental convergence is suspected, the integral may be recomputed, requesting better accuracy; if the new request is more stringent than the degree of accidental agreement (which is of course unknown), improved results should be obtained. This is only possible when the accidental agreement is not better than machine accuracy. It should be noted that the function requests the same accuracy for the inner integrals as for the outer integral. In practice it has been found that in the vast majority of cases this has proved to be adequate for the overall result of the double integral to be accurate to within the specified value.
The function is not well-suited to non-smooth integrands, i.e., integrands having some kind of analytic discontinuity (such as a discontinuous or infinite partial derivative of some low-order) in, on the boundary of, or near, the region of integration.
Warning: such singularities may be induced by incautiously presenting an apparently smooth interval over the positive quadrant of the unit circle,
This may be presented to
nag_quad_2d_fin (d01da) as
but here the outer integral has an induced square-root singularity stemming from the way the region has been presented to
nag_quad_2d_fin (d01da). This situation should be avoided by re-casting the problem. For the example given, the use of polar coordinates would avoid the difficulty:
Example
This example evaluates the integral discussed in
Further Comments, presenting it to
nag_quad_2d_fin (d01da) first as
and then as
Note the difference in the number of function evaluations.
Open in the MATLAB editor:
d01da_example
function d01da_example
fprintf('d01da example results\n\n');
ya = 0;
yb = 1;
absacc = 1e-06;
[ans1, npts1, ifail] = d01da(ya, yb, @phi1, @phi2a, @fa, absacc);
[ans2, npts2, ifail] = d01da(ya, yb, @phi1, @phi2b, @fb, absacc);
fprintf('First formulation:\n');
fprintf('Integral = %9.4f\n', ans1);
fprintf('Number of function evaluations = %5d\n\n', npts1);
fprintf('Second formulation:\n');
fprintf('Integral = %9.4f\n', ans2);
fprintf('Number of function evaluations = %5d\n', npts2);
function result = phi1(y)
result=0;
function result = phi2a(y)
result = sqrt(1-y^2);
function result = fa(x,y)
result=x+y;
function result = phi2b(y)
result = pi/2;
function result = fb(x,y)
result=(y^2)*(cos(x)+sin(x));
d01da example results
First formulation:
Integral = 0.6667
Number of function evaluations = 189
Second formulation:
Integral = 0.6667
Number of function evaluations = 89
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015