b_c(n) = fzero(@(b) func_HE11(b,V,l),[0.0000001 30]);
fzero() needs to evaluate at both endpoints, and the two endpoints have to give different sign of value, so that fzero can do whatever (bisection, etc..) So the function will be evaluated with b = 30 and l = 1
u= V*sqrt(1-b);
b > 1, so 1-b is negative, so sqrt(1-b) is complex, so u is complex valued.
J1 = besselj(l-1,u);
l is 1, so l-1 is 0, so that is a bessel0 computation of a complex number -- confusingly then stored in a variable named J1 which would tend to suggest bessel1 . Anyhow, the computation comes up real-valued for b = 30.
J0 = besselj(l,u);
l is 1, so this is a bessel1 computation of a complex number -- confusingly then stored in a variable named J0 whikch would tend to suggest bessel0. Anyhow, the computation comex up complex-valued for b = 30.
w = V*sqrt(b);
K1 = besselk(l-1,w);
K0 = besselk(l,w);
real, real, and real.
lhs = J1./J0;
Ratio of a real and a complex is complex, so lhs is complex.
rhs = (w./u).*(K1./K0);
w is real but u is complex, so their ratio is complex. K1 and K0 are real so their ratio is real. So the overall expression is complex.
result = lhs - rhs;
Complex minus complex. Do the imaginary components just happen to cancel out, giving something that is real-valued as the result? NO. And the imbalance is too much compared to the real component to believe that it would have balanced out if not for round-off error.
The easiest fix would appear to be to plot to no more than about 0.9999