%% Integrand with Singularity on Integration Boundary
% Integrate the function
% \left[ \left( x+y \right)^{1/2} \left(1+x+y\right)^2\right]^{-1}
% over the region 0 \le x \le 1 and 0 \le y \le 1-x. This integrand is infinite at the origin (0,0), which lies on the boundary of the integration region.

fun = @(x,y) 1./(sqrt(x + y) .* (1 + x + y).^2 );
ymax = @(x) 1 - x;
Q = quad2d(fun,0,1,0,ymax)

%
% The true value of the integral is \pi /4 - 1/2.

pi/4 - 0.5

% Copyright 2012 The MathWorks, Inc.