About incomplete gamma function
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Mike Hosea
el 18 de Ag. de 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 comentarios
Mike Hosea
el 18 de Ag. de 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
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!