Why do I get the error "max number of function evalutations reached" using integral2?

1 view (last 30 days)
Peter Uwsen
Peter Uwsen on 19 Apr 2019
Commented: Walter Roberson on 23 Apr 2019
Hi,
I'm having some problems using the integral2 function. I get the error "max number of function evalutations reached" for certain imput values.
This is my code:
lambda = 4;
a = 1.8821;
m = 1.0228;
psi = 1;
p = @(r) 3/pi*a*sqrt(1-r.^2)-2*lambda/pi*atan(sqrt((m^2-1)./(1-r.^2)));
x = 0.9;
z = 1e-6; % varied value
nu = .25;
X = @(r,phi) x-r.*cos(phi);
Y = @(r,phi) -r.*sin(phi);
R = @(r,phi) (X(r,phi).^2 + Y(r,phi).^2).^.5;
Rho = @(r,phi) (X(r,phi).^2 + Y(r,phi).^2 + z^2).^.5;
f1 = @(r,phi) (1 - z./Rho(r,phi)).*(X(r,phi).^2 - Y(r,phi).^2)./R(r,phi).^2;
f2 = @(r,phi) f1(r,phi) + z*Y(r,phi).^2./Rho(r,phi).^3;
f3 = @(r,phi) (1 - 2*nu)./R(r,phi).^2.*f2(r,phi) - 3*z*X(r,phi).^2./Rho(r,phi).^5;
fun = @(r,phi) r.*p(r).*f3(r,phi);
sx = psi/2/pi*integral2(fun,0,1,0,2*pi);
In need the variable "sx" for different values of "z".
For values greater than 1e-4 it works just fine, but for small values, for example 1e-6, I get an error.
I guess this has to do with some kind of singularity when calculating the integral, but I don't know how integral2 works..
I'm happy about any ideas on how to fix this problem!
Thanks a lot!
  4 Comments
Walter Roberson
Walter Roberson on 23 Apr 2019
You do not need singularity to have integral2 problems with iterations: it can happen due to round-off problems, and it can happen for very steep functions, and it can happen for oscillating functions. It is a convergence issue, and sometimes you can deal with those by permitted more steps and sometimes you are never going to be able to solve them numerically.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!