Re: patterns

• To: mathgroup at smc.vnet.net
• Subject: [mg31188] Re: patterns
• From: "Alan Mason" <swt at austin.rr.com>
• Date: Tue, 16 Oct 2001 01:19:16 -0400 (EDT)
• References: <9q66qu\$rs4\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hello Yannis.
The following code snippet should get you started.

In[79]:=
L = {1.`,1.1`,1.2`,1.1`,1.4`,1.5`,1.6`,1.2`,1.3`,1.7`};

In[80]:=
cond = #>1.1;
pickPair[L_List, cond_] := Module[{a, b,c, L2, pos, pos2},
L2 = Union[Select[L, cond&]];
Print["L2 is ", L2];
pos = Sort[Flatten[Position[L, #]&/@ L2]];
Print["pos is ", pos];
pos2[{}] := {};
pos2[{a_}] := {};
pos2[{a_, b_}] := If[b-a\[Equal]1, {a, b}, {}];
pos2[{a_, b_, c___}] := Flatten[Append[pos2[{a, b}], pos2[{b,c}]]];
pos = Union[pos2[pos]];
Print["pos is ", pos];
If[Length[pos]<2, Return[{}]];
Return[  Take[ L, {pos[[1]], pos[[2]]}]];
]

In[82]:=
pickPair[L, cond]

L2 is \[InvisibleSpace]{1.2,1.3,1.4,1.5,1.6,1.7}

pos is \[InvisibleSpace]{3,5,6,7,8,9,10}

pos is \[InvisibleSpace]{5,6,7,8,9,10}

Out[82]=
{1.4,1.5}

Modify to taste.

Alan
<Yannis.Paraskevopoulos at ubsw.com> wrote in message
news:9q66qu\$rs4\$1 at smc.vnet.net...
> Hi,
>
> I have built the following function for selecting consecutive elements
> of a list that do satisfy a particular condition. Here it is:
>
>
> f[x_, matrix_] := Module[{t, selector},
> (* Flatten and group number in pairs *)
>     t = Partition[Flatten[matrix], 2];
> (* Selector : returns true if all in list  > x *)
>     selector[xx_, list_] := Apply[And, Map[(# > xx) &, list]];
>     (* select *)
>     Select[t, selector[x, #] &]]
>
>
> t = Table[Table[Random[], {4}], {12}];
>
> f[0.01,t]
>
> {{0.301739,0.837578},{0.710472,0.373638},{0.950287,0.828919},{0.327263,
>     0.861149},{0.734775,0.491342},{0.623224,0.365866},{0.962033,
>     0.549466},{0.0602337,0.0313664},{0.293098,0.277972},{0.0841844,
>     0.550993},{0.0538037,0.157458},{0.990937,0.167571},{0.752064,
>     0.31988},{0.280465,0.793933},{0.801777,0.490962},{0.953202,
>     0.932784},{0.0670017,0.99962},{0.329978,0.566918},{0.104969,
>     0.450153},{0.269745,0.535552},{0.811871,0.172181},{0.18556,
>     0.984558},{0.758067,0.0147228},{0.194623,0.816987}}
>
> seems to work. My question is how one could modify the function so :
> 1) we pick the first set of consecutive numbers that satisfy the
> condition and 2) from any partition of 10 you check the first 5 who
> satisfy the condition (again continuous) and then go  to the next row
> of the initial matrix.
>
> Do you know any good reference with lots of examples for conditions and
> patterns with lists and matrices?
>
>
> Thank you very much in advance.
>
> yannis
>
>
>
>
>
>
> This message contains confidential information and is intended only
> for the individual named.  If you are not the named addressee you
> should not disseminate, distribute or copy this e-mail.  Please
> notify the sender immediately by e-mail if you have received this
> e-mail by mistake and delete this e-mail from your system.
>
> E-mail transmission cannot be guaranteed to be secure or error-free
> as information could be intercepted, corrupted, lost, destroyed,
> arrive late or incomplete, or contain viruses.  The sender therefore
> does not accept liability for any errors or omissions in the contents
> of this message which arise as a result of e-mail transmission.  If
> verification is required please request a hard-copy version.  This
> message is provided for informational purposes and should not be
> construed as a solicitation or offer to buy or sell any securities or
> related financial instruments.
>
>

```

• Prev by Date: Re: How do I eliminate premultipliers of "1." ?
• Next by Date: Re: patterns
• Previous by thread: Re: patterns
• Next by thread: Re: Using NDSolve for 2-variables function ?