MATLAB: Warning: Rank deficient, rank = 0, tol = NaN for summation

bessel functionsrank deficient matrix

Hello,
I am trying to implement the following equation
however, I get the "Rank deficient, rank = 0, tol = NaN" warning when I run my code. I understand that the warning comes about because some of the entries in my matrix are "NaN", but I am not able to see what is wrong in the way I translated the equation into matlab (shown below). I would really appreciate any help I can get to figure out what is going on. The Bessel function is periodical and I would suspect that I might have a divide by zero somewhere, however given that I am just implementing an existing equation, I probably have a typo I cannot see. Please help! 🙂
sumn = 0;
summ = 0;
for n=0:1:2000
for m=0:1:2000 % m-summation
summ = summ + (((cos(2*m+1)*ksi*cos(2*m+1)*delta)/((2*m+1)^2)))...
*(besseli(2*m+2,(2*n+1)*pi*a/L)/besseli(2*m+1,(2*n+1)*pi*a/L));
end
sumn = sumn + (-1)^n*sin((2*n+1)/2)*(pi*len/L)*summ;
end
C0_L = 32*a*eps0/(pi^2)*sumn;
Note: I did have this as a while loop originally, but I was getting the same error message and switching to for-loop was one of my debugging steps.

Best Answer

Your besseli calls underflow to 0 on both the numerator and denominator, giving you a 0/0 operation, which is NaN.
You can divide up the computation so that the numerator is calculated first, and if it is 0 then you can break the loop (the terms are not going to get larger from that point.)