[ADMB Users] factln
davef at otter-rsch.com
Wed Sep 11 10:57:42 PDT 2013
Has any one noticed small errors in double factln(double n) for small
values of n?
I'm getting the following for n = 0 ... 5
n factn(n) n!
0 -3.41362e-11 1
1 -7.81881e-11 1
2 0.693147 2
3 1.79176 6
4 3.17805 24
5 4.78749 120
Which seem to be incorrect for n=0 and n=1. The difference between 1e-11
is quite small but it turns out to make a difference after a
sufficiently long computation.
The algorithm depends on a series approximation for the log gamma
function. Perhaps arguments 0 and 1 should be treated a special cases?
another way to deal with this is to find out what the derivatives say 1
and 2 of the
function are. Then you can replace it with
factn(x) = factn'(0)*x + 0.5* factn''(0)*x*x
which will probably suffice for say |x|<1.e-5
according this guy
fact'(1) = -euler const.
fact''(1) = (euler const)^2 + pi^2/6
More information about the Users