gamma
Gamma function
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
gamma(x
) gamma(iv
)
gamma(x)
represents the gamma function .
The gamma function is defined for all complex arguments apart from the singular points 0,  1,  2, ….
The gamma function is related to the factorial function: gamma(x)
= fact(x  1) = (x  1)!
for all positive integers x
.
If x
is a floatingpoint value, then gamma
returns
a floatingpoint value. If x
is a floatingpoint
interval, gamma
returns a floatingpoint interval.
If x
is a positive integer not larger than the
value given by Pref::autoExpansionLimit()
, then
an integer is returned. (Use expand(gamma(x))
to
get an integer value for larger integers x
.) If x
is
a rational number of domain type DOM_RAT
not larger than the value given
by Pref::autoExpansionLimit()
, then the functional
relation Γ(x +
1) = x Γ(x) is
applied to “normalize” the result. (Again, use expand(gamma(x))
to
enforce this normalization for larger rational numbers x
.)
The functional relation
is applied if is
a rational number of domain type DOM_RAT
that is an integer multiple of or .
The call gamma(1/2)
yields sqrt(PI)
.
The call gamma(infinity)
yields infinity
.
For all other arguments, a symbolic function call is returned.
The floatingpoint attribute of gamma
is
a kernel function, that is, floatingpoint evaluation is fast.
The expand
attribute
rewrites gamma(x)
by using the functional equation Γ(x +
1) = x Γ(x),
the reflection formula
,
and the Gauss multiplication formula for Γ(k x) when k is
a positive integer. See Example 3.
For numerical x
, the functional equation is used
to shift the argument to the range 0 < x < 1
.
The functional equations for gamma
lead to
various identities for lngamma
which can be applied
via expand
. See Example 3.
The logarithmic derivative of gamma
is implemented
by the digamma function psi
.
When called with a floatingpoint argument, the function is
sensitive to the environment variable DIGITS
which determines
the numerical working precision.
Call gamma
with exact and symbolic input
data:
gamma(15), gamma(3/2), gamma(3/2), gamma(sqrt(2)), gamma(x + 1)
Call gamma
with floatingpoint arguments:
gamma(11.5), gamma(2.0 + 10.0*I)
gamma
is singular for nonpositive integers:
gamma(0)
Error: Singularity. [gamma]
diff
, expand
, float
, limit
, and series
handle expressions
involving gamma
:
diff(gamma(x^2 + 1), x)
float(ln(3 + gamma(sqrt(PI))))
expand(gamma(x + 2))
expand(gamma(2*x))
expand(gamma(2*x  1))
limit(1/gamma(x), x = infinity)
limit(gamma(x  4)/gamma(x  10), x = 0)
series(gamma(x), x = 0, 3)
The Stirling formula is obtained as an asymptotic series:
series(gamma(x), x = infinity, 4)
The logarithm function ln
has
a branch cut along the negative real semi axis, where the values jump
by 2 π i when
crossing the cut. In the following plot of the imaginary part of the
logarithm of the gamma function the lines in the complex z plane
with and are
clearly visible as discontinuities:
plotfunc3d(Im(ln(gamma(x + I*y))), x = 10 .. 10, y = 10 .. 10, Submesh = [2, 2], CameraDirection = [0, 1, 1000]):
The function lngamma(z)
, however, adds suitable
integer multiples of 2 π i to ln(gamma(z))
making
the function analytic throughout the complex plane with a branch cut
along the negative real semi axis:
plotfunc3d(Im(lngamma(x + I*y)), x = 10 .. 10, y = 10 .. 10, Submesh = [2, 2], CameraDirection = [0, 1, 1000]):
 

Arithmetical expression or a floatingpoint interval.
x