Using double precision, find x for which exp(x) doesn't overflow.

6 ビュー (過去 30 日間)
Shiksha Pandey
Shiksha Pandey 2021 年 3 月 24 日
コメント済み: Rik 2021 年 3 月 24 日
Using double precision, find x for which exp(x) doesn't overflow.
  4 件のコメント
Shiksha Pandey
Shiksha Pandey 2021 年 3 月 24 日
編集済み: Rik 2021 年 3 月 24 日
This is what I have. I'm not sure if this is the best way to go though.
expn=0;
x=1:1000;
while expn < realmax
expn=(exp(x));
maxexpn = double(expn);
xx = double(log(maxexpn));
mexp = max(maxexpn(~isinf(maxexpn)));
mx = max(xx(~isinf(xx)))
abserr = abs(mexp-realmax)
relerr = (abs(mexp-realmax))/realmax
end
Is there a shorter way to go about it?
Rik
Rik 2021 年 3 月 24 日
I don't really understand what you're attempting to do with the while loop, but yes, there is a faster way. It requires you to think a bit more.
log2(realmax)
ans = 1024
OK, so we are looking for x where e^x is at most 2^1024.
With a little bit of algebra that should not be too hard to solve. Can you see how?

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

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 3 月 24 日
編集済み: KALYAN ACHARJYA 2021 年 3 月 24 日
All data creates in MATLAB are douple precision (Standard /By Default)
More:
e^x = 1 + (x ^ 1 / 1!) + (x ^ 2 / 2!) ......

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by