How to compute the incomplete Gamma function with an negetive parameter in MATLAB?

2.6k Views Asked by At

I need to compute the upper incomplete gamma function $$\Gamma(-0.5,0.5r)$$ But in MATLAB, the upper incomplete Gamma function "gammainc" is defined as $$\Gamma\left(\alpha ; x\right) = \dfrac{1}{\Gamma(\alpha)}\int\limits_{x}^{\infty}t^{\alpha - 1}e^{-t}\text{ d}t\text{.}$$ with parameter $\alpha > 0$.

When I type "gammainc(0.5,-0.5*1,'upper')", the MATLAB says "Error using gammainc, A must be real and non-negative!"

But actually what I want to get is defined as this From Wolfram MathWorld: $$\Gamma(\alpha;x) = \int\limits_{x}^{\infty}t^{a-1}e^{-t}\text{ d}t\text{.}$$ So what do I have to do to get the results in MATLAB ?

2

There are 2 best solutions below

3
On

Please notice, in the Matlab Function (gammainc(x,a)) , the position of $\alpha$ and x is different, see the help. Due to the help, you should enter the codes as below:

$$ \Gamma(a,x) = {\Gamma(\alpha)}\ * \ gammainc(x,a,'upper')$$

In fact, it returns regularized incomplete Gamma function

Otherwise, if you know this tip check below:

Does the definition of the upper case incomplete gamma function $\Gamma(a,x)=\int_{x}^{\infty}e^{-t}\ t^{a-1}$ hold for any integer $a$?

1
On

Here's a MATLAB function that claims to compute the upper incomplete Gamma function for negative $\alpha$: http://www.mathworks.com/matlabcentral/fileexchange/29321-evaluation-of-the-upper-incomplete-gamma-function/content/gamma_incomplete.m