1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Create Bessell Function using VBA

  1. Sep 26, 2014 #1
    1. The problem statement, all variables and given/known data
    Write a VBA program to input x, n, the max number of terms to be considered, and the tolerance. Then evaluate [itex]J_{n}(x)[/itex]. Continue your series until a term becomes less than the tolerance or the maximum number of terms is reached.

    2. Relevant equations
    [itex]J_{n}(x)=\sum_{k=0}^{\infty} \frac{(-1)^k x^{n+2k}}{2^{n+2k}k!\Gamma (n+k+1)}[/itex]

    [itex]\Gamma (m)=(m-1)!\\[/itex] if m is an integer

    3. The attempt at a solution
    I am having a lot of difficulty figuring out how to create the loop to execute the [itex]\Gamma[/itex] function. I am supposed to use a Do While loop to control the overall series and For loops for the [itex]k![/itex] and [itex]\Gamma[/itex] function.

    Below is what I have started with. The [itex]k![/itex] for loop works correctly on its own and I plan to place it within "Do While n < max_term Or Abs(term) > tol" but from there I do not know where to go.
    Code (Text):

    Sub bess()
    Dim x As Double, max_term As Double, tol As Double, n As Double, k As Double, fact As Double
    x = Val(InputBox("enter x value now"))
    max_term = Val(InputBox("enter max terms now"))
    tol = Val(InputBox("enter tolerance now"))
    n = Val(InputBox("enter n now"))
    Cells(1, "B").Value = x
    Cells(2, "B").Value = tol
    Cells(3, "B").Value = max_term
    k = 1
    fact = 1
      For k = 1 To n
      fact = fact * k
      Next k
    Cells(5, "B").Value = fact
    End Sub
  2. jcsd
  3. Sep 26, 2014 #2
    I figured out my problem. Thanks
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted