help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use GNU MP in octave?


From: Shai Ayal
Subject: Re: How to use GNU MP in octave?
Date: Tue, 24 May 2005 12:59:20 +0300
User-agent: Mozilla Thunderbird 1.0 (X11/20041206)



Javier Arantegui wrote:
Hello,

El Martes, 24 de Mayo de 2005 05:28, Keith Goodman escribió:

Here's a quote from google

[...]

Let x = lg(8600!). Since lg(xy)=lg(x)+lg(y) you have

x = sum(lg(k),k=1..86000)

Define floor(x) as the integer part of x. Then

86000! = 10^(x-floor(x))*10^floor(x).

You can evaluate x to the degree of accuracy you want, for example,
using Maple I got:

86000! = 7.91222558*10^372239


Unfortunately, Octave doesn't buy the trick :-(:-(

octave:4> k=1:1:86000;
octave:5> x=sum(log10(k))
x =  3.8702e+05
octave:6> 10^(x-floor(x))*10^floor(x)
ans = Inf


Octave doesn't buy this trick since the maximum double value is ~ 10^300. I think Keith meant to say:

use octave to calc 10^(x-floor(x)) which is hard to do by hand, and multiply by 10^floor(x) in your head which is easy, (at least to me ...)


octave:8>  k=1:1:86000;
octave:9>  x=sum(log10(k));
octave:10> format long
octave:11> x
x = 387020.407702849
octave:12> floor(x)
ans = 387020
octave:13> 10^(x-floor(x))
ans = 2.55683586378090

so your answer is approximately 2.55683586378090*10^387020, (or 2.55683586378090e+387020 in octaves output format). 16 decimal digits is the limit of double precision floting point used in octave. If you need more precision, than other programing tools, as suggested in previous emails in this thread are appropriate.

Note that this result is different from the maple result given above, probably due to roundoff errors in the sum. I suppose this could be improved with some more perusing, although the double precision output of maple leads me to suspect that tin his case a a similar algorithm, or some approximation was used, not real arbitrary precision arithmetic.



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]