Skip to content

Instantly share code, notes, and snippets.

@idoushiki
Last active December 3, 2017 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idoushiki/1be13731975938b1d3245decd7414fc2 to your computer and use it in GitHub Desktop.
Save idoushiki/1be13731975938b1d3245decd7414fc2 to your computer and use it in GitHub Desktop.
ガウス=ルジャンドルのアルゴリズム
import math
aa=0
bb=0
tt=0
a=[0]*20
a[0]=1
b=[0]*20
b[0]=1/(math.sqrt(2))
t=[0]*20
t[0]=0.25
p=[0]*20
p[0]=1
n=0
while n<19:
a[n+1]=(a[n]+b[n])/2
b[n+1]=math.sqrt(a[n]*b[n])
t[n+1]=t[n]-(p[n]*((a[n]-a[n+1])**2))
p[n+1]=2*p[n]
pi=((a[n]+b[n])**2)/(4*t[n])
print("{0:.20f}".format(pi))
n=n+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment