Create Bessell Function using VBA

  • Thread starter Thread starter aztec
  • Start date Start date
  • Tags Tags
    Function
Click For Summary
A user is seeking assistance in writing a VBA program to compute the Bessel function J_{n}(x) by inputting values for x, n, maximum terms, and tolerance. The program should utilize a Do While loop to control the series evaluation, continuing until a term is less than the specified tolerance or the maximum number of terms is reached. The user has successfully implemented a factorial calculation using a For loop but is uncertain about integrating this into the overall loop structure. After some troubleshooting, the user reports resolving their initial problem. The discussion highlights the challenges of implementing mathematical functions in VBA programming.
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 J_{n}(x). Continue your series until a term becomes less than the tolerance or the maximum number of terms is reached.

Homework Equations


J_{n}(x)=\sum_{k=0}^{\infty} \frac{(-1)^k x^{n+2k}}{2^{n+2k}k!\Gamma (n+k+1)}

\Gamma (m)=(m-1)!\\ if m is an integer




The Attempt at a Solution


I am having a lot of difficulty figuring out how to create the loop to execute the \Gamma function. I am supposed to use a Do While loop to control the overall series and For loops for the k! and \Gamma function.

Below is what I have started with. The k! 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
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
788
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 27 ·
Replies
27
Views
5K
  • · Replies 14 ·
Replies
14
Views
2K