This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Gamma function


Y = gamma(X)



Y = gamma(X) returns the gamma function evaluated at the elements of X.


collapse all

Evaluate the gamma function with a scalar and a vector.

Evaluate , which is equal to .

y = gamma(0.5)
y = 1.7725

Evaluate several values of the gamma function between [-3.5 3.5].

x = -3.5:3.5;
y = gamma(x)
y = 

  Columns 1 through 7

    0.2701   -0.9453    2.3633   -3.5449    1.7725    0.8862    1.3293

  Column 8


Plot the gamma function and its inverse.

Use fplot to plot the gamma function and its inverse. The gamma function increases quickly for positive arguments and has simple poles at all negative integer arguments (as well as 0). The function does not have any zeros. Conversely, the inverse gamma function has zeros at all negative integer arguments (as well as 0).

hold on
fplot(@(x) 1./gamma(x))
hold off
grid on

Input Arguments

collapse all

Input array, specified as a scalar, vector, matrix, or multidimensional array. The elements of X must be real.

Data Types: single | double

More About

collapse all

Gamma Function

The gamma function is defined for real x > 0 by the integral:


The gamma function interpolates the factorial function. For integer n:

gamma(n+1) = factorial(n) = prod(1:n)

The domain of the gamma function extends to negative real numbers by analytic continuation, with simple poles at the negative integers. This extension arises from repeated application of the recursion relation



The computation of gamma is based on algorithms outlined in [1]. Several different minimax rational approximations are used depending upon the value of A.


[1] Cody, J., An Overview of Software Development for Special Functions, Lecture Notes in Mathematics, 506, Numerical Analysis Dundee, G. A. Watson (ed.), Springer Verlag, Berlin, 1976.

[2] Abramowitz, M. and I.A. Stegun, Handbook of Mathematical Functions, National Bureau of Standards, Applied Math. Series #55, Dover Publications, 1965, sec. 6.5.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?