Advertisement
jukaukor

Basel_rapid.py

Jun 23rd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # Basel problem, converges rapidly
  2. # Calculates with wanted number precision
  3. # Juhani Kaukoranta 23.6.2018
  4.  
  5. from decimal import *
  6. import math
  7.  
  8.  
  9. def binomial(n,k):
  10. a = math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
  11. return(a)
  12.  
  13. def Basel(precision):
  14. getcontext().prec=precision
  15. b = Decimal(0)
  16. for n in range(1,2*precision):
  17. b = b+Decimal(1)/(n*n*binomial(2*n,n))
  18. return(3*b)
  19. precision = int(input("How many numbers precision, f.eq 100 "))
  20. print("Basel problem = ",Basel(precision))
  21. print("Pi^2/6 = ",math.pi*math.pi/6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement