Evaluates the gamma function; a generalization of factorial for real and complex numbers.
GAMMA(z)
z |
- |
A scalar, series or table, the exponential factor. |
A scalar, series, or table Γ(z).
gamma({1,2,3,4})
returns series {1, 1, 2, 6}.
gamma(1+i)
returns 0.498016 - 0.154950i
x = 0..5;
xx = 0..0.01..5;
W1: gamma(xx+1);overp(gamma(x+1),lred);
W1: setsym(1014,2);setplotstyle(1,2);setx(-1,6);scales(2);
W1: xlabel("x");ylabel("\Gamma(x+1)");
W1: label("\Gamma(x+1) and x!");
Demonstrates the interpolation property of the gamma function.
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. As shown in the last example, the gamma function can be thought of as an interpolation function for the integer factorial function.
For z > 20 or z < 0, GAMMA 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. A recurrance relation is used for all other values of z.
In practice, it is often advisable to use the natural log version of GAMMA, GAMMALN, because GAMMA will exceed the maximum floating point representation for arguments greater than about 171.62.
See GAMMAP and GAMMAQ for implementations of the incomplete gamma function.
See GAMMAINC for an alternate implementation of the incomplete gamma function.
See GAMM for the γ constant.
See FACTORIAL to compute the factorial of positive integers.