Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Basel problem, converges rapidly
- # Calculates with wanted number precision
- # Juhani Kaukoranta 23.6.2018
- from decimal import *
- import math
- def binomial(n,k):
- a = math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
- return(a)
- def Basel(precision):
- getcontext().prec=precision
- b = Decimal(0)
- for n in range(1,2*precision):
- b = b+Decimal(1)/(n*n*binomial(2*n,n))
- return(3*b)
- precision = int(input("How many numbers precision, f.eq 100 "))
- print("Basel problem = ",Basel(precision))
- print("Pi^2/6 = ",math.pi*math.pi/6)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement