Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*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 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: Test of a pure function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34046] RE: [mg34041] Re: [mg34010] Test of a pure function
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Sun, 28 Apr 2002 03:46:39 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

I like this solution a lot and can't think why I missed the idea...
probably because I'm not used to thinking in terms of patterns yet.

HOWEVER, if the list isn't always sorted and you want to find adjacent
list elements that bracket x, a solution more like mine is required.

Bobby

-----Original Message-----
From: BobHanlon at aol.com [mailto:BobHanlon at aol.com] 
To: mathgroup at smc.vnet.net
Subject: [mg34046] [mg34041] Re: [mg34010] Test of a pure function


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





  • Prev by Date: RE: Re: Dynamic referencing AND hyperlinking for numbered equations
  • Next by Date: Re: Re: recognizing integer numbers
  • Previous by thread: RE: Test of a pure function
  • Next by thread: Dynamic referencing AND hyperlinking for numbered equations