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: [mg68526] Re: MemberQ
  • From: Peter Pein <petsie at dordos.net>
  • Date: Wed, 9 Aug 2006 04:18:31 -0400 (EDT)
  • References: <eb9pkt$t4j$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Bruce Colletti schrieb:
> 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
> 

It returns False, because 0.7 is definitely _not_ a member of
In[1]:= Range[0.,1.,.1]//InputForm

Out[1]//InputForm=
  {0., 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6000000000000001,
  0.7000000000000001, 0.8, 0.9, 1.}

Don't expect exact results, when using inexact numbers.

MemberQ[lst,elm] looks for exactly the same as elm in lst. You can write 
your own MemberQ using == instead of ===, because Equal[] considers 
"very similar" reals to be equal:

In[2]:= sloppyMemberQ = Cases[#1, x_ /; x == #2, 1, 1] =!= {} & ;
In[3]:= sloppyMemberQ[Range[0., 1., 0.1], 0.7]
Out[3]= True

Peter


  • Prev by Date: Re: for higher dimensions?
  • Next by Date: Re: How to get the output of Minimize function in x = a format
  • Previous by thread: Re: MemberQ
  • Next by thread: RE: MemberQ