# GAMMA

## Purpose:

Evaluates the gamma function; a generalization of factorial for real and complex numbers.

## Syntax:

GAMMA(z)

 z - A scalar, series or table, the exponential factor.

## Returns:

A scalar, series, or table Γ(z).

## Example:

gamma({1,2,3,4})

returns series {1, 1, 2, 6}.

## Example:

gamma(1+i)

returns 0.498016 - 0.154950i

## Example:

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.

## Remarks:

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.