       Re: Problems with numerical precision

• To: mathgroup at smc.vnet.net
• Subject: [mg13267] Re: Problems with numerical precision
• From: Robert Knapp <rknapp>
• Date: Fri, 17 Jul 1998 03:17:58 -0400
• Organization: Wolfram Research, Inc.
• References: <6od359\$hpn@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Joel Cannon wrote:
>
> I was surprised by the following behavior. I have a large, compicated 39
> term exact expression which I will paste at the bottom of this message
> (actually it is one element of a matrix that needs to be evaluated).
> The terms vary in magnitude from approx. 10^(21) to 10^(7). The sum of
> the terms is ~.1 so (in retrospect) the answer would be unreliable
> until precision was at least greater than 22 digits. What surprised me
> was that when I innocently used standard precision when converting to a
> number, mathematica gave an erroneous answer but indicated that this
> answer had normal precision. As soon as I used a precision sufficient
> to obtain a reliable number, mathematica returned a reasonable value
> for precision.
>
> (* I innocently evaluate the expression with 16 bit precision and
> allegedly get a 16 digit answer *)
>
> In:=
> N[exact]
>
> Out=
> -387994.
>
> In:=
> Precision[%]
>
> Out=
> 16
>
> ......

The precision shown for this result is \$MachinePrecision, and is a
consequence of "Whenever machine-precision numbers appear in a
calculation, the whole calculation is typically done in machine
precision.  Mathematica will then give machine-precision numbers as the
result." (The Mathematica Book, Third Edition, p711)

Basically Mathematica gives you a choice.  You can use machine-precision
cacluations (N with one argument), which are fast, but have NO
VERIFICATION of precision built in, or you can use arbitrary precision
numbers (N with a second precision argument) which are slower, but
verify the precision with significance arithmetic at each step.

To get this completely clear, I strongly recommend a thorough reading of
Section 3.1 in The Mathematica Book.

Rob Knapp
Numerics
Wolfram Research

```

• Prev by Date: Re: Editable Images of the Globe?
• Next by Date: Re: 3DGraphics color problem
• Previous by thread: Re: Problems with numerical precision
• Next by thread: Win95 to Win98 issues