Start | raknautpi
 

Räkna ut PI



Räkna ut pi med python

Leibniz formel

iter = 5000 pi = 0 n = 1 t = 1 for i in range(iter): pi += (1/n)*t n += 2 t = -t pi *=4 print(pi)
John Wallis produkt
iter = 50000 t = 2 n = 1 pi = 2 for i in range(iter): if(i%2): t+=2 if(not i%2): n+=2 pi*=t/n pi *=2 print(pi)
def pos(d): return(neg(d-2) + 1/d) def neg(d): if d>0: return(pos(d-2) - 1/d) else: return(0) def pi(n): return(4 * pos(4*n+1)) print(pi(50))
12.57586479187 ms