Limits of using vpa

3 ビュー (過去 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 Center および File ExchangeGamma Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by