MATLAB: Different results for solving integral equation in each run

fsolveintegral equation

Dear all,
I am trying to solve the following integral equation:
T=100.;
mustar = 400.;
Lambda = 602.3;
GsLambda2 = 2.319;
Gs = 0.00000639;
m = 100.;
Gv = 0.5 * Gs;
Gd = 0.75 * Gs;
Deltagap = @(d) integral(@(p) 4.0/pi.^2*Gd*d.*p.^2.*(((1.-2.*((exp (( sqrt (( sqrt (p.^2.+m.^2.) – mustar ).^2 + …
d.^2))/T) +1).^(-1)))./(sqrt (( sqrt (p.^2.+m.^2.) – mustar).^2 + d.^2))) + …
((1. – 2.*((exp (( sqrt (( sqrt (p.^2 + m.^2) + mustar).^2 + d.^2))/T)…
+ 1).^(-1)))./(sqrt (( sqrt (p.^2+m.^2) + mustar).^2 + d.^2)))), 0, 602.3) – d;
B = fsolve(@(d) Deltagap(d), rand(1,1))
Each time when I run the code, I got a different answer.
I don't know which one is correct.
What should I do?
I have to run the code for the different value of the mustar as well as T thus I must manage to get correct result for every run.
Thank you in advance.

Best Answer

the fsolve funciton is a robust root-finding algorithm. If you plot ‘Deltagap’, you will find that it has no zero-crossings at all for positive values of ‘d’, and for ‘d’ itself crossing 0 (so allowing for negative and positive values), it has exactly 1 zero-crossing, that being exactly at 0.
Related Question