Incomplete Gamma Function in Matlab

dmw16

Diamond Member
Nov 12, 2000
7,608
0
0
Does anyone know how to use the incomplete gamma function in matlab (or mathematica?)

I need to solve, as an example gammaincomplete(1-C1*C4) where I know C1 and C4. I know I need the upper result.

The syntax is gammainc(X,A)

I assume X is the matrix of values I am integrating between and A is the matix of results when plugging in X?

This may seem like a stupid question, but I am fresh back to grad school after 3 years of not taking classes (since I graduated) and a lot of this math has some dust on it.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
If I'm understanding your problem, you should try

gammainc(x,1-C1*C4,'upper')

where x is the upper limit of integration (i.e. when you're integrating from 0 to x).
 

dmw16

Diamond Member
Nov 12, 2000
7,608
0
0
Thanks. I had already found the docs.

My confusion was with how to apply the syntax.

In this case, I actually want the upper bound, so I want to integrate from something to 1...
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
The complete gamma function includes an integral from zero to infinity. MATLAB formulates the incomplete gamma function simply by changing the limits of integration to 0 to x. If you want to do what you're proposing, you'll have to modify the gammainc function into a new function file, since the gammainc function won't allow the limits that you need.
 

dmw16

Diamond Member
Nov 12, 2000
7,608
0
0
then what does 'upper' do? I thought that the UPPER call implied integrating from x to y.
 

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
Originally posted by: dmw16
then what does 'upper' do? I thought that the UPPER call implied integrating from x to y.
You may be right, though the documentation is slightly confusing to me on this point. It says that using the upper will give 1 - gammainc(x,a). I think this will give you what you want for some cases of x and a, but I'm not sure that it will work for all since gammainc approaches 1 as x goes to infinity. I'm really not that familiar with this particular function's behavior, so I don't want to tell you the wrong thing. I'm just trying to give advice based on the documentation.

It would be relatively easy to write your own function that does exactly what you're trying to do. Something like the attached code should do the trick.

edit: attached code had no line breaks... wtf. Here it is in plain text:

function P=gammainc1(xl,xu,a)
%xl is the lower limit on x
%xu is the upper limit on x
%a is a

fun=@(t) exp(-t)*t.^(a-1);%integrand
integral=int(fun,xl,xu);%numerical integrator - could use trapz, for example
P=integral/gamma(x,a);%compute the incomplete gamma function