I am looking to calculate the Bessel function of the first kind $J_o(\beta)$. I am using the formula (referenced from wikipedia) to accomplish this.
$$J_\alpha (\beta) = \sum_{m=0}^{\infty}\frac{(-1)^m}{m!\Gamma(m+\alpha +1)} \left(\frac{\beta}{2}\right)^{2m+\alpha}$$
I am also aware of that MATLAB has a function which can calculate the solution as well. The function call is $besselj(nu,Z)$. However, what I am finding is that there is a discrepancy between what my $for$ loop calculates and what MATLAB outputs.
Does anyone see why this might be happening? I have included my code for reference:
loop_var = 100;
beta = 0.120;
alpha = 0;
sum = 0;
amp = 0;
[matl,ierr] =besselj(alpha,beta)
for m=0:loop_var
amp=amp+((-1)^m)/(factorial(m)*gamma(m+alpha+1))*(beta/2)^(2*m+alpha);
end
amp
Thanks for all comments and suggestions.
EDIT: Thanks to Fabian and Ed for catching that error.
I suppose as a "followup" question, the wikipedia formula and that MATLAB function seem to only match for "small" values of $\beta$. After $\beta$ is great than approximately 10, there is some error between the two values. Does anyone then know how the Matlab number is obtained?
This code only executes the loop once.
This code is correct (notice the
0:afterm=).For your edited question...
From the MATLAB
besseljdocumentation:The first paper can be found here.