RE: MemberQ
- To: mathgroup at smc.vnet.net
- Subject: [mg68554] RE: [mg68503] MemberQ
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 9 Aug 2006 04:20:27 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Bruce, Because... set1 = Range[0.0, 1.0, 0.1] % // InputForm {0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.} {0., 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001, 0.7000000000000001, 0.8, 0.9, 1.} Try.. set2 = Table[x/10, {x, 0, 10}] // N % // InputForm {0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.} {0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.} MemberQ[set2, 0.7] True But in general you're going to get poor results testing set inclusion with approximate numbers. You could use something like Count[set1, x_ /; 0.699 < x < 0.701] > 0 True David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Bruce Colletti [mailto:vze269bv at verizon.net] To: mathgroup at smc.vnet.net 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