Limits of using vpa

조회 수: 9 (최근 30일)
John Fullerton
John Fullerton 2020년 6월 23일
편집: Pratheek Punchathody 2020년 11월 24일
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일
편집: 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