Integer type:** int32**** int64**** nag_int** show int32 show int32 show int64 show int64 show nag_int show nag_int

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).

nag_quad_2d_fin (d01da) attempts to evaluate a definite integral of the form

where a$a$ and b$b$ are constants and φ_{1}(y)${\varphi}_{1}\left(y\right)$ and φ_{2}(y)${\varphi}_{2}\left(y\right)$ are functions of the variable y$y$.

$$I=\underset{a}{\overset{b}{\int}}\underset{{\varphi}_{1}\left(y\right)}{\overset{{\varphi}_{2}\left(y\right)}{\int}}f(x,y)dxdy$$ |

The integral is evaluated by expressing it as

Both the outer integral I$I$ and the inner integrals F(y)$F\left(y\right)$ are evaluated by the method, described by

Patterson (1968) and Patterson (1969), of the optimum addition of points to Gauss quadrature formulae.

$$I=\underset{a}{\overset{b}{\int}}F\left(y\right)dy\text{, \hspace{1em} where \hspace{1em}}F\left(y\right)=\underset{{\varphi}_{1}\left(y\right)}{\overset{{\varphi}_{2}\left(y\right)}{\int}}f(x,y)dx\text{.}$$ |

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 3$3$-point Gauss rule, formulae using 7$7$, 15$15$, 31$31$, 63$63$, 127$127$ and finally 255$255$ 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.

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

- 1: ya – double scalar
- a$a$, the lower limit of the integral.
- 2: yb – double scalar
- b$b$, the upper limit of the integral. It is not necessary that a < b$a<b$.
- 3: phi1 – function handle or string containing name of m-file
- 4: phi2 – function handle or string containing name of m-file
- 5: f – function handle or string containing name of m-file
- 6: absacc – double scalar
- The absolute accuracy requested.

None.

None.

- 1: ans – double scalar
- The estimated value of the integral.
- 2: npts – int64int32nag_int scalar
- The total number of function evaluations.
- 3: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and 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`ifail = 1${\mathbf{ifail}}=1$- This indicates that 255$255$ 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`ifail = 10 × n${\mathbf{ifail}}=10\times n$- This indicates that the outer integral has converged but n$n$ inner integrals have failed to converge with the use of 255$255$ points. In this case ans may still contain an approximate estimate of the integral, but its reliability will decrease as n$n$ increases.

`W`ifail = 10 × n + 1${\mathbf{ifail}}=10\times n+1$- This indicates that both the outer integral and n$n$ of the inner integrals have not converged. ans may still contain an approximate estimate of the integral, but its reliability will decrease as n$n$ increases.

The absolute accuracy is specified by the variable absacc. If, on exit, ifail = 0${\mathbf{ifail}}={\mathbf{0}}$ 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.

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 F(y)$F\left(y\right)$ 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, R$R$

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:

I = ∫ _{R}(x + y)dx
dy.
$$I={\int}_{R}(x+y)dxdy\text{.}$$ |

$$I=\underset{0}{\overset{1}{\int}}dy\underset{0}{\overset{\sqrt{1-{y}^{2}}}{\int}}(x+y)dx=\underset{0}{\overset{1}{\int}}(\frac{1}{2}(1-{y}^{2})+y\sqrt{1-{y}^{2}})dy$$ |

$$I=\underset{0}{\overset{1}{\int}}dr\underset{0}{\overset{\frac{\pi}{2}}{\int}}{r}^{2}(\mathrm{cos}\upsilon +\mathrm{sin}\upsilon )d\upsilon \text{.}$$ |

Open in the MATLAB editor: nag_quad_2d_fin_example

function nag_quad_2d_fin_exampleya = 0; yb = 1; absacc = 1e-06; [ans, npts, ifail] = nag_quad_2d_fin(ya, yb, @phi1, @phi2, @f, absacc)function result = phi1(y)result=0;function result = phi2(y)result = sqrt(1-y^2);function result = f(x,y)result=x+y;

ans = 0.6667 npts = 189 ifail = 0

Open in the MATLAB editor: d01da_example

function d01da_exampleya = 0; yb = 1; absacc = 1e-06; [ans, npts, ifail] = d01da(ya, yb, @phi1, @phi2, @f, absacc)function result = phi1(y)result=0;function result = phi2(y)result = sqrt(1-y^2);function result = f(x,y)result=x+y;

ans = 0.6667 npts = 189 ifail = 0

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013