for loop and while loop largest integer

4 ビュー (過去 30 日間)
Coupe Honda
Coupe Honda 2017 年 2 月 12 日
編集済み: Jan 2017 年 2 月 13 日
a) Write a code using a for or a while loop to determine the largest integer n for which e^n <infinite in MATLAB. Also, determine the largest integer for which e^-n > 0. Print out these two values of n.
b) Write a code using a for or a while loop to determine the largest integer n for which n!! < infinite in MATLAB. Print out this value of n.
  2 件のコメント
Jan
Jan 2017 年 2 月 12 日
@Coupe Honda: What kind of help do you want? We cannot and should not solve your homework, because then you could not deliver it without cheating. Therefore it is better you post, what you have tried so far and ask a specific question.

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

採用された回答

Walter Roberson
Walter Roberson 2017 年 2 月 12 日
a) ln(1) is 0, so the answer for e^n < 1 is going to have to be the largest integer less than 0. Exactly where are you going to start counting for the loop? If you start from intmin('int64') then you would be calculating a rather long time...
For e^-n, again where do you start counting? intmax('int64') just is not practical.
b) n!! is factorial(factorial(n)) . factorial(n) >= 1 for all non-negative n, and factorial(n) for non-negative values is never less than n, so factorial(factorial(n)) must be >= 1 for all non-negative n. factorial() does not accept negative integers.
If you rewrite the expression from factorial to gamma, gamma(1+gamma(1+n)) then you have the problem that gamma is infinity at all negative integers. Therefore there are no negative integers for which gamma(1+gamma(1+n)) < 1. We have eliminated the non-negative integers and we have eliminated the negative integers, so this proves there is no solution to n!! < 1 for integer n.
  4 件のコメント
Coupe Honda
Coupe Honda 2017 年 2 月 13 日
I got this problem.I just don't know what is the infinite number in matlab. It's actually the Inf. Thanks anyway.
Walter Roberson
Walter Roberson 2017 年 2 月 13 日
inf and -inf . You can use isinf() to test for the infinities.

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

その他の回答 (1 件)

Jan
Jan 2017 年 2 月 12 日
I'd prefer a while loop. Start at e.g. k=0 and check if exp(k) is finite as condition of the loop. If you do not know how to check this, search the documentation for the term "finite":
docsearch finite
or ask an internet search engine for "Matlab is finite". You will find the command isfinite...
If the test is successful, increase k by 1.
The code for testing exp(-n) > 0 and n!! < Inf will be very similar.
  2 件のコメント
Coupe Honda
Coupe Honda 2017 年 2 月 13 日
Thank you.
Jan
Jan 2017 年 2 月 13 日
編集済み: Jan 2017 年 2 月 13 日
Whooops? I'm not familiar with the forum's interface, at least not with the detail that 2 answers can be accepted.

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

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by