Post your method of calculating pi.

notfred

Lifer
Feb 12, 2001
38,241
4
0
I wrote a little script to calculate pi based on the series (-1)^(n+1) * (1/(2n-1)).
It does the first million iterations, and is fairly accurate, I get: 3.14159165358977

here's the script:
#!/usr/bin/perl -w
$pi = 0;
for($n = 1; $n <= 1000000; $n++){
$pi += (-1)**($n+1) * (1/(2 * $n - 1));
}
$pi *= 4;
print "$pi\n";

I'm sure there are more effecient ways than that, and there are those calcultors on line that can jsut keep spitting out pi to as many places as you like.

Anyone got any good pi computations?
 

edro

Lifer
Apr 5, 2002
24,326
68
91
I hit the PI key on my TI-89 and it does a farely good job of calculating it :D
 

FoBoT

No Lifer
Apr 30, 2001
63,084
15
81
fobot.com
Originally posted by: Tyler
is fairly accurate

um, is that like fairly pregnant?

isn't a number either pi or not?

how can it only be "fairly" accurate, it either calculates pi or it doesn't?

:confused:
 

jbahseng

Golden Member
Mar 13, 2001
1,231
0
76
Originally posted by: Tyler
I wrote a little script to calculate pi based on the series (-1)^(n+1) * (1/2n-1).
It does the first million iterations, and is fairly accurate, I get: 3.14159165358977

Shouldn't it be 3.1415926535....?

 
Jan 31, 2002
40,819
2
0
Ingredients
- 6 cups thinly sliced apples
- 3/4 cup white sugar
- 1 tablespoon butter
- 1 teaspoon ground cinnamon
- 1 pastry for a 9 inch single crust pie

Directions
- Prepare your pastry for a two crust pie. Wipe, quarter, core, peel, and slice apples; measure to 6 cups.
- Combine sugar and cinnamon. The amount of sugar used depends on how tart your apples are.
- Arrange apples in layers in pastry lined pie plate. Sprinkle each layer with sugar and cinnamon. Dot top layer with small pieces of butter or margarine. Cover with top crust.
- Place on lowest rack in oven preheated to 450 degrees F (230 degrees C). Bake for 10 minutes, then reduce oven temperature to 350 degrees F (175 degrees C). Bake for 30 to 35 minutes longer. Serve warm or cold.

That's how I calculate pie.

- M4H
 

pyonir

Lifer
Dec 18, 2001
40,856
321
126
Originally posted by: edro13
I hit the PI key on my TI-89 and it does a farely good job of calculating it :D

I did that in high school. I've never had to use it since then, so i don't calculate Pi
 

AvesPKS

Diamond Member
Apr 21, 2000
4,729
0
0
Originally posted by: FoBoT
Originally posted by: Tyler
is fairly accurate

um, is that like fairly pregnant?

isn't a number either pi or not?

how can it only be "fairly" accurate, it either calculates pi or it doesn't?

:confused:

Unless you've got an infinite amount of time, all you can do is approximate Pi. I always go for 22/7.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: FoBoT
Originally posted by: Tyler
is fairly accurate

um, is that like fairly pregnant?

isn't a number either pi or not?

how can it only be "fairly" accurate, it either calculates pi or it doesn't?

:confused:

It's an infinite series. The farther out I go, the closer I get to pi. You don't expect me to do an infinite number of calculations, do you? I did 1 million, which, IMO, is fairly accurate.

-w enables warnings.
 

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
Originally posted by: FoBoT
Originally posted by: Tyler
is fairly accurate

um, is that like fairly pregnant?

isn't a number either pi or not?

how can it only be "fairly" accurate, it either calculates pi or it doesn't?

:confused:


The number "pi" can never be completely accruate since it doesn't end...as far as anyone's found. Therefore you're always using a "fairly" accurate representation of it.

amish
 

Viper GTS

Lifer
Oct 13, 1999
38,107
433
136
I actually did a paper on methods of calculating pi (was assigned in a calculus class).

I don't recall the specifics of the generally accepted standard (at least at that time), but it got complex VERY quickly. After only three iterations it became too complicated to easily fit on one page, & to obtain any decent level of accuracy you had to do it 30+ times.

For my purposes SuperPi works great.

:D

Viper GTS
 

FoBoT

No Lifer
Apr 30, 2001
63,084
15
81
fobot.com
Originally posted by: Tyler
Originally posted by: FoBoT
Originally posted by: Tyler
is fairly accurate

um, is that like fairly pregnant?

isn't a number either pi or not?

how can it only be "fairly" accurate, it either calculates pi or it doesn't?

:confused:

It's an infinite series. The farther out I go, the closer I get to pi. You don't expect me to do an infinite number of calculations, do you? I did 1 million, which, IMO, is fairly accurate.

-w enables warnings.


oh, you mean it is accurate as far as you have gone, ok , i get it
i thought you meant some early digits might be off, nevermind
 

Haircut

Platinum Member
Apr 23, 2000
2,248
0
0
You can use:

PI = 24 arctan(1/8) + 8 arctan(1/57) + 4 arctan(1/239)

where arctan(x) = x - x^3/3 + x^5/5 - x^7/7 + ...

This will converge much faster.