# Singularity on Interior of Integration Domain

This example shows how to split the integration domain to place a singularity on the boundary.

### Define the Integrand with an Anonymous Function

The integrand of the complex-valued integral

${\int }_{-1}^{1}{\int }_{-1}^{1}\frac{1}{\sqrt{x+y}}\phantom{\rule{0.2222222222222222em}{0ex}}dx\phantom{\rule{0.2222222222222222em}{0ex}}dy$

has a singularity when x = y = 0 and is, in general, singular on the line y = -x.

Define this integrand with an anonymous function.

fun = @(x,y) ((x+y).^(-1/2));

### Integrate Over a Square

Integrate fun over a square domain specified by $-1\le x\le 1$ and $-1\le y\le 1$.

format long
q = integral2(fun,-1,1,-1,1)
Warning: Non-finite result. The integration was unsuccessful. Singularity likely.
q =
NaN +               NaNi

If there are singular values in the interior of the integration region, the integration fails to converge and returns a warning.

### Split the Integration Domain into Two Triangles

You can redefine the integral by splitting the integration domain into complementary pieces and adding the smaller integrations together. Avoid integration errors and warnings by placing singularities on the boundary of the domain. In this case, you can split the square integration region into two triangles along the singular line y = -x and add the results.

q1 = integral2(fun,-1,1,-1,@(x)-x);
q2 = integral2(fun,-1,1,@(x)-x,1);
q = q1 + q2
q =
3.771236166328259 - 3.771236166328255i

The integration succeeds when the singular values are on the boundary.

The exact value of this integral is

$\frac{8\sqrt{2}}{3}\left(1-i\right)$

8/3*sqrt(2)*(1-i)
ans =
3.771236166328253 - 3.771236166328253i