Limits of using vpa

9 views (last 30 days)
John Fullerton
John Fullerton on 23 Jun 2020
Edited: Pratheek Punchathody on 24 Nov 2020
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 Comment
David Goodmanson
David Goodmanson on 23 Jun 2020
Hi John,
at some point it make a lot more sense to use the logarithm.
vpa(gammaln(1e100),100)
ans = 2.292585092994046058293551528706245869611598545401159566538932922285195947207408619737372157648583e+102

Sign in to comment.

Answers (1)

Pratheek Punchathody
Pratheek Punchathody on 24 Nov 2020
Edited: Pratheek Punchathody on 24 Nov 2020
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.

Community Treasure Hunt

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

Start Hunting!