# igamma

Incomplete gamma function

## Syntax

``g = igamma(nu,z)``

## Description

example

````g = igamma(nu,z)` returns the upper incomplete gamma function.`igamma` uses the definition of the upper incomplete gamma function. However, the default MATLAB® `gammainc` function uses the definition of the regularized lower incomplete gamma function, where ```gammainc(z,nu) = 1 - igamma(nu,z)/gamma(nu)```. The order of input arguments differs between these functions.```

## Examples

collapse all

Depending on its arguments, `igamma` returns floating-point or exact symbolic results.

Compute the upper incomplete gamma function for these numbers. Because these numbers are not symbolic objects, you get floating-point results.

`g = [igamma(0,1), igamma(3,sqrt(2)), igamma(pi,exp(1)), igamma(3,Inf)]`
```g = 1×4 0.2194 1.6601 1.1979 0 ```

Compute the upper incomplete gamma function for the numbers converted to symbolic objects.

```symg = [igamma(sym(0),1), igamma(3,sqrt(sym(2))), ... igamma(sym(pi),exp(sym(1))), igamma(3,sym(Inf))]```
`symg = $\left(\begin{array}{cccc}-\text{ei}\left(-1\right)& {\mathrm{e}}^{-\sqrt{2}} \left(2 \sqrt{2}+4\right)& \Gamma \text{igamma}\left(\pi ,\mathrm{e}\right)& 0\end{array}\right)$`

Use vpa to approximate symbolic results with floating-point numbers.

`vpag = vpa(symg)`
`vpag = $\left(\begin{array}{cccc}0.21938393439552027367716377546012& 1.6601049038903044104826564373576& 1.1979302081330828196865548471769& 0\end{array}\right)$`

`igamma` is implemented according to the definition of the upper incomplete gamma function. If you want to compute the lower incomplete gamma function, convert results returned by `igamma` as follows.

Compute the upper incomplete gamma function for these arguments using `igamma`.

```z = [-5/3, -1/2, 0, 1/3]; gupper = igamma(1/3,z)```
```gupper = 1×4 complex -0.3900 - 5.3156i 1.3156 - 2.3614i 2.6789 + 0.0000i 0.7569 + 0.0000i ```

Subtract these results out of the gamma function to obtain the lower incomplete gamma function.

`glower = gamma(1/3) - gupper`
```glower = 1×4 complex 3.0689 + 5.3156i 1.3634 + 2.3614i 0.0000 + 0.0000i 1.9220 + 0.0000i ```

For comparison, you can also calculate the regularized lower incomplete gamma function by using the MATLAB `gammainc` function. The regularized definition differs by the gamma function factor.

`glower2 = gammainc(z,1/3)*gamma(1/3)`
```glower2 = 1×4 complex 3.0689 + 5.3156i 1.3634 + 2.3614i 0.0000 + 0.0000i 1.9220 + 0.0000i ```

Because `gammainc` does not accept complex arguments, if one or both arguments are complex numbers, use `igamma` to compute the regularized lower incomplete gamma function.

`gcomplex = 1 - igamma(1/2,1i)/gamma(1/2)`
```gcomplex = 0.9693 + 0.4741i ```

## Input Arguments

collapse all

Input, specified as a symbolic number, variable, expression, or function, or as a vector or matrix of symbolic numbers, variables, expressions, or functions.

Input, specified as a symbolic number, variable, expression, or function, or as a vector or matrix of symbolic numbers, variables, expressions, or functions.

collapse all

### Upper Incomplete Gamma Function

The following integral defines the upper incomplete gamma function:

`$\Gamma \left(\eta ,z\right)=\underset{z}{\overset{\infty }{\int }}{t}^{\eta -1}{e}^{-t}dt$`

### Regularized Lower Incomplete Gamma Function

The following integral defines the regularized lower incomplete gamma function:

`$\gamma \left(z,\eta \right)=\frac{1}{\Gamma \left(\eta \right)}\underset{0}{\overset{z}{\int }}{t}^{\eta -1}{e}^{-t}dt,$`

where the gamma function $\Gamma \left(\eta \right)$ is defined by

`$\Gamma \left(\eta \right)={\int }_{0}^{\infty }{t}^{\eta -1}{e}^{-t}dt.$`

## Tips

• The MATLAB `gammainc` function does not accept complex arguments. For complex arguments, use `igamma`.

• `gammainc(z,nu) = 1 - igamma(nu,z)/gamma(nu)` represents the regularized lower incomplete gamma function in terms of the upper incomplete gamma function.

• `igamma(nu,z) = gamma(nu)*(1 - gammainc(z,nu))` represents the upper incomplete gamma function in terms of the regularized lower incomplete gamma function.

• `gammainc(z,nu,"upper") = igamma(nu,z)/gamma(nu)`.

## Version History

Introduced in R2014a