Difficulty calculating the lower incomplete gamma function for very large and small values
9 次查看(过去 30 天)
显示 更早的评论
Hi,
I've been using the expression gammainc(z,a)*gamma(a) to calculate the lower incomplete gamma function along with function vpa (to handle large numbers).
However, even when using vpa this fails at a certain point:
gamma(vpa(1e7))
ans =
1.2024234005159034561401534879443e+65657052
>> gamma(vpa(1e8))
ans =
Inf
I have tried taking logs, but have been unable to combine this with how I was calculating the lower incomplete gamma function (see previous question https://www.mathworks.com/matlabcentral/answers/540815-issue-with-gammainc-x-a-for-small-x-and-larger-a?s_tid=prof_contriblnk).
Is there a way to calculate both these large and small (very close to zero) values with necessary precision?
Thank you!
5 个评论
David Goodmanson
2020-6-27
The function gammainc(z,a)*gamma(a) is simply
Integral{0,x} x^(a-1) e^-x dx.
For small x you can just expand e^-x in a Taylor series and integrate term-by-term to obtain
result = x^a ( 1/a - x/(a+1) + x^2/(2!(a+2)) - x^3/(3!(a+3)) ... )
which is easy to calculate, although the factor in front takes special handling and in many cases can be expressed only in terms of its exponent.
Large x is harder, especially if 'a' is also large.
The range of 1e-8 to 1e8 for x is pretty reasonable, but since 'a' appears in the exponent in the integrand, large values of 'a' can lead to crazy large or small values for the result. For example if x = 1e-6 and a = 1e8 then the result is 10(-8) * 10^(-6*10^8). And if 'a' is 10^7 and x is larger than that, the result is (10^7)! which is approximately 10^(6.57*10^7). These numbers are so large (or small) that it is hard to see what their purpose might be. Could you explain the context for these values?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gamma Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!