Hilbert's Hotel

Diskussionsforum zur Unendlichkeit: Theismus, Atheismus, Primzahlen, Unsterblichkeit, das Universum...
Discussing Infinity: theism and atheism, prime numbers, immortality, cosmology, philosophy...

Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 877 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Calculating Pi #205319
05/05/08 20:36
05/05/08 20:36
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
Our infinite most beautiful number:

Here a way to calculate PI in Java.
(btw, LiteC is just using some different expressions for loops,
square-roots and float values)

 Code:
//calculating PI
		
		double sum=0;
		double adder=0;
		for (int i=0; i<2000000;i++)  //the more, the more exact
		{
			adder+=1;
			sum+=(1/(adder*adder));
		}
		
		sum = sum*6;
		sum=Math.sqrt(sum);  //quare root, the result is PI !!

		System.out.println("Pi is:"+sum);



gives us: 3.1415921761250813 (well its close)

Are there suggestions to calculate it quicker ?

Re: Calculating Pi [Re: Oxy] #205324
05/05/08 20:47
05/05/08 20:47
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
http://crd.lbl.gov/~dhbailey/bbp-formula.bmp gives you the n-th digit of pi without having to calculate the n-1 previous digits.

Last edited by Joey; 05/05/08 20:47.
Re: Calculating Pi [Re: Joey] #205325
05/05/08 20:52
05/05/08 20:52
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
Ok, cool, thanks

Re: Calculating Pi [Re: Oxy] #205648
05/07/08 18:53
05/07/08 18:53
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
how does that work, by the way? i only see a function which diverges very quickly to pi.

Re: Calculating Pi [Re: Joey] #205674
05/07/08 21:45
05/07/08 21:45
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
The code I posted comes actually from Euler, who found out that the sum
of the infinite chain of natural numbers:

1/(1*1) + 1/(2*2) + 1/(3*3) ....

is exactly (PI*PI)/6

Thus we can calculate PI (using computers calculation power to get
the value of the infinite chain)

Re: Calculating Pi [Re: Oxy] #205724
05/08/08 08:07
05/08/08 08:07
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i meant the formula i gave you.

have you tried 3 + 1/3 - 1/5 + 1/7 - 1/9...? this should be also faster than your approach.


Moderated by  jcl, Lukas, old_bill, Spirit 

Kompaktes W�rterbuch des UnendlichenCompact Dictionary of the Infinite


Powered by UBB.threads™ PHP Forum Software 7.7.1