Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

RE: MemberQ

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68528] RE: [mg68503] MemberQ
  • From: "Erickson Paul-CPTP18" <Paul.Erickson at Motorola.com>
  • Date: Wed, 9 Aug 2006 04:18:38 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Bruce,

In[2]:=
Range[0., 1., .1][[8]] - .7
Out[2]=
1.1102230246251565x10^-16

Looks like ye old precision problem of accumulated error. That is 7
increments of 0.1 as a real machine precision number is not equal to
0.7.

One of probably many ways around this would be to wrap Range with a
rounding function like Rationalize and then convert each element
separately back to machine precision:
In[9]:=
MemberQ[ N[ Rationalize[ Range[0., 1., .1] ] ], .7]
Out[9]=
True

Another is of course to normalize to integers so as to avoid the problem
in the first place.

Paul

-----Original Message-----
From: Bruce Colletti [mailto:vze269bv at verizon.net] 
To: mathgroup at smc.vnet.net
Subject: [mg68528] [mg68503] MemberQ

Re Mathematica 5.2.0.0.

Since 0.7 is in the set {0.0, 0.1, 0.2,..., 0.9, 1.0}, why does
MemberQ[Range[0., 1., .1], .7] return False?
 
Thankx.

Bruce


  • Prev by Date: Re: NDSolve with boundary condition(s) at infinity?
  • Next by Date: RE: MemberQ
  • Previous by thread: Re: MemberQ
  • Next by thread: RE: MemberQ