       Re: Re: Re: Accuracy and Precision

• To: mathgroup at smc.vnet.net
• Subject: [mg37097] Re: [mg37076] Re: [mg37058] Re: Accuracy and Precision
• From: David Withoff <withoff at wolfram.com>
• Date: Wed, 9 Oct 2002 05:25:52 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```> > > > In:=
> > > > f = SetAccuracy[333.75*b^6 + a^2*(11*a^2*b^2 - b^6 -
> > > >          121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100];
> > > > a=SetPrecision[77617.,100];  b = SetPrecision[33096.,100];
> > > >
> > > > In:=
> > > > {f, Precision[f]}
> > > >
> > > Out=
> > >  {-0.82739605994682136814116509547981629199903311578438481991\
> > > 781484167246798617832`61.2597, 61}
> > >
> > > Congratulations! You just requested accuracy of
> > 100 for f and got 61 (
> > > to convince yourself add Accuracy[f] to In).

There is no request in that example for an accuracy of 100 in the
result.  The only request is for an accuracy of 100 in the input.

> > In:= f = SetAccuracy[333.75*b^6 +
> > a^2*(11*a^2*b^2 - b^6 -
> > 	121*b^4 - 2) + 5.5*b^8 + a/(2*b), 100];
> >
> > In:= Accuracy[f]
> > Out= 100.
> >
> > Now we assign values to some indeterminants in f.
> >
> > In:= a = SetPrecision[77617.,100]; b = SetPrecision[33096.,100];
> >
> > In:= {f, Precision[f], Accuracy[f]}
> > Out=
> > {-0.8273960599468213681411650954798162919990331157843848199178148,
> > 	61.2599, 61.3422}
> >
> > The precision and accuracy has dropped. This is all
> > according to
> > standard numerical analysis regarding cancellation
> > error. You'll find it in any textbook on the topic.
> >
>
> Assume that I want accuracy and precision of 100 for
> f. You advice me to make experiments to find out, what
> should be the initial precision and accuracy of a and
> b to reach the requested accuracy and precision for f.
> Notice, that you cannot just repeat I, we saw
> already what happens. I have to re-type I, I,
> I, I, I, and I as many times as needed
> to get f with accuracy and precision 100.
>
> Dan, you simply advocate to do MANUAL WORK that should
> be done by machine.

You do not have to do any of this manually.  The machine (Mathematica)
will do all of this, usually using built-in functions.  The N function,
for example, will automatically adjust the working precision to give
you a precision that you request, provided that doing so doesn't involve
making up arbitrary digits.

The example above starts out with machine numbers (333.75, 5.5, etc.),
uses SetPrecision and SetAccuracy to make up arbitrary digits to pad
those numbers out to some specified number of digits, and then does
some simple arithmetic.  If the goal is to get some specified number
of digits in the result, and it is ok to make up arbitrary digits like
this to achieve that goal, then the only manual work required to achive
that goal is to apply SetAccuracy or SetPrecision to the result, to
tell the computer that that is what you want.

> Let's suppose that in the above example I just want 60
> digits not 61. Precisely, I want 60 digits and nothing
> or zeros afterwards. Let's see if I could use
> SetAccuracy.
>
> In:= SetAccuracy[%, 60]
>
> Out= -0.82739605994682136814116509547981629199903311578438481991781
>
> In:= % // FullForm
>
> Out//FullForm=
> -0.827396059946821368141165095479816291999033115784384819917814841672467988`\
> 59.9177
>
> Oops, it did not work (as expected).

If you could explain what you were expecting I am sure there are many
contributors to this group who could explain to you why it did not do that.

> Let's highlight
> with mouse the expression in Out and copy to a new
> cell. Oops, we got
> -0.827396059946821368141165095479816291999033115784384819917814841672467988`\
> 59.9177 again. Let's change Out to a text cell and then copy.
>
> In:= -0.82739605994682136814116509547981629199903311578438481991781
>
> Out= -0.82739605994682136814116509547981629199903311578438481991781
>
> Success? Not so fast.

If you could describe what you were trying to achieve with all of that
copying and pasting and such I am again sure that there are many
contributors to this group who could describe how to do it.   It
is very unlikely that the process will involve any copying and pasting
or detours through text cells.

> In:=
> % // FullForm
>
> Out//FullForm=
> -0.827396059946821368141165095479816291999033115784384819917809999999999998635\
> 08`59.2041
>
> Dan, is there any simple way to get what I want?

Probably the answer is yes, but you will have to describe more
clearly what you want.

> As I repeated already number of times, at this stage
> of the development of computer technology, software
> should do it for me (!).

If what you want to do is get a certain number of digits in
the result, and it is ok to make up arbitrary digits as in the
examples above, then you can do that by simply applying SetPrecision
or SetAccuracy to the result.  If you want the computer to
automatically adjust the working precision to give a certain
precision in the result, you can do that using N.  If you want
something else, and you can describe what that is, then probably
someone can describe how to get Mathematica to do that for you.

Dave Withoff
Wolfram Research

```

• Prev by Date: Re: Operating on every k-th element of list?
• Next by Date: RE: Re: Re: Accuracy and Precision
• Previous by thread: Re: Re: Accuracy and Precision
• Next by thread: RE: Re: Re: Accuracy and Precision