Position and Real Numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg18811] Position and Real Numbers
- From: Jason Gill <jgill at vbimail.champlain.edu>
- Date: Thu, 22 Jul 1999 08:19:28 -0400
- Organization: IBM Microelectronics
- Sender: owner-wri-mathgroup at wolfram.com
Folks, I had a member of my department ask me this question, and I thought I'd share it with the group. In short he was using Position to return to the location of a number in a list, and it wouldn't work in many cases. The example was In[251]:= x=Range[-3,2,.05] Out[251]= {-3,-2.95,-2.9,-2.85,-2.8,-2.75,-2.7,-2.65,-2.6,-2.55,-2.5,-2.45,-2.4,-2.35,-\ 2.3,-2.25,-2.2,-2.15,-2.1,-2.05,-2.,-1.95,-1.9,-1.85,-1.8,-1.75,-1.7,-1.65,-1.\ 6,-1.55,-1.5,-1.45,-1.4,-1.35,-1.3,-1.25,-1.2,-1.15,-1.1,-1.05,-1.,-0.95,-0.9,\ -0.85,-0.8,-0.75,-0.7,-0.65,-0.6,-0.55,-0.5,-0.45,-0.4,-0.35,-0.3,-0.25,-0.2,-\ 0.15,-0.1,-0.05,0.,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65, 0.7,0.75,0.8,0.85,0.9,0.95,1.,1.05,1.1,1.15,1.2,1.25,1.3,1.35,1.4,1.45,1.5, 1.55,1.6,1.65,1.7,1.75,1.8,1.85,1.9,1.95,2.} For a variety or Values, Position returned the null set. In[286]:= Position[x,-.2] Position[x,-1.15] Position[x,-.15] Position[x,-.05] Position[x,.1] Out[286]= {} Out[287]= {{38}} Out[288]= {} Out[289]= {} Out[290]= {} The use of InputForm sheds a little light on the situation, but even that is not consistent, for example the values -1.15 vs. -.15. I was able to offer a work around that seemed to work, but I am not sure how reliable it is: xList=Floor[x*100]/100//N In anycase, even though I partially understand the behavior, it in general seems wierd. Is there an easy way to make Position work as expected for real numbers, or more accurately make Range work as expected ??? Thanks, Jason P.S. Mathematica 3.0 on Win 95. In[285]:= x//InputForm Out[285]//InputForm= {-3, -2.95, -2.9, -2.85, -2.799999999999999, -2.75, -2.7, -2.649999999999999, -2.6, -2.549999999999999, -2.5, -2.45, -2.399999999999999, -2.35, -2.299999999999999, -2.25, -2.2, -2.149999999999999, -2.1, -2.049999999999999, -2., -1.95, -1.9, -1.849999999999999, -1.799999999999999, -1.75, -1.7, -1.649999999999999, -1.599999999999999, -1.549999999999999, -1.5, -1.45, -1.399999999999999, -1.349999999999999, -1.299999999999999, -1.25, -1.199999999999999, -1.149999999999999, -1.099999999999999, -1.049999999999999, -1., -0.9499999999999996, -0.9, -0.85, -0.7999999999999998, -0.75, -0.6999999999999997, -0.6499999999999999, -0.5999999999999996, -0.5499999999999998, -0.5, -0.4499999999999997, -0.3999999999999999, -0.3499999999999996, -0.2999999999999998, -0.25, -0.1999999999999997, -0.1499999999999999, -0.09999999999999964, -0.04999999999999982, 0, 0.05000000000000026, 0.1, 0.1500000000000003, 0.2000000000000001, 0.25, 0.3000000000000002, 0.35, 0.4000000000000003, 0.4500000000000001, 0.5, 0.5500000000000002, 0.6, 0.6500000000000003, 0.7000000000000001, 0.75, 0.8000000000000003, 0.85, 0.9000000000000003, 0.9500000000000001, 1., 1.049999999999999, 1.1, 1.15, 1.2, 1.25, 1.299999999999999, 1.35, 1.4, 1.45, 1.5, 1.549999999999999, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2.}