Guest User

Untitled

a guest
May 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. *************
  2. value to take the log factorial of is 1
  3. Exact value is 0.0
  4. Small value approximation (K.V. Raman) is -1.0
  5. Stirling is -0.0810614667953
  6. Stirling with extra term is -0.00101875912179
  7. Ramanujan is -0.000143497498377
  8. *************
  9. *************
  10. value to take the log factorial of is 2
  11. Exact value is 0.69314718056
  12. Small value approximation (K.V. Raman) is 0.0794415416798
  13. Stirling is 0.651806484605
  14. Stirling with extra term is 0.805957164432
  15. Ramanujan is 0.693112511922
  16. *************
  17. *************
  18. value to take the log factorial of is 5
  19. Exact value is 4.78749174278
  20. Small value approximation (K.V. Raman) is 4.6566274746
  21. Stirling is 4.77084705159
  22. Stirling with extra term is 5.11915374586
  23. Ramanujan is 4.78748794075
  24. *************
  25. *************
  26. value to take the log factorial of is 10
  27. Exact value is 15.1044125731
  28. Small value approximation (K.V. Raman) is 15.3284360229
  29. Stirling is 15.0960820096
  30. Stirling with extra term is 15.7022178132
  31. Ramanujan is 15.1044119984
  32. *************
  33. *************
  34. value to take the log factorial of is 20
  35. Exact value is 42.3356164608
  36. Small value approximation (K.V. Raman) is 42.9103777446
  37. Stirling is 42.3314501411
  38. Stirling with extra term is 43.3122793941
  39. Ramanujan is 42.3356163818
  40. *************
  41. *************
  42. value to take the log factorial of is 1000
  43. Exact value is 5912.12817849
  44. Small value approximation (K.V. Raman) is 5914.66303426
  45. Stirling is 5912.12809515
  46. Stirling with extra term is 5916.56287235
  47. Ramanujan is 5912.12817849
  48. *************
  49.  
  50. def logfact(n):
  51. from math import log
  52. sum = 0
  53. for i in range(1, n+1):
  54. sum = sum + log(i)
  55. return sum
  56.  
  57. def smallvalapprox(n):
  58. from math import log, pi
  59. return (n+1)*log(n) - n
  60.  
  61. def stirling(n):
  62. from math import log, pi
  63. return n*log(n) - n + 0.5*log(n) + 0.5*log(2*pi)
  64.  
  65. def stirlinge(n):
  66. from math import log, pi
  67. return n*log(n) - n + 0.5*log(n) + 0.5*log(2*pi) + log(1+(1.0/12*n))
  68.  
  69. def r(n):
  70. from math import log, exp, sqrt, pi
  71. #return sqrt((2*x + (1.0/3))*pi) * (x**pi)*(exp(-x))
  72. return n*log(n) - n + (log(n*(1+4*n*(1+2*n))))/6 + log(pi)/2
  73.  
  74.  
  75. def logfactapprox(x):
  76. print "*************"
  77. print "value to take the log factorial of is", x
  78. print "Exact value is", logfact(x)
  79. print "Small value approximation (K.V. Raman) is", smallvalapprox(x)
  80. print "Stirling is", stirling(x)
  81. print "Stirling with extra term is", stirlinge(x)
  82. print "Ramanujan is", r(x)
  83. print "*************"
  84.  
  85. logfactapprox(1)
  86. logfactapprox(2)
  87. logfactapprox(5)
  88. logfactapprox(10)
  89. logfactapprox(20)
  90. logfactapprox(1000)
Add Comment
Please, Sign In to add comment