matlab bessel functions?

Discussion in 'Programmer's Corner' started by suzuki, Jun 8, 2012.

  1. suzuki

    Thread Starter Member

    Aug 10, 2011
    119
    0
    Hi all,

    I'm trying to implement a bessel function method in Matlab. I am aware of the besselj() function call but I'd like to use the formula to "brute force" the solution for my application.

    I tried to implement the Bessel Function of the first kind, as shown here. http://en.wikipedia.org/wiki/Bessel_function#Bessel_functions_of_the_first_kind_:_J.CE.B1

    I have written the following code:

    Code ( (Unknown Language)):
    1. beta = 4;
    2. alpha = 1;
    3. iteration = 3;
    4.  
    5. format long
    6.  
    7. for m = 1:iteration
    8.     J(m) = (((-1)^m)/(factorial(m)*gamma(m+alpha+1)))*(beta/2)^(2*m+alpha);
    9. end
    10.  
    11. out = sum(J)
    But when i compare my solution to the return of besselj(), its not the same, and I'm completely lost as to where I made a mistake.

    Thanks.



    update: i made a mistake. All the m's can be replaced with m-1 and this solves the issue
     
    Last edited: Jun 11, 2012
Loading...