Gamma function should not take any negative value as an argument. Look at the code below where strange thing happens. Is this some problem with R?
I was using function optim
to optimize some function containing:
gamma(sum(alpha))
with respect to alpha
. R returns negative alpha
.
> gamma(sum(alpha))
[1] 3.753+14
>sum(alpha)
[1] -3
gamma(-3)
[1] NaN
Warning message:
In gamma(-3) NaN's produced.
Can somebody explain? Or any suggestion for the optimization?
Thanks!