[comp.theory] PI and all that Jazz

00lhramer@bsu-ucs.uucp (Leslie Ramer) (12/12/90)

> Can anyone give me a good algorithm to generate pi?
> If possible, I would like one that generates a digit at a time.
> 
> Jeff
-- 

X[0] := 3.0
.
.
.
X[n+1] := X[n] + SIN ( X[n] )

My handy dandy calculator computes...

X[1] = 3.141120008
X[2] = 3.141592654 <- This is as accurate as my calculator will go.

This operates on a fixed-point solution from numerical analysis.  It converges
quite quickly, though.

Here's one that a friend of mine tried here at BSU.  Examine a unit square in
the first quadrant.  Superimpose the quarter of a unit circle in the first
quadrant also.  Now from a random number generator pick x and y such that
0<=x<=1 && 0<=y<=1      Now to check and see if it fell in the unit circle,
x*x + y*y <= 1          The probability of it falling in the circle is
equal to the area of the quarter circle divided by the area of the unit square.
In other words, keep track of all the times the point fell in the circle as
opposed to the total number of random points you have tried, and the ratio of
the two is PI/4.  Of course you will have to pick several thousand points
to get much accuracy.  With the Bufon needle simulation, I remember simulations
that ran on the order of 200 thousand simulations before an accuracy of the
hundreths was assured.

Something that I found interesting was a mistake that I made in the
simulation.  My program had a bug (actually as a freshman this bug was
just a misinterpretation of what we were supposed to do).  Onward and upward.
My program kicked out when the difference between a constant PI I had stored
in my program and the approximation was a small value.  What is interesting
is that after slightly more than 700 simulations I had a higher degree of
accuracy than my collegues whose programs dropped the needle 200k times.

The moral of the story?  This provoked a question, are there any "SPECIAL"
numbers of iterations that achieve a greater accuracy quicker than others?
If so, what are these special numbers?

(This can be fun!)

====         "No one runs so fast as he that is chased."
                ._
|    .-. .-.    | \ .-, .-.-. .-. .-.  00LHRAMER@bsu-ucs.bsu.edu
|    +-' `-,    |_/ .-+ | | | +-' |    00LHRAMER@bsu-ucs.UUCP
|___ `-' `-'    | \ `.| | | | `-' |    00LHRAMER@bsuvax1.bitnet