Advertisement
jukaukor

RamanujanPi.py

Jun 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. # Modified Ramanujan's formula of sqrt(2)/pi
  2. # Ramanujan wrote in 1914 his original formula of 1/pi
  3. # Juhani Kaukoranta 18.6.2018
  4.  
  5. from decimal import *
  6. import math
  7.  
  8.  
  9. def RamanujanInversePi(precision):
  10. getcontext().prec=precision
  11. inverse = Decimal(0)
  12. for n in range(0,precision):
  13. inverse = inverse + Decimal(1)*math.factorial(4*n)/(math.factorial(n))**4*(26390*n+1103)/396**(4*n)
  14.  
  15. inverse = inverse*4/9801
  16. return(inverse)
  17.  
  18. numbers = int(input("Kuinka monta numeroa haluat "))
  19. inversePi = RamanujanInversePi(numbers)
  20. print("sqrt(2)/pi = ",inversePi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement