Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!a21g2000prj.googlegroups.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: where is the mistake
Date: Sun, 27 Feb 2011 14:40:54 -0800 (PST)
Organization: http://groups.google.com
Lines: 98
Message-ID: <78fe1b42-dd6d-46ae-af69-015453241122@a21g2000prj.googlegroups.com>
References: <ikbqin$4gr$1@fred.mathworks.com> <ikdnp4$4i$1@fred.mathworks.com>
 <ikdrci$jch$1@fred.mathworks.com> <ikdt79$bdd$1@speranza.aioe.org> <ikedib$582$1@fred.mathworks.com>
NNTP-Posting-Host: 24.7.153.92
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1298846455 17281 127.0.0.1 (27 Feb 2011 22:40:55 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 27 Feb 2011 22:40:55 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: a21g2000prj.googlegroups.com; posting-host=24.7.153.92; posting-account=YqIC9AoAAADap7NvyM7RBldP6UMj5cTQ
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13)
 Gecko/20101203 Firefox/3.6.8 NET_mmhpset,gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:712756

On Feb 27, 12:52 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Nasser M. Abbasi" <n...@12000.org> wrote in message <ikdt79$bd...@speranza.aioe.org>...> On 2/27/2011 7:42 AM, John D'Errico wrote:
> > > .......
> > > I could not resist trying out my new toolbox in MATLAB.
>
> > > FPF is a class that allows you to work in floating point
> > > arithmetic with a user specified precision. So here, with
> > > 50 digits of precision in all computations...
> > >.......
> > ......
> > Fyi, here is the result from Mathematica using 50 digits
> > precision, it matches your results. Note, while comparing,
> > Mathematica has 50 digits after the decimal point, the above
> > output has 49 digits after the decimal.
> > ......
>


> - - - - - - - - - -
>   I used the direct formula p(n) = (-1)^n * (!n * exp(1) - n!) with the symbolic toolbox set at a precision of 100 to compute p(17:20) accurately for comparison purposes and noticed a curious phenomenon.  By n = 20 John's value has lost about 20 decimal places of accuracy from the original 50, which one would more or less expect from the intrinsic nature of the iteration.  However Nassar's answers apparently remain accurate to the full 50 digits which is very surprising since he is using the same iteration.  How did you manage that using only 50 digits precision, Nassar?  Possibly you are getting more precision than you realize with Mathematica.
>
>   Here are our respective results for n = 20:
>
> John   0.1238038307625699486913961699581691307326964474879
> Nassar 0.12380383076256994869139616995822245119978530814180
> Roger   .123803830762569948691396169958222451199785308141796375457917
>
>   The significance of this as far as John's results are concerned is that if we were to continue the same iteration up to, say, n = 100, doing everything with only 50 decimal digit precision, the results would surely have deteriorated catastrophically.  Nassar's results remain a puzzle to me but presumably for a sufficiently large n his results would also begin to show a rapid decline in accuracy using this algorithm.
>
> Roger Stafford

Hello Roger,

I am no expert on this, but Mathematica by default uses variable
precision for floating points, which
keeps tracks of precision at each step as described in this page. This
might be different from what you might have been thinking of.

http://reference.wolfram.com/mathematica/tutorial/ArbitraryPrecisionNumbers.html

This behaviour can be changed if needed.

But one can see the result of fixing the maximum precision to say 55
is that at one point, Mathematica now complained after 6 iterations:

----------------------------------
$MaxPrecision=55;
y=1;
For[i=2,i<=20,i++,
{y=Exp[1]-i*y;
Print[N[y,50]]}
]

0.71828182845904523536028747135266249775724709369996
0.56343634308190952927942505729467500448550581260008
0.46453645613140711824258724217396247981522384329964
0.39559954780200964414735126048285009868112787720178
0.34468454164698737047617990845556190567047983048929
0.30549003693013364202702811216372915806388828027495

$MaxPrecision::prec: In increasing internal precision while attempting
to evaluate
...
the limit $MaxPrecision .... was reached.
Increasing the value of $MaxPrecision may help resolve the
uncertainty. >>

0.2743615330179760991440625740428292332461408515004


$MaxPrecision::prec: .....

0.249028031297260343063724304967199398541979430197

etc...

When using Mathematica, and if I want to work with just
machinePrecision computation, I add this line to the top of my script:

$MinPrecision = $MachinePrecision; $MaxPrecision = $MachinePrecision;

--Nasser