Re: Test of a pure function

*To*: mathgroup at smc.vnet.net*Subject*: [mg34041] Re: [mg34010] Test of a pure function*From*: BobHanlon at aol.com*Date*: Sat, 27 Apr 2002 00:57:14 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

In a message dated 4/26/02 5:11:41 AM, soconnor at ccs.nrl.navy.mil writes: >I hope someone can help me with this I know the solution should be easy >but I am still learning how pure functions work. > >I am trying to pick out a position in a list were a number falls i.e. > >Position[xBins, _?(#1<=x <= #2 &)]. I keep getting errors Like these > > >Function::slotn: Slot number 2 in #1 x #2& cannot be filled >from \ >(#1 x #2&)[List]. > >Function::slotn: Slot number 2 in >#1 x #2& cannot be filled from \ >(#1 x #2&)[-1]. > >From >In[83]:= >Function::slotn: Slot number 2 in #1 x #2& cannot be filled from >\ >(#1 x #2&)[-0.995]. > >General::stop: Further output of >Function::slotn will be suppressed during \ >this calculation. > > >Can I make a comparison with the nth and nth+1 element in a pure function. > Rather than trying to compare x to two adjacent values, restructure the question to count the number of values less than or equal to x. myPosition[xBins_?VectorQ, x_?NumericQ] := Count[xBins, _?(#<=x&)]+1; data = Sort[Table[Random[], {10}]] {0.08812644925276472, 0.10010226701182356, 0.4254438313086471, 0.4540738901849056, 0.5471335846922069, 0.6297724295620055, 0.725499086248874, 0.8527355066955329, 0.8919613144350851, 0.9392439737457312} myPosition[data, .5] 5 Bob Hanlon Chantilly, VA USA