Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *************
- value to take the log factorial of is 1
- Exact value is 0.0
- Small value approximation (K.V. Raman) is -1.0
- Stirling is -0.0810614667953
- Stirling with extra term is -0.00101875912179
- Ramanujan is -0.000143497498377
- *************
- *************
- value to take the log factorial of is 2
- Exact value is 0.69314718056
- Small value approximation (K.V. Raman) is 0.0794415416798
- Stirling is 0.651806484605
- Stirling with extra term is 0.805957164432
- Ramanujan is 0.693112511922
- *************
- *************
- value to take the log factorial of is 5
- Exact value is 4.78749174278
- Small value approximation (K.V. Raman) is 4.6566274746
- Stirling is 4.77084705159
- Stirling with extra term is 5.11915374586
- Ramanujan is 4.78748794075
- *************
- *************
- value to take the log factorial of is 10
- Exact value is 15.1044125731
- Small value approximation (K.V. Raman) is 15.3284360229
- Stirling is 15.0960820096
- Stirling with extra term is 15.7022178132
- Ramanujan is 15.1044119984
- *************
- *************
- value to take the log factorial of is 20
- Exact value is 42.3356164608
- Small value approximation (K.V. Raman) is 42.9103777446
- Stirling is 42.3314501411
- Stirling with extra term is 43.3122793941
- Ramanujan is 42.3356163818
- *************
- *************
- value to take the log factorial of is 1000
- Exact value is 5912.12817849
- Small value approximation (K.V. Raman) is 5914.66303426
- Stirling is 5912.12809515
- Stirling with extra term is 5916.56287235
- Ramanujan is 5912.12817849
- *************
- def logfact(n):
- from math import log
- sum = 0
- for i in range(1, n+1):
- sum = sum + log(i)
- return sum
- def smallvalapprox(n):
- from math import log, pi
- return (n+1)*log(n) - n
- def stirling(n):
- from math import log, pi
- return n*log(n) - n + 0.5*log(n) + 0.5*log(2*pi)
- def stirlinge(n):
- from math import log, pi
- return n*log(n) - n + 0.5*log(n) + 0.5*log(2*pi) + log(1+(1.0/12*n))
- def r(n):
- from math import log, exp, sqrt, pi
- #return sqrt((2*x + (1.0/3))*pi) * (x**pi)*(exp(-x))
- return n*log(n) - n + (log(n*(1+4*n*(1+2*n))))/6 + log(pi)/2
- def logfactapprox(x):
- print "*************"
- print "value to take the log factorial of is", x
- print "Exact value is", logfact(x)
- print "Small value approximation (K.V. Raman) is", smallvalapprox(x)
- print "Stirling is", stirling(x)
- print "Stirling with extra term is", stirlinge(x)
- print "Ramanujan is", r(x)
- print "*************"
- logfactapprox(1)
- logfactapprox(2)
- logfactapprox(5)
- logfactapprox(10)
- logfactapprox(20)
- logfactapprox(1000)
Add Comment
Please, Sign In to add comment