
Aug 20th, 2009, 09:22 PM
#1
Thread Starter
PowerPoster
A way to calculate Pi
This is a method that can be used to calculate Pi  the more iterations of i the more accurate the result will be
Code:
Dim Counter As Integer = 1
Dim Answer As Double = 0
For i = 1 To 100000000
Answer += (4 / Counter)  (4 / (Counter + 2))
Counter += 4
Next
Debug.Print(Answer)
Oh btw this uses the GregoryLeibniz method
Kris
Last edited by i00; Oct 5th, 2011 at 11:14 PM.

Aug 23rd, 2009, 05:45 PM
#2
Addicted Member
Re: A way to calculate Pi
22/7=3,1428571428571428571428571428571
Pi=3,1415926535897932384626433832795

Aug 24th, 2009, 06:44 AM
#3
Re: A way to calculate Pi
Why do you show like 40 digits if only the first two are correct lol.

Aug 25th, 2009, 06:48 AM
#4
Addicted Member
Re: A way to calculate Pi
To see that they are not correct

Sep 14th, 2009, 10:24 AM
#5
Frenzied Member
Re: A way to calculate Pi
Why wouldn't you just use Math.PI?

Sep 14th, 2009, 08:51 PM
#6
Thread Starter
PowerPoster
Re: A way to calculate Pi
... because  just showing a way to calculate it
Kris

Oct 22nd, 2009, 07:26 AM
#7
Hyperactive Member
Re: A way to calculate Pi
Well that doesn't provide an accurate result at all.
After the first 2 digits, it's already entirely incorrect.

Oct 5th, 2011, 11:16 PM
#8
Thread Starter
PowerPoster
Re: A way to calculate Pi
Originally Posted by Mathiaslylo
Well that doesn't provide an accurate result at all.
After the first 2 digits, it's already entirely incorrect.
I know this is inaccurate ... just a demo of how to do it using the GregoryLeibniz method.
Check this wikipedia link for more details

Oct 6th, 2011, 03:49 AM
#9
Re: A way to calculate Pi
Originally Posted by i00
I know this is inaccurate ... just a demo of how to do it using the GregoryLeibniz method.
Check this wikipedia link for more details
Reminds me of Professor Frink's sarcasm detector. Comic Book Guy: Now that's really useful ... (machine explodes)
Just kidding Kris, it's a nice code example. BB

Nov 12th, 2011, 01:19 PM
#10
Hyperactive Member
Re: A way to calculate Pi
@i00 Seems like you and I are stuck in the same boat.
vbnet Code:
Public ReadOnly Property Pi(ByVal Optional limit As Int32 = 25) As Double 'Pi = (6(1/1^2 + 1/2^2 + 1/3^2 + 1/4^2 + ...))^(1/2) Get Dim result As Double Dim tmp As Double = 0.0 For i As Int32 = 1 To limit tmp = tmp + (1/i)^2 Next result = (6*tmp)^(1/2) Return result End Get End Property
This is only as accurate as the number of times you process it.. and of course the higher you go the longer it takes. I've pushed it to 100,000,000x before I realized this is not practical for my applications use. 100,000,000x gave me 3.14159264498239. My guess is 1,000,000,000x will produce 3.14159265... so on and so forth.. just as you proposed in your method.
Last edited by DavesChillaxin; Nov 12th, 2011 at 01:26 PM.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
Survey posted by VBForums.
