MATLAB: For loop and while loop largest integer

doit4mehomeworkno attempt

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.

Best Answer

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.