Hi there, I received an assignment asking me to calculate pi with Virtual Basic. We were to select from a number sequence and create a function to calculate the first 50 terms..
The sequence I chose was sqrt(8*(1/1^2 +1/3^2 + 1/5^2 ... and etc))
To start, wouldn't excel only allow up to 30 decimal places? Or am I mislead over that..
Anyways, heres my frustrating work of trying to create this over and over..
Function my_calc()
Dim my_pi As Integer
Dim my_base As Integer
Dim my_count As Integer
Dim my_next As Integer
Dim my_total As Integer
Dim my_max As Integer
Dim my_constant As Integer
my_total = 0
my_pi = 0
my_base = 1
my_constant = 8
my_next = 0
my_max = 50
my_count = 0
Do While my_count < my_max
my_next = (1 / (my_base ^ 2)) + my_total
my_total = my_next
my_base = my_base + 2
my_count = my_count + 1
my_pi = (8 * (my_total)) ^ 0.5
Loop
my_calc = my_pi
Cells(3, 1) = "Pi ="
Cells(3, 2) = my_calc
End Function
In the end, my result comes out to 3.0000000 ... I've changed the decimal places to 30 and everything but what seems to be happening from what I've tried to figure out is that after the first time around, my "my_next" just seems to be kind of rounding? When I change my_max to 1, the my_next equals 1, but when I change it to two, I assume the my_next would then be "my_next = 1/ 3^2" and yield .111, however it goes to 0. Any advice or help would be greatly appreciated~
The sequence I chose was sqrt(8*(1/1^2 +1/3^2 + 1/5^2 ... and etc))
To start, wouldn't excel only allow up to 30 decimal places? Or am I mislead over that..
Anyways, heres my frustrating work of trying to create this over and over..
Function my_calc()
Dim my_pi As Integer
Dim my_base As Integer
Dim my_count As Integer
Dim my_next As Integer
Dim my_total As Integer
Dim my_max As Integer
Dim my_constant As Integer
my_total = 0
my_pi = 0
my_base = 1
my_constant = 8
my_next = 0
my_max = 50
my_count = 0
Do While my_count < my_max
my_next = (1 / (my_base ^ 2)) + my_total
my_total = my_next
my_base = my_base + 2
my_count = my_count + 1
my_pi = (8 * (my_total)) ^ 0.5
Loop
my_calc = my_pi
Cells(3, 1) = "Pi ="
Cells(3, 2) = my_calc
End Function
In the end, my result comes out to 3.0000000 ... I've changed the decimal places to 30 and everything but what seems to be happening from what I've tried to figure out is that after the first time around, my "my_next" just seems to be kind of rounding? When I change my_max to 1, the my_next equals 1, but when I change it to two, I assume the my_next would then be "my_next = 1/ 3^2" and yield .111, however it goes to 0. Any advice or help would be greatly appreciated~