I need help computing Pi. I am trying to write a python program that will compute Pi numbers to X. I tried several from the python mailing list and it should slow down for my use. I read about the Gauss-Legendre Algorithm , and I tried porting it to Python without success.
I read from here and I would appreciate any data on where I am going wrong!
Output: 0.163991276262
from __future__ import division import math def square(x):return x*x a = 1 b = 1/math.sqrt(2) t = 1/4 x = 1 for i in range(1000): y = a a = (a+b)/2 b = math.sqrt(b*y) t = t - x * square((ya)) x = 2* x pi = (square((a+b)))/4*t print pi raw_input()
python algorithm pi
Lobe Dec 07 '08 at 16:15 2008-12-07 16:15
source share