About incomplete gamma function

3 Ansichten (letzte 30 Tage)
YOGESH VIRKAR
YOGESH VIRKAR am 17 Aug. 2011
Hi,
I require the incomplete gamma function for my MLE calculations. I realize that the implementations in Mathematica and matlab are different.
Basically I want to calculate value of this integral,
int(t^(a-1)*exp(-t), t, x, inf), where a and x are inputs to the incomplete gamma function.
The problem here is not that I want the upper tail, but that matlab implementation which is,
gammainc(x,a), is different from what I want i.e. gammainc(a,x), the parameters in this case are reversed.
But matlab does not allow negative value for a, which is why a simple swapping of input parameters is not working in my case.
If I try to integrate using matlab's int function, the speed of execution is very slow (though I get the desired answer). I was wondering if someone could suggest a faster way for me to do this. My guess is that matlab's gammainc uses mex files to speed things up, but if someone could suggest a more convenient way, I would really appreciate it.
Thanks,
Yogesh

Antworten (1)

Mike Hosea
Mike Hosea am 18 Aug. 2011
I'm confused by the swapping parameters aspect, perhaps because I have not used Mathematica for nearly two decades. Could we forget about gammainc functions in MATLAB and Mathematica for a moment and just tell me the integral you want to evaluate and the ranges of the two parameters that you want it to work for? For example, "I want to evaluate the integral of t^(a-1)*exp(-t) from x to infinity where a > 0 and x >= 1" or whatever it has to be. -- Mike
  5 Kommentare
Mike Hosea
Mike Hosea am 18 Aug. 2011
If you will allow the constraint x > 0, you can use QUADGK (with whatever tolerances you like). You have to put it in a loop for vector inputs:
function y = foo(x,a)
y = zeros(size(x));
for k = 1:numel(y)
y(k) = quadgk(@(t)t.^(a(k)-1).*exp(-t),x(k),inf,'abstol',1e-12,'reltol',1e-12);
end
YOGESH VIRKAR
YOGESH VIRKAR am 18 Aug. 2011
Hi Mike,
My x's are always positive....thanks a ton. That works! I had this big deadline in two days, and now I am good!
Thanks,
Yogesh

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by