Documentation

# `gamma`

Gamma function

MuPAD® notebooks will be removed in a future release. 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.

## Syntax

```gamma(`x`)
gamma(`iv`)
```

## Description

`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 floating-point value, then `gamma` returns a floating-point value. If `x` is a floating-point interval, `gamma` returns a floating-point 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 floating-point attribute of `gamma` is a kernel function, that is, floating-point 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 Γ(kx) 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`.

## Environment Interactions

When called with a floating-point argument, the function is sensitive to the environment variable `DIGITS` which determines the numerical working precision.

## Examples

### Example 1

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 floating-point arguments:

```gamma(11.5), gamma(2.0 + 10.0*I)```
` `

### Example 2

`gamma` is singular for nonpositive integers:

`gamma(0)`
```Error: Singularity. [gamma] ```

### Example 3

`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)`
` `

### Example 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]):``` ## Parameters

 `x` `iv`

## Return Values

Arithmetical expression or a floating-point interval.

`x`