# How to compute the upper incomplete gamma function in MATLAB?

I need to compute the upper incomplete gamma function $$\Gamma(0,i\pi K)$$ where $i=\sqrt{-1}$ and K is real.

I have some basic idea about what this "special function" is, but am not used to using it. I am confused because MATLAB refuses to compute this for me - I get an error message says that inputs must be real.

The CAS wxMaxima computes it no problem with or without complex or inputs. How can I implement this in MATLAB?

In MATLAB the command I am using is 1 - gammainc(a,z)

In wxMaxima the command is gamma_incomplete(a,z) or gamma_incomplete_regularized(a,z).

EDIT: What I mean to say here is that, in MATLAB, I want to get the same result that gamma_incomplete(a,z) gives in wxMaxima. For example, in wxMaxima the command gamma_incomplete(0,%i*%pi); gives the output 0.28114072518757*%i-0.073667912046426 Now what do I have to do in MATLAB to get the same result?

-

Your inputs are the wrong way round. Additionally, you should specify that you want the upper tail of the gamma function, rather than subtracting from 1. This gives more accurate values in the case where the real part of $\Gamma(x,a)$ is near to 1.

On Wolfram Alpha you have

$$\Gamma(1,i) = 0.5403 - 0.8415i$$

and in Matlab

>> gammainc(1i,1,'upper')
ans =
0.5403 - 0.8415i


which matches up.

-
This is what I get when I enter pretty much the exact same thing. >> gammainc(i*pi,1,'upper') ??? Error using ==> gammainc Inputs must be real, full, and double or single. – ben Oct 11 '12 at 15:15
On my machine that returns -1.0000 + 0.0000i. What version of Matlab do you have? Have you checked that you don't have a variable called i in your environment? It's always good practice to declare complex numbers with the 1+2i format, rather than using i on its own. It prevents errors where you accidentally overwrite i with some other value (e.g. if you use it in a loop counter). In this example you could write 1i*pi instead of i*pi. – Chris Taylor Oct 11 '12 at 15:17
Version 7.10 R2010a. When I enter "i" in the command line I get the following, so I think the program recognizes it as such: >> i ans = 0 + 1.000000000000000i – ben Oct 11 '12 at 15:20
If you type edit gammainc and look at the last line of the header comment to get the revision number, what do you see? For example, I see % $Revision: 5.17.4.3$ $Date: 2004/07/05 17:02:00$. – Chris Taylor Oct 11 '12 at 15:22
I get: % $Revision: 5.17.4.5$ $Date: 2008/10/31 06:20:55$ – ben Oct 11 '12 at 15:23

Chris mentioned the symbolic toolbox. The upper incomplete gamma function is now implemented as igamma in the symbolic toolbox.

>> igamma(0,i*pi)
ans =
-0.0737 + 0.2811i

-