Re: Position and Real Numbers

• To: mathgroup at smc.vnet.net
• Subject: [mg18857] Re: [mg18811] Position and Real Numbers
• From: BobHanlon at aol.com
• Date: Thu, 22 Jul 1999 22:57:51 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Jason,

x = Range[-3, 2, .05];

Position is looking for an exact match, i.e., equivalent to SameQ

{Position[x, -.2], Position[x, -1.15],
Position[x, -.15], Position[x, -.05],
Position[x, .1]}

{{}, {{38}}, {}, {}, {}}

For the equivalent of Equals use

{Position[x, _?(# == -0.2 &)], Position[x, _?(# == -1.15 &)],
Position[x, _?(# == -.15 &)], Position[x, _?(# == -0.5 &)],
Position[x, _?(# == .1 &)]}

{{{57}}, {{38}}, {{58}}, {{51}}, {{63}}}

or

myPosition[x_List, val_?NumericQ] :=
Position[x, _?(# == val &)];

myPosition[x, #] & /@ {-.2, -1.15, -.15, -.5, .1}

{{{57}}, {{38}}, {{58}}, {{51}}, {{63}}}

Bob Hanlon

In a message dated 7/22/99 6:24:54 PM, jgill at vbimail.champlain.edu writes:

>    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]=
>{}

```

• Prev by Date: Re: ARghh!!
• Next by Date: Re: Limit of an Integer Function
• Previous by thread: Position and Real Numbers
• Next by thread: Re: Position and Real Numbers