MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: how to avoid numeric error

  • To: mathgroup at
  • Subject: [mg20364] Re: [mg20309] how to avoid numeric error
  • From: BobHanlon at
  • Date: Sun, 17 Oct 1999 02:45:39 -0400
  • Sender: owner-wri-mathgroup at



8.551437202665365431742222523666`12.6535*^864 - 

Despite its large magnitude, the magnitude of the imaginary part is small 
compared to the magnitude of the real part (differ by 12 orders of magnitude).

10^864*Chop[(-5.2)^1208./10^864] == (-5.2)^1208


Extending the concept of Chop

relativeChop[x_ , delta_:10^-10] /; (Abs[x] == 0) = 0;
relativeChop[x_, delta_:10^-10] := 
  Module[{mag = Abs[x]}, mag*Chop[x/mag, delta]]

relativeChop[(-5.2)^1208.] == (-5.2)^1208


Bob Hanlon

In a message dated 10/16/1999 12:38:51 AM, atulksharma at writes:

>I am at a loss to explain this behavior, though I perhaps
>misunderstand how Mathematica implements it's machine precision routines.
>This is a simple example of a problem that cropped up during evaluation
>constants of integration
>in a WKB approximation, where I would get quite different results depending
>on how the constant was evaluated. I have localized the discrepancy to
>term of the form shown below:
>testParameters =
>  {x1 -> 5.2, x2 -> 0.3, x3 -> 0.002, x4 -> -0.00025}
>(-x1)^(-(x2 + x3)/x4) /. testParameters
>In this case, as it turns out, x1 = -5.2, which is a floating point number,
>and the exponent = 1208 (which may be integer or floating point, but is
>floating point in this case).
>I assumed that the result would be evaluated to machine precision in either
>since x1 is a float regardless. However, depending on whether the exponent
>is integer or not, I get two different results, with a large imaginary
>8.55143720266536543174145`12.6535*^864 -
>  2.48026735232231456274073`12.6535*^852*I
>I assume that this has some simple relationship to machine precision and
>round-off error, but am I wrong in assuming that x1 should determine the
>numeric precision of the entire operation?
>I am using Mathematica 3.01.1 on a PC/Win95 platform.
>I also encountered another problem, which bothers me because it's so
>insidious. In moving a notebook from one machine to another by floppy (work
>to home), a parsing error occurred buried deep inside about 30 pages of
>code. A decimal number of the form 1.52356 was parsed as 1.5235 6 with
>space inserted and interpreted as multiplication. The same error occured
>the same place on several occasions (i.e. when I start getting bizarre
>results, I know to go and correct this error).
>I know these sound minor, but they have a large effect on the solution
>could easily go undetected. Thanks in advance.

  • Prev by Date: Re: Why doesn't this work?
  • Next by Date: Re: bug in Legendre polinomials
  • Previous by thread: how to avoid numeric error
  • Next by thread: Re: how to avoid numeric error