MathGroup Archive 2005

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

Search the Archive

Re: Pattern Matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58239] Re: Pattern Matching
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 24 Jun 2005 02:49:58 -0400 (EDT)
  • References: <d9e0bc$g6i$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Jeff,
we can do your desired selection  by a condition with a side effect. We 
need a auxillary variable, say tt that we set to your starting 
threshold, e.g.
tt= t[[1]]-2;
we now construct a function that test the condition and, if True, 
decrements tt by two. Remember that boolean expressions connected by && 
are evaluated left to right until one expression fails. Therefore,
(#<=tt)&&(tt=tt-2;True) &
will test and decrement when needed. This function used in a Select 
statement:
Select[t,(#<=tt)&&(tt=tt-2;True) &]
will do the trick.
sincerely, Daniel

Jeff wrote:
> Given a list of numbers, t = {0, -1, 0, -1, -2, -3, -4,-3,-4,-5}, I
> would like to extract those numbers that are less than or equal to the
> starting value by, for example, at least 2, but once the first (and
> each subsequent) match is found, I would the starting value to drop by
> 2.  So for the list t, the output would be {-2, -4}.
> 
> I can use Cases or map using If[ ] on the list to extract those
> elements that are less than or equal to -2, but I'm having difficutly
> in figuring out how to change the starting value to be applied to
> subsequent elements of the list.
> 
> Given my example, I could just extract all the multiples of 2 in the
> list, but I would like the starting value to change by a fixed
> percentage or combination of fixed number and percentage.
> 
> Thanks,
> Jeff
> 


  • Prev by Date: Re: General 3-state stochastic matrix (again)
  • Next by Date: Re: Numerical solution of quadratic equations set.
  • Previous by thread: Re: Pattern Matching
  • Next by thread: Simplify and Memory