Limits of using vpa

2 次查看(过去 30 天)
John Fullerton
John Fullerton 2020-6-23
Hi,
I need to evaluate the gamma function in MATLAB for some very large values, and have so far been using 'vpa' to do this.
However, this now seems to be hitting a limit around gamma(1e8), as shown below.
Is it posible to extend this somehow to calculate gamma(1e8)?
Thank you!
gamma(vpa(1e7))
ans =
1.2024234005159034561401534879443e+65657052
>> gamma(vpa(1e8))
ans =
Inf
  1 个评论
David Goodmanson
David Goodmanson 2020-6-23
Hi John,
at some point it make a lot more sense to use the logarithm.
vpa(gammaln(1e100),100)
ans = 2.292585092994046058293551528706245869611598545401159566538932922285195947207408619737372157648583e+102

请先登录,再进行评论。

回答(1 个)

Pratheek Punchathody
编辑:Pratheek Punchathody 2020-11-24
Hi John
Logarithm of gamma function command avoids the underflow and overflow that may occur.
By using the command
y=gammaln(1e8);
Output obtained is y= 1.7421e+09
If the number of digits that has to be displayed is known (say 25) then
By using the command
z= vpa(gammaln(1e8),25);
Output obtained is z = 1742068066.103834867477417
Refer to the documentation on vpa(x,d) for more information. Here d must be greater than 1 and lesser than 2^29+1.

类别

Help CenterFile Exchange 中查找有关 Gamma Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by