Monte Carlo Method and pi
Fri Jul 9 00:14:23 CEST 2004
"Karl Pech" <KarlPech at users.sf.net> writes:
> I got a task there I have to compute pi using the
> Method above.
This sounds like a homework problem...
> for i in range(0, n):
> x = random.random() # coordinates
> sy += math.sqrt(1-math.sqrt(x)) # calculate y and add to sy
> print 4*sy/n # compute pi
> Unfortunately, even for n = 2000000 the result is ~2,13... .
> It converges very slow to pi and I don't know why.
Better make sure the formulas are correct, by asking yourself why the
simulation is supposed to work at all.
More information about the Python-list