Create Bessell Function using VBA

  • Thread starter Thread starter aztec
  • Start date Start date
  • Tags Tags
    Function
Click For Summary
SUMMARY

The discussion focuses on creating a VBA program to evaluate the Bessel function J_{n}(x) using a series expansion. The program requires user input for the variables x, n, the maximum number of terms, and the tolerance level. The main challenge highlighted is implementing a Do While loop to control the series evaluation, alongside For loops for calculating factorials and the Gamma function. The user successfully resolved their issue with the factorial calculation within the loop.

PREREQUISITES
  • Understanding of VBA programming language
  • Knowledge of Bessel functions and their mathematical properties
  • Familiarity with loops and conditional statements in programming
  • Basic concepts of factorial and Gamma function calculations
NEXT STEPS
  • Implement the Do While loop to evaluate the series until the specified tolerance is met
  • Research the implementation of the Gamma function in VBA
  • Explore error handling techniques in VBA for user input validation
  • Study optimization techniques for improving the performance of the Bessel function calculation
USEFUL FOR

Students and developers working on mathematical programming in VBA, particularly those interested in numerical methods and series expansions for special functions.

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
 

Similar threads

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