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: Test of a pure function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34038] RE: [mg34010] Test of a pure function
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Sat, 27 Apr 2002 00:57:04 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

A pure function isn't always the way to go --- for maintainability of
the code, if nothing else.  Look at this approach:

xBins=Union[Sort[Random[Integer,{1,100}]&/@Range[10]]]

{1,39,46,54,55,66,75,85,96,100}

bracket[x_]:=
  Flatten[Position[
      IntervalMemberQ[#,x]&/@
        Interval/@
 
Transpose[{Join[{-\[Infinity]},xBins],Join[xBins,{\[Infinity]}]}],
      True]]

bracket/@Join[{-20},xBins,{200}]

{{1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10},{10,11},{11}
}

This function gives the positions in xBins of elements that bracket x
or, if x < Min[xBins] it gives {1}, and if x > Max[xBins] it gives
{Length[xBins]+1}.  The two special cases return singletons while usual
cases result in at least two elements returned.

It seems to me that a good solution might involve ListCorrelate, but I
haven't been able to think that through as yet.

Bobby Treat

-----Original Message-----
From: Shawn O'Connor [mailto:soconnor at ccs.nrl.navy.mil] 
To: mathgroup at smc.vnet.net
Subject: [mg34038] [mg34010] Test of a pure function

Hello,

    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.
Thank you,








  • Prev by Date: Re: 3D contour through a point
  • Next by Date: Re: Getting File Directory Using Any Platform
  • Previous by thread: Re: Test of a pure function
  • Next by thread: RE: Re: Test of a pure function