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

C# |
---|

public static void d01da( double ya, double yb, D01..::..D01DA_PHI1 phi1, D01..::..D01DA_PHI2 phi2, D01..::..D01DA_F f, double absacc, out double ans, out int npts, out int ifail ) |

Visual Basic |
---|

Public Shared Sub d01da ( _ ya As Double, _ yb As Double, _ phi1 As D01..::..D01DA_PHI1, _ phi2 As D01..::..D01DA_PHI2, _ f As D01..::..D01DA_F, _ absacc As Double, _ <OutAttribute> ByRef ans As Double, _ <OutAttribute> ByRef npts As Integer, _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void d01da( double ya, double yb, D01..::..D01DA_PHI1^ phi1, D01..::..D01DA_PHI2^ phi2, D01..::..D01DA_F^ f, double absacc, [OutAttribute] double% ans, [OutAttribute] int% npts, [OutAttribute] int% ifail ) |

F# |
---|

static member d01da : ya : float * yb : float * phi1 : D01..::..D01DA_PHI1 * phi2 : D01..::..D01DA_PHI2 * f : D01..::..D01DA_F * absacc : float * ans : float byref * npts : int byref * ifail : int byref -> unit |

#### Parameters

- ya
- Type: System..::..Double
*On entry*: $a$, the lower limit of the integral.

- yb
- Type: System..::..Double
*On entry*: $b$, the upper limit of the integral. It is not necessary that $a<b$.

- phi1
- Type: NagLibrary..::..D01..::..D01DA_PHI1phi1 must return the lower limit of the inner integral for a given value of $y$.
A delegate of type D01DA_PHI1.

- phi2
- Type: NagLibrary..::..D01..::..D01DA_PHI2phi2 must return the upper limit of the inner integral for a given value of $y$.
A delegate of type D01DA_PHI2.

- f
- Type: NagLibrary..::..D01..::..D01DA_Ff must return the value of the integrand $f$ at a given point.
A delegate of type D01DA_F.

- absacc
- Type: System..::..Double
*On entry*: the absolute accuracy requested.

- ans
- Type: System..::..Double%
*On exit*: the estimated value of the integral.

- npts
- Type: System..::..Int32%
*On exit*: the total number of function evaluations.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

d01da attempts to evaluate a definite integral of the form

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

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

The integral is evaluated by expressing it as

Both the outer integral $I$ and the inner integrals $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\left(x,y\right)dx\text{.}$$ |

This method uses a family of interlacing common point formulae. Beginning with the $3$-point Gauss rule, formulae using $7$, $15$, $31$, $63$, $127$ and finally $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.

# References

Patterson T N L (1968) On some Gauss and Lobatto based integration formulae

*Math. Comput.***22**877–881Patterson T N L (1969) The optimum addition of points to quadrature formulae, errata

*Math. Comput.***23**892# Error Indicators and Warnings

**Note:**d01da may return useful information for one or more of the following detected errors or warnings.

Errors or warnings detected by the method:

- ${\mathbf{ifail}}=1$
- This indicates that $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.

- ${\mathbf{ifail}}=10\times n$
- This indicates that the outer integral has converged but $n$ inner integrals have failed to converge with the use of $255$ points. In this case ans may still contain an approximate estimate of the integral, but its reliability will decrease as $n$ increases.

- ${\mathbf{ifail}}=10\times n+1$
- This indicates that both the outer integral and $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$ increases.

# Accuracy

# Parallelism and Performance

None.

# Further Comments

The time taken by 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\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 method 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 method 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.

This may be presented to d01da as

but here the outer integral has an induced square-root singularity stemming from the way the region has been presented to d01da. This situation should be avoided by re-casting the problem. For the example given, the use of polar coordinates would avoid the difficulty:

**Warning**: such singularities may be induced by incautiously presenting an apparently smooth interval over the positive quadrant of the unit circle, $R$$$I={\int}_{R}\left(x+y\right)dxdy\text{.}$$ |

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

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

# Example

This example evaluates the integral discussed in [Further Comments], presenting it to d01da first as

and then as

Note the difference in the number of function evaluations.

$$\underset{0}{\overset{1}{\int}}\underset{0}{\overset{\sqrt{1-{y}^{2}}}{\int}}\left(x+y\right)dxdy$$ |

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