MATLAB: How to find an implicit value in an integral equation

numerical integration

I want to solve the following problem numerically
I tried to input the function as a handle function to matlab, but it refutes to compute the integral for the second layer, while the trapz returns the very wrong answer when I refine the domain of integral. Is there anyway to do it with high accuracy in Matlab?

Best Answer

f = @(x,y,r) 1./(2 *(r + exp(-x.^2) .* (1-sin(2*pi*y))));
Fcr = @(cr,r) integral2(@(x,y) f(x,y,r), 0, cr, 0, 1, 'RelTol', 1e-3) - 1;
opt = optimset('MaxIter', 20000);
solr = @(R) arrayfun(@(r) fzero(@(cr) Fcr(cr,r), [1/100 100*r], opt), R);
fplot(solr, [1/100 1])
Note: this will produce several warnings,
"Warning: Reached the maximum number of function evaluations (10000). The result fails the global error test."
Those occur for some of the values on the lower end when fplot is doing the plotting. All of the interesting shape is on the lower end, though.