gamma

Gamma function, the extension of the factorial to real numbers.

Category: Mathematics > Elementary Math

Syntax

Y = gamma(X)

Evaluates the gamma function at each element of X.

Description

For positive integers, gamma(n) equals factorial(n-1). For other real values it interpolates smoothly between them, with gamma(0.5) equal to sqrt(pi). The function has poles at zero and at the negative integers, where gamma returns Inf, and it alternates in sign between consecutive negative poles.

The values grow so quickly that they overflow for large arguments. When only the logarithm is needed, gammaln avoids the overflow.

Input arguments

X
Real array.

Output arguments

Y
Array of the same size as X.

Example

Factorials and half-integers

gamma([1 2 5])
gamma(0.5)^2
gamma([0 -1.5])
Output
ans = 1×3

     1     1    24
ans = 3.1416
ans = 1×2

       Inf    2.3633

See also

gammaln factorial gammainc psi beta