MathGroup Archive 2002

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

Search the Archive

Re: Length of monotonic sequencies

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33581] Re: Length of monotonic sequencies
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 2 Apr 2002 03:36:29 -0500 (EST)
  • References: <a89191$pah$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

merkat,
Here are some ideas - it might be possible ot tune the splitting condition
to get closer to what you want.

    e1 = {2, 3, 4, 2, 5, 6, 5, 3, 2, 1, 1};

    n = 1;

    e2 =
    Split[Partition[e1, 2, 1],
       (#1 <= n && #2 <= n || #1 > n && #2 > n & )[
         Subtract @@ #1, Subtract @@ #2] &
    ]


{{{2,3},{3,4}},{{4,2}},{{2,5},{5,6},{6,5}},{{5,3}},{{3,2},{2,1},{1,1}}}

    (Join[First[#1], Last /@ Rest[#1]] & ) /@ e2

        {{2,3,4},{4,2},{2,5,6,5},{5,3},{3,2,1,1}}

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"merkat" <cabanc at hotmail.com> wrote in message
news:a89191$pah$1 at smc.vnet.net...
> Hi
>
> I want to get the lengths of the monotonic rising and falling  parts
> in a list l.
>
> for this I can use:
>
> Drop[RotateRight[l] - l, 1];
> % /. x_ /; x > 0 -> 1  ;
> % /. x_ /; x < 0 -> -1  ;
> Split[%]
> Length /@ %
>
> I want to include the case of no change in the sequence values which
> makes the seqence longer. (flat progression)
> I further want to relax the condition of monotonicity by allowing
> shallow drops in the sequences.
>
> for a drop of one unit:
> { 2,3,2,3,4,3,5,3,4,3,7}  gives {7,4}
>
> for a drop of 2 units:
> {2,3,4,2,5,6,5,1}              gives {7,1}
>
> how can the code be written for an arbitrary drop?
>
> Merkat
>




  • Prev by Date: Re: information on Eigensystem
  • Next by Date: Re: Automatic restart
  • Previous by thread: Length of monotonic sequencies
  • Next by thread: Re: Re: Mathematica & MS Word