Beta function...

Ben Abbott bpabbott at mac.com
Mon Mar 17 14:40:27 CDT 2008


On Monday, March 17, 2008, at 02:56PM, "Jorge Londoño" <jmlon at yahoo.com> wrote:
>I just happen to jump into a problem that require me to compute the Beta function with negative arguments.
>If you look at the definition of the beta function, for example here:
>
>http://mathworld.wolfram.com/BetaFunction.html, or
>http://en.wikipedia.org/wiki/Beta_function
>
>you will notice it is ok to evaluate the beta function at negative values, as far as they are not integers.
>
>The current implementation of the Beta function uses the logarithmic gamma function:
>
>retval = exp (gammaln (a) + gammaln (b) - gammaln (a+b))
>
>which does not work for negative numbers. (This line is taken from /usr/share/octave/2.9.12/m/specfun/beta.m)
>
>Using the alternative definition of the gamma function:
>x = gamma(a)*gamma(b)/gamma(a+b)
>
>it returns the correct values for negative numbers.
>
>Jorge Londono

I did a quick comparison of gamma/gammaln

octave:30> x = 1:1e6;
octave:31> tic;gammaln(x);toc
Elapsed time is 0.18 seconds.
octave:32> tic;gamma(x);toc
Elapsed time is 0.05 seconds.

If speed is not the issue, does anyone have an idea why gammaln was used instead of gamma?

Ben





More information about the Bug-octave mailing list