Large integer rounding problem

2 ビュー (過去 30 日間)
HAORAN SUN
HAORAN SUN 2020 年 7 月 13 日
コメント済み: HAORAN SUN 2020 年 7 月 14 日
I have a question about an equation when I put it in Matlbab.
We know (1+x/n)^n = e^x as n goes infinity. However, the LHS gives me 1 when I use a small value of x and a large integer value of n(1e15, for example). Is there a better way I can compute this so that the final value is closer to e^x? Thank you so much!

採用された回答

David Goodmanson
David Goodmanson 2020 年 7 月 14 日
編集済み: David Goodmanson 2020 年 7 月 14 日
Hello HS,
you ran into the limits of double precision numbers. However,
(1+x/n)^n = e^x*f % f = correction factor that is nearly 1 for large n
f = e^(-x)*(1+x/n)^n
% in terms if the log,
log(f) = log(e^(-x)) + log((1+x/n)^n)
= -x + n*log(1+x/n)
% taylor series for log about x = 1
= -x + n*( x/n -(x/n)^2/2 +(x/n)^3/3 -(x/n)^4/4 ...)
= -x^2/(2*n) +x^3/(3*n^2) -x^4/(4*n^3) ...
For large n, the log of the correction factor is -x^2/(2*n) to lowest order. That's the basic result.
You can exponentiate this to get f itself, but again for large n you will run into the limits of double precision. Using the taylor series for exp, you have
f ~~ exp(-x^2/(2*n)) ~~ 1 -x^2/(2*n)
showing the correction factor itself to first order. From this you can estimate how large n has to be until the second term goes to about 1e-15 and is no longer describable in double precision.
You can expand out to many more decimal places with vpa, but storing 1000 decimal places is not nearly as important as knowing the basic behavior for large n.
  1 件のコメント
HAORAN SUN
HAORAN SUN 2020 年 7 月 14 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumbers and Precision についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by