aztec
- 3
- 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