The "integral2" function in MATLAB was designed to have a more generic interface in order to house more than one method of integration. Unfortunately, it was not designed to offer a lot of custom tuning such as turning off the singularity-weakening transform (which makes the 'tiled' method slightly different to the "TwoD" function, and ultimately causes it to return unexpected result when integrating your PDF).
Getting an adaptive quadrature algorithm successfully started is a ubiquitous problem. Different implementations will exhibit different behaviors on problems that are challenging to start integrating, challenging because the integrand is zero or almost zero almost everywhere. Generally speaking, it is always possible to engineer a failure on such problems by modifying the limits of integration and/or the intensity of the spike. There will be different “tipping points”, and the success of one implementation or the other in a given circumstance usually doesn’t mean much; a lucky sample point here, a more conservative start there, these things matter but on the whole don’t make one method clearly better than the other in general. With 1D integration we provide a “waypoints” feature that can help, but you would need to know where those points are to supply them. Since we don’t have a waypoints feature for 2D integration, we would want to locate those spikes, split the region of integration, and put those spikes in small regions, perhaps on boundaries. That will make your "computeAzElProbability" function considerably more complicated as it figures out where to split the region and then performs and adds up integrations over subregions, but ultimately that will make it much more reliable.
As a workaround, you might want to use the "quad2d" function in MATLAB instead:
>> azElProb = quad2d(@integrand, azmin, azmax, elmin, elmax, 'RelTol', 1e-9, 'AbsTol', 0, 'singular', false);
Best Answer