`quad2d`

begins by mapping the region of integration to a rectangle. Consequently, it may have trouble integrating over a region that does not have four sides or has a side that cannot be mapped smoothly to a straight line. If the integration is unsuccessful, some helpful tactics are leaving `Singular`

set to its default value of `true`

, changing between Cartesian and polar coordinates, or breaking the region of integration into pieces and adding the results of integration over the pieces.

For instance:

Warning: Reached the maximum number of function evaluations (2000). The result fails the global error test.

The failure plot shows two areas of difficulty, near the points `(-1,0)`

and `(1,0)`

and near the circle $${x}^{2}+{y}^{2}=0.25$$.

Changing the value of `Singular`

to `true`

will cope with the geometric singularities at `(-1,0)`

and `(1,0)`

. The larger shaded areas may need refinement but are probably not areas of difficulty.

Warning: Reached the maximum number of function evaluations (2000). The result passes the global error test.

From here you can take advantage of symmetry:

However, the code is still working very hard near the singularity. It may not be able to provide higher accuracy:

Warning: Reached the maximum number of function evaluations (2000). The result passes the global error test.

At higher accuracy, a change in coordinates may work better.

It is best to put the singularity on the boundary by splitting the region of integration into two parts: