MathGroup Archive 2009

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

Search the Archive

Re: A simple error

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102184] Re: A simple error
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Fri, 31 Jul 2009 05:59:22 -0400 (EDT)
  • References: <h4rpen$l85$1@smc.vnet.net>

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.
> Thank you,
> Youness
> 
> 
The moral of this, is never manipulate algebraic expressions containing 
real numbers. A number like 0.11 cannot be stored exactly as a machine 
precision number, because such numbers are held in binary format. If you 
enter 0.11 as 11/100 and 0.28 as 28/100 you get exact expressions, which 
yield the exact result that you expected.

This problem is intrinsic to computer arithmetic - a fractional quantity 
that can be represented exactly in one base (e.g. 10) can't always be 
represented exactly to another base (e.g. 2).

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: A simple error
  • Next by Date: Re: A simple error
  • Previous by thread: Re: A simple error
  • Next by thread: Re: A simple error