Python program to calculate `\pi`
Python program to calculate π
Chundnovsky's formulae:
`\frac{426880\sqrt{10005}}{\pi}=`
`\sum _{k=0}^{\infty}\frac{(6k)!(13591409+545140134k)}{(3k)!(k!)^3(-640320)^{3k}}`
import decimal
import math
#we use Chundnovsky's formulae
def compute_pi(n):
decimal.getcontext().prec=n+1
A=426880*decimal.Decimal(10005).sqrt()
B=6
C=1
D=1
E=13591409
F=E
for i in range(1,n):
C=C*((1728*i*i*i)-(2592*i*i)+(1104*i)-120)/(i*i*i)
E+=545140134
D*=0-262537412640768000
F+=decimal.Decimal(C*E)/D
pi=A/F
return pi
n=int(input("Enter decimal places:"))
P=compute_pi(n)
print(P)
if there is any mistake, please comment!
You are really a mathematician as well as a programmer! Pride to be an Russian
ReplyDelete