MathGroup Archive 2009

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

Search the Archive

Re: A simple error

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102177] Re: A simple error
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 31 Jul 2009 05:57:51 -0400 (EDT)

On 7/30/09 at 5:34 AM, y.eaidgah at gmail.com (Youness Eaidgah) wrote:

>Dear all, I have faced a awkward situation in Mathematica. I want to
>sum the following simple equations:

>DTEP12 = 0.11 (80000 - 12000 P + 800000 (1 - R)) +   0.11 (40000 -
>12000 P + 1000000 (1 - R)) + 0.28 (-12000 P + 1200000 (1 - R))
>MTEP12 = 0.11 (-130000 + 12000 (-35 + P) + 800000 R) + 0.11 (-130000
>+ 12000 (-35 + P) + 1000000 R) + 0.28 (-130000 + 12000 (-35 + P) +
>1200000 R)

>Obviously, the result of the DTEP12+MTEP12 is : 272200

>However, when I use the following commands

>Simplify[DTEP12+ MTEP12]   or FullSimplify[DTEP12+MTEP12]

>Mathematica returns: 272200.+ 0. P + 5.82077*10^-11 R. I am suprised
>where the last term comes form (5.82077*10^-11 R)! It is a really
>really small value, however, it is still an error. it creates some
>inconveniences later in my calculations. I would appreciate if you
>could help me out.

The small term arises from using machine precision numbers.
Values like 0.11 and 0.28 cannot be expressed in a finite number
of binary digits. As a consequence, the coefficients simplify to
values that differ from what you are expecting.

This issue comes up repeatedly here and is not a Mathematica
issue. It is inherent in floating point arithmetic used in any
modern computer.

You have two choices for dealing with this issue.

1) use exact expressions, e.g.,

In[14]:= DTEP12 =
   11/100 (80000 - 12000 P + 800000 (1 - R)) +
    11/100 (40000 - 12000 P + 1000000 (1 - R)) +
    28/100 (-12000 P + 1200000 (1 - R));
MTEP12 = 11/100 (-130000 + 12000 (-35 + P) + 800000 R) +
    11/100 (-130000 + 12000 (-35 + P) + 1000000 R) +
    28/100 (-130000 + 12000 (-35 + P) + 1200000 R);

In[16]:= Simplify[DTEP12 + MTEP12]

Out[16]= 272200

2) use Chop, e.g.,

In[17]:= DTEP12 =
   0.11 (80000 - 12000 P + 800000 (1 - R)) +
    0.11 (40000 - 12000 P + 1000000 (1 - R)) +
    0.28 (-12000 P + 1200000 (1 - R));
MTEP12 = 0.11 (-130000 + 12000 (-35 + P) + 800000 R) +
    0.11 (-130000 + 12000 (-35 + P) + 1000000 R) +
    0.28 (-130000 + 12000 (-35 + P) + 1200000 R);

In[19]:= Chop[Simplify[DTEP12 + MTEP12]]

Out[19]= 272200.




  • Prev by Date: Re: Fast way to Rotate a bitmap in Mathematica 6.0
  • Next by Date: Re: The audience for Mathematica (Was: Re: Show doesn't work inside
  • Previous by thread: Re: A simple error
  • Next by thread: Trouble controlling Rasterize -- it introduces unwanted borders