FreeMat
GAMMA Gamma Function

Section: Mathematical Functions

Usage

Computes the gamma function for real arguments. The gamma function takes only a single argument

  y = gamma(x)

where x is either a float or double array. The output vector y is the same size (and type) as x.

Internals

The gamma function is defined by the integral:

\[ \Gamma(x) = \int_{0}^{\infty} e^{-t} t^{x-1} \, dt \]

The gamma function obeys the interesting relationship

\[ \Gamma(x) = (x-1)\Gamma(x-1), \]

and for integer arguments, is equivalent to the factorial function.

Example

Here is a plot of the gamma function over the range [-5,5].

--> x = linspace(-5,5);
--> y = gamma(x);
--> plot(x,y); xlabel('x'); ylabel('gamma(x)');
--> axis([-5,5,-5,5]);

which results in the following plot.

gamma1.png