MathGroup Archive 1999

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

Search the Archive

Re: how to avoid numeric error

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

Atul,

(-5.2)^1208.

8.551437202665365431742222523666`12.6535*^864 - 
  2.4803091328936406321397756468`12.6535*^852*I

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

True

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

True

Bob Hanlon

In a message dated 10/16/1999 12:38:51 AM, atulksharma at yahoo.com 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
>of
>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
>one
>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
>case,
>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
>component
>
>In[27]:=
>(-5.2)^1208.
>
>Out[27]=
>8.55143720266536543174145`12.6535*^864 -
>  2.48026735232231456274073`12.6535*^852*I
>
>In[28]:=(-5.2)^1208
>
>Out[28]=
>8.55143720266675767908621`12.8725*^864
>
>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
>a
>space inserted and interpreted as multiplication. The same error occured
>in
>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
>and
>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