How should I resolve the warning "Warning: Reached the maximum number of function evaluations (100000). The result fails the global error test."?

30 views (last 30 days)
I am trying too evaluate a double integral numerically using 'quad2d' function over a triangular area.
c = 1;
xib = 0;
yib = 0.866;
zi = 1e-05;
gamma = 0.866;
tmin1 = 0;
tmax1 = @(s)sqrt(3)*(s+c/2);
tmin2 = 0;
tmax2 = @(s)sqrt(3)*(-s+c/2);
rho = @(s,t)((xib-s).^2+(yib-t).^2+zi.^2).^(1./2);
fintzz = @(s,t)-t./rho(s,t).^5;
% touzz = (3*zi^3)/(2*pi*gamma).*quad2d(fintzz,0,gamma,smin,smax,'AbsTol',1e-15,'RelTol',1e-15,'FailurePlot',true,'MaxFunEvals',50000);
touzz1 = (3*zi^3)/(2*pi*gamma).*quad2d(fintzz,-c/2,0,tmin1,tmax1,'FailurePlot',true,'Singular',true,'MaxFunEvals',100000);
touzz2 = (3*zi^3)/(2*pi*gamma).*quad2d(fintzz,0,c/2,tmin2,tmax2,'FailurePlot',true,'Singular',true,'MaxFunEvals',100000);
touzz = touzz1+touzz2;
Initially, I was integrating over the entire triangular area in one line. I know that there is a singularity at point (0,0) for the integrand. After looking at some suggestions in MATLAB forums, I have split the integration region into two areas. I am using the above code to solve a bigger problem, for which I have analytical solutions. The results improved with splitting the region, but I am not getting an answer which is satisfactorily closer to the analytical values. The accuracy is not improving for whatever number of function evaluations I do, like here I have used 100000 evaluations, and I still get the warning. Can someone guide me with any better alternatives in MATLAB? Thanks.

Accepted Answer

Devineni Aslesha
Devineni Aslesha on 19 May 2020
Hi Yaswanth
It looks like the warning occurs even when the maximum number of function evaluations are 2000. I recommend you to go through the 'Limitations of quad2d' in quad2d doc link. You can try splitting the integral into more areas by examining the FailurePlot, increase the tolerances using 'AbsTol' and 'RelTol' properties of quad2d as specified in this link. Also, try using integral2 function in MATLAB with 'Method' property set to 'iterated'.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!