Create Bessell Function using VBA

  • Thread starter Thread starter aztec
  • Start date Start date
  • Tags Tags
    Function
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 1K views
aztec
Messages
3
Reaction score
0

Homework Statement


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.

Homework 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
[itex][/itex]
[itex][/itex]
[itex][/itex]

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:
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
 
Physics news on Phys.org
I figured out my problem. Thanks