Last active
December 3, 2017 09:54
-
-
Save idoushiki/1be13731975938b1d3245decd7414fc2 to your computer and use it in GitHub Desktop.
ガウス=ルジャンドルのアルゴリズム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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