DADiSP Worksheet Functions > Function Categories > Special Functions > GAMMALN
Computes the natural log of the gamma function. GAMMALN is often used in place of GAMMA when the value of GAMMA becomes very large.
GAMMALN(z)
z |
- |
A scalar, series or table, the exponential factor. |
A scalar, series, or table.
gammln({1,2,3})
returns a series {-3.4136E-011,-7.8188E-011,6.9315E-001}, the natural log of GAMMA.
a = gammaln(1+i);
b = ln(gamma(1+i));
a == b == -0.650923 - 0.301640i
The gamma function Γ(z), is defined as:
The gamma function for integer n is the factorial of n - 1 such that:
gamma(n) == prod(1..n-1)
The gamma function extends the factorial function for real and complex values and can be considered an interpolating function for the integer factorial function.
GAMMALN computes the natural log of the GAMMA function:
For z < 0, GAMMALN uses a 15 term Lanczos approximation developed by Paul Godfrey to achieve 15 digit accuracy for real inputs and 13 digit accuracy for complex inputs. For other values of z, an algorithm due to Didonato and Morris is employed [1].
In practice, it is often advisable to recast equations to use GAMMALN instead of GAMMA, as the GAMMA value of arguments greater than 171.62 exceeds the maximum floating point representation.
Algorithm 708: Significant Digit Computation of the Incomplete Beta Function Ratios
TOMS 1992, 18(3), 360-373