http://www.mathworks.com/matlabcentral/newsreader/view_thread/283349
MATLAB Central Newsreader  problems with log being infinity when it should not be
Feed for thread: problems with log being infinity when it should not be
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 28 May 2010 21:33:22 +0000
problems with log being infinity when it should not be
http://www.mathworks.com/matlabcentral/newsreader/view_thread/283349#749887
Irene
Hello,<br>
I am not sure how to correct this problem in Matlab.<br>
<br>
When I calculate:<br>
log(factorial(100)/(10000^100))<br>
I get <br>
Inf<br>
<br>
However, when I calculate:<br>
<br>
factorial(100) = 9.33*10^157<br>
log(9.33*10^157/10^400)<br>
I get<br>
557.2949<br>
<br>
Mathematica also obtains the latter answer.<br>
How should I tell matlab that I want the last answer and not Inf?<br>
<br>
Thank you!

Fri, 28 May 2010 21:53:25 +0000
Re: problems with log being infinity when it should not be
http://www.mathworks.com/matlabcentral/newsreader/view_thread/283349#749902
Walter Roberson
Irene wrote:<br>
<br>
> I am not sure how to correct this problem in Matlab.<br>
> <br>
> When I calculate:<br>
> log(factorial(100)/(10000^100))<br>
> I get Inf<br>
> <br>
> However, when I calculate:<br>
> <br>
> factorial(100) = 9.33*10^157<br>
> log(9.33*10^157/10^400)<br>
> I get<br>
> 557.2949<br>
> <br>
> Mathematica also obtains the latter answer.<br>
> How should I tell matlab that I want the last answer and not Inf?<br>
<br>
You cannot. 10^400 is not representable in Matlab. The parser must be doing <br>
something special to be able to use it in a constant expression.<br>
<br>
In 2008b, the constant expression returns Inf as well.<br>
<br>
If you have the symbolic toolbox, you could evaluate the expression in that, <br>
as that has a much higher range, in the thousands of digits.

Fri, 28 May 2010 22:01:24 +0000
Re: problems with log being infinity when it should not be
http://www.mathworks.com/matlabcentral/newsreader/view_thread/283349#749904
James Tursa
"Irene " <jez_zaz_bel@yahoo.com> wrote in message <htpcr2$4av$1@fred.mathworks.com>...<br>
> Hello,<br>
> I am not sure how to correct this problem in Matlab.<br>
> <br>
> When I calculate:<br>
> log(factorial(100)/(10000^100))<br>
> I get <br>
> Inf<br>
> <br>
> However, when I calculate:<br>
> <br>
> factorial(100) = 9.33*10^157<br>
> log(9.33*10^157/10^400)<br>
> I get<br>
> 557.2949<br>
> <br>
> Mathematica also obtains the latter answer.<br>
> How should I tell matlab that I want the last answer and not Inf?<br>
> <br>
> Thank you!<br>
<br>
Pay attention to your intermediate calculations. e.g.,<br>
<br>
>> 10000^100<br>
ans =<br>
Inf<br>
>> 10^400<br>
ans =<br>
Inf<br>
<br>
You will either need to use the symbolic toolbox, or work with sums of logs instead of the values directly, or do some of the exponent calculations by hand before you give it to MATLAB, or something else to avoid the limitations of IEEE Double Precision format.<br>
<br>
James Tursa

Fri, 28 May 2010 23:15:22 +0000
Re: problems with log being infinity when it should not be
http://www.mathworks.com/matlabcentral/newsreader/view_thread/283349#749920
Roger Stafford
"Irene " <jez_zaz_bel@yahoo.com> wrote in message <htpcr2$4av$1@fred.mathworks.com>...<br>
> Hello,<br>
> I am not sure how to correct this problem in Matlab.<br>
> <br>
> When I calculate:<br>
> log(factorial(100)/(10000^100))<br>
> I get <br>
> Inf<br>
> <br>
> However, when I calculate:<br>
> <br>
> factorial(100) = 9.33*10^157<br>
> log(9.33*10^157/10^400)<br>
> I get<br>
> 557.2949<br>
> <br>
> Mathematica also obtains the latter answer.<br>
> How should I tell matlab that I want the last answer and not Inf?<br>
> <br>
> Thank you!<br>
<br>
It is not reasonable to use matlab's double precision floating point numbers to do such a calculation as that in the form you have used. These numbers cannot go beyond about 1.8e+308 before becoming "infinity". You may be sure Mathematica does not use them for this computation as it stands. As both Walter and James have said, use matlab's symbolic toolbox for a fair comparison with Mathematica's results for anything using such large numbers.<br>
<br>
James has given you an alternative of using sums of logarithms and converting exponents to products. Write it like this:<br>
<br>
sum(log(1:100))100*log(10000)<br>
<br>
Roger Stafford

Sat, 29 May 2010 15:54:05 +0000
Re: problems with log being infinity when it should not be
http://www.mathworks.com/matlabcentral/newsreader/view_thread/283349#750004
Irene
"Irene " <jez_zaz_bel@yahoo.com> wrote in message <htpcr2$4av$1@fred.mathworks.com>...<br>
> Hello,<br>
> I am not sure how to correct this problem in Matlab.<br>
> <br>
> When I calculate:<br>
> log(factorial(100)/(10000^100))<br>
> I get <br>
> Inf<br>
> <br>
> However, when I calculate:<br>
> <br>
> factorial(100) = 9.33*10^157<br>
> log(9.33*10^157/10^400)<br>
> I get<br>
> 557.2949<br>
> <br>
> Mathematica also obtains the latter answer.<br>
> How should I tell matlab that I want the last answer and not Inf?<br>
> <br>
> Thank you!<br>
<br>
I see. Thank you!