.1382
===
Subject: Sequence@@List
I want to construct the corresponding variable list to a
CoefficientList[poly, {var1, var2, var3,...}].
The following code does the work:
---------------------------------------------------------
In[472]:=
vl = {x, y, z}
dims = {2, 3, 2}
r = Dimensions[dims]
Out[472]=
{x,y,z}
Out[473]=
{2,3,2}
Out[474]=
{3}
In[475]:=
Table[vl[[1]]^a*vl[[2]]^b*
vl[[3]]^c, {a, 0,
dims[[1]] - 1},
{b, 0, dims[[2]] - 1},
{c, 0, dims[[3]] - 1}]
Out[475]=
!({{{1, z}, {y, y z}, {y^2, y^2 z}}, {{x, x
z}, {x y, x y z}, {x y^2, x y^2 z}}})
-----------------------------------------------------------
To do the job automated (so that a different variable list vl can be
used easily, as well as the output of Dimensions[CoefficientList[...]]
can be used as dims, for veriable polynomials and variables) I tried
------------------------------------------------------------
In[477]:=
body = Product[vl[[k]]^i[k],
{k, 1, Dimensions[vl][[1]]}]
iterator = Table[{i[ind], 0,
dims[[ind]] - 1},
{ind, 1, r[[1]]}]
Table[body, Sequence @@ iterator]
Out[477]=
x^i[1]*y^i[2]*z^i[3]
Out[478]=
{{i[1], 0, 1}, {i[2], 0, 2},
{i[3], 0, 1}}
Table::itform:Argument !(Sequence @@ iterator) at position
!(2)
does
not have the correct form for an iterator.
!(*ButtonBox[Mehr.89¥Ï,
ButtonStyle->RefGuideLinkText, ButtonFrame->None,
ButtonData:>General::itform])
---------------------------------------------------------------
which does not work because in this case, because Sequence does not
strip the outer List brackets, while using it as the only argument to
some function, e.g.
---------------------------------------------------------------
In[480]:=
f[Sequence @@ iterator]
Out[480]=
f[{i[1], 0, 1}, {i[2], 0, 2},
{i[3], 0, 1}]
---------------------------------------------------------------
does work.
Any help regarding using Sequence in a function accepting more than just
one argument is appreciated!
Martin
===
Subject: Nonlinear Fit of Complex functions
Laura
Laura Borgese: Laura.Borgese@guest.unimi.it
Departement of Phisical Chemistry and Electrochemistry
University of Milan- Italy
===
Subject: autogenerated packages carriage returns and line feeds
Hi Mathgroup,
Does anyone know of a way to make the MS Windows front end save an
autogenerated package (.m file from initialization cells in a .nb file)
with line feeds instead of carriage returns and line feeds? If you do,
please let me know how.
Also/alternatively, can someone provide me with a way to save arbitrary
(ranges of) cells as plain text with the aforementioned line feeds
instead of carriage returns and line feeds?
===
Subject: automatic line feeds at 80 columns for generated packages
Would anyone care to drop some knowledge about how to force Mathematica
to end lines in autogenerated packages (or indeed, arbitrary exported
cell code) after 80 columns (with an LF only) using the windows front
end and kernel (or the windows front end and a remote linux kernel).
If so, please do! - and accept my mad props ;)
===
Subject: FindRoot & NDSolve
Hi all,
This is my first post to here.
I have a problem and want your help.
Mathematica 4 did the following calculation with no pleblem,
while Mathematica 5(.2) cannot do it.
FindRoot[
(f /.NDSolve[ {D[f[x], {x,1}] - 2 x - a == 0, f[0] == 0}, f, {x, -3, 3}
][[1]])[2] == 4,
{a, -10, 10}
]
Does anyone know solution or altanative way to do it?
Takashi Inoue,
Dept. Phys. Sophia University
===
Subject: Re: XMLElement and XMLObject docs
WRI's Bruce Miller replied to me personally on this, but for some
reason did not cc the list. I didn't notice until now. Since the
information might be useful to others, here it is:
>Mr. Chiasson,
>I found your note on MathGroup (above) and thought it worth
notifying our developers about.
>The answer to your last question is
AddOns and Links - XML Capabilities - Introduction - Symbolic XML
Representing Elements
Representing Other Objects
>This is a known bug in the documentation.
>Bruce Miller
Technical Support
Wolfram Research, Inc.
support@wolfram.com
http://support.wolfram.com/
===
Subject: Re: 3D Graphics suggestions?
For rotating 3D graphics, I use an experimental package called
RealTime3D, which might still be shipped by default with Mathematica -
I can tell you that it's in release 5.1.
It allows you to rotate the plot with the mouse. Unfortunately, not all
graphics and text components may be rendered (hence the
experimental).
Try, e.g.,
<< RealTime3D`
Plot3D[Sin[x y], {x, 0, 1}, {y, 0, 1}]
To return to the default 3D graphics rendering state, you'll need to
load
<< Default3D`
Best wishes,
Sugi
===
Subject: Re: Left Justification in a button
David,
One possibility is to get rid of the ButtonFrame which seems to block
the GridBox option ColumnAlignments. Then you can embellish the gridbox
with a frame and use StyleBox to give it a background color. For
example
CellPrint[Cell[BoxData[StyleBox[GridBox[{{ButtonBox[this is text,
ButtonFrame -> None]}}, ColumnWidths -> 20, ColumnAlignments ->
Left, GridFrame -> True], Background -> GrayLevel[0.9]]], Text,
FontWeight -> Bold , FontFamily -> Helvetica]]
Brian
===
Subject: Re: Plot -> axes inversion
For interchanging the x- and y- axes for plot a simple way is to use
ParametricPlot
ParametricPlot[ {1/Gamma[x] , x}, { x, -4 , 4 } , AxesLabel -> { y ,
x } ]
Brian
===
Subject: Re: Plot -> axes inversion
> Hi buddies ,
> I have a plot :
> Plot[ 1/Gamma[x] , { x, -4 ,4 } ,AxesLabel - > { x ,
y }
> I want to interchange the x- and y-axes. (A kinda rotatation by
90
> degrees ). Which option should I use ?
> How about the plot inversion option for Plot3D[ . ] ?
You could try replacement rules as in the following examples:
g = Plot[1/Gamma[x], {x, -4, 4}, AxesLabel -> {x, y}];
In[2]:=
Show[g /. {x_, y_} :> {y, x}];
Below, we have a rotation on the left by Pi/2
In[3]:=
Show[g /. {x_, y_} :> {-y, x}];
/J.M.
===
Subject: Re: Plot -> axes inversion
>I have a plot :
>Plot[ 1/Gamma[x] , { x, -4 ,4 } ,AxesLabel - > { x , y }]
>I want to interchange the x- and y-axes. (A kinda rotatation by 90
>degrees ). Which option should I use ?
I think the simplest way to do this would be to use ParametricPlot instead
of Plot, i.e.,
ParametricPlot[{1/Gamma[x], x}, {x, -4, 4}, AxesLabel->{x, y}];
--
To reply via email subtract one hundred and four
===
Subject: Forcing surds into the numerator
Does anyone know how I can force Mathematica to display surds in the
numerator of an expression, or a function that can be applied to do the
job?
For example, FullSimplify[1/(3+Sqrt[2])] returns itself and not 1/7
(3-root2)
Similarly, Sin[Pi/12] returns (-1+root3)/(2root2) and not 1/4 (root6-root2)
Tony
===
Subject: Re: Plot -> axes inversion
Plot[1/Gamma[x],{x,-4,4},
AxesLabel->{x,y}];
Show[
Plot[1/Gamma[x],{x,-4,4},
DisplayFunction->Identity]/.
{x_?NumericQ,y_?NumericQ,r___}:>{y,x,r},
AxesLabel->{y,x},
DisplayFunction->$DisplayFunction,
AspectRatio->1];
Bob Hanlon
===
> Subject: Plot -> axes inversion
> Hi buddies ,
> I have a plot :
> Plot[ 1/Gamma[x] , { x, -4 ,4 } ,AxesLabel - > { x ,
y }
> I want to interchange the x- and y-axes. (A kinda rotatation by
90
> degrees ). Which option should I use ?
> How about the plot inversion option for Plot3D[ . ] ?
===
Subject: Re: Multivariable Limits
there're some example in help browser.
===
Subject: Re: finding the position of a pattern in list (Correction)
> It is possible to do it still much faster by applying the method
> advocated a number of times on this list by Carl Woll (who seems to
> have finally grown tired of doing so I am posting this instead ;-))
> Here is the Woll approach:
> pos4[l_] := SparseArray[
> Sign[ListConvolve[{-1,
> 1}, l] + 1] - 1] /. SparseArray[_, _, _, p_] :> Flatten[p[[2, 2]]]
> Let's compare it with pos3 below:
> pos3[data_] := Position[Most[RotateLeft[data]] - Most[data], 1] //
> Flatten;
> In[3]:=
> data = Table[Random[Integer], {10^5}];
> In[4]:=
> Timing[a = pos4[data]; ]
> Out[4]=
> {0.04354899999999995*Second, Null}
> In[5]:=
> Timing[b = pos3[data]; ]
> Out[5]=
> {0.12303199999999992*Second, Null}
> In[6]:=
> a == b
> Out[6]=
> True
Andrzej,
matter. There's been a new addition to my family, and I've been enjoying
that.
Concerning your implementation, I would construct the sparse array
differently, avoiding ListConvolve:
pos5[li_] := Module[{m, r},
m = Most[li];
r = Rest[li];
SparseArray[(r - m)r] /. SparseArray[_,_,_,p_]:>Flatten[p[[2,2]]]
]
Comparing:
d = Table[Random[Integer], {10^6}];
In[22]:=
r1=pos4[d];//Timing
r2=pos5[d];//Timing
Out[22]=
{0.266 Second,Null}
Out[23]=
{0.109 Second,Null}
Out[24]=
True
Carl Woll
Wolfram Research
> Andrzej Kozlowski
>> There is an error in my second method. It will indicate a match for
>> the last
>> position if the first data element is 1 and the last data element is
>> 0. For
>> example,
>> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
>> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
>> data={1,0,0,1,0,0,1,0};
>> pos1[data]
>> {3,6}
>> pos2[data]
>> {3,6,8}
>> The correct method is
>> pos3[data_]:=Position[Most[RotateLeft[data]]-Most[data],1]//Flatten;
>> pos3[data]
>> {3,6}
>> The revision is still much faster than the original.
>> data=Table[Random[Integer],{100000}];
>> pos1[data]==pos3[data]
>> True
>> Timing[pos1[data]][[1]]
>> 0.389007 Second
>> Timing[pos3[data]][[1]]
>> 0.132175 Second
>> Bob Hanlon
===
> Subject: finding the position of a
> pattern in list
> Here is a faster method than the one that I first suggested.
> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
> data=Table[Random[Integer],{100000}];
> pos1[data]==pos2[data]
> True
> Timing[pos1[data]][[1]]
> 0.39032 Second
> Timing[pos2[data]][[1]]
> 0.128189 Second
> Bob Hanlon
>>
===
>> Subject: finding the position of a pattern
>> in list
>>
>> data={0,0,1,1,1,0,0,1,1,1,0};
>>
>> Position[Partition[data,2,1],{0,1}]//Flatten
>>
>> {2,7}
>>
>>
>> Bob Hanlon
>>
>
===
> Subject: finding the position of a pattern in
> list
>
> I am working on a program to do the following: My data is a list of
0
> and 1. For example, {0,0,1,1,1,0,0,1,1,1,0}. I want to find the
> positions of all the pattern of {0,1}. In my previous example, the
> first {0,1} is at 2 and and the second {0,1} appears at 7. I can
> write a loop to do this, but I have several thousands such lists,
> the computation will be time consuming using loop.
>
> My question is whether it is possible to use the pattern match to do
> this quickly. If not for the list, do I need to convert the list to
>
>
> Gang Ma
>
>
>
>
>>
===
Subject: Re: finding the position of a pattern in list (Correction)
It is possible to do it still much faster by applying the method
advocated a number of times on this list by Carl Woll (who seems to
have finally grown tired of doing so I am posting this instead ;-))
Here is the Woll approach:
pos4[l_] := SparseArray[
Sign[ListConvolve[{-1,
1}, l] + 1] - 1] /. SparseArray[_, _, _, p_] :> Flatten[p[[2,
2]]]
Let's compare it with pos3 below:
pos3[data_] := Position[Most[RotateLeft[data]] - Most[data], 1] //
Flatten;
In[3]:=
data = Table[Random[Integer], {10^5}];
In[4]:=
Timing[a = pos4[data]; ]
Out[4]=
{0.04354899999999995*Second, Null}
In[5]:=
Timing[b = pos3[data]; ]
Out[5]=
{0.12303199999999992*Second, Null}
In[6]:=
a == b
Out[6]=
True
Andrzej Kozlowski
> There is an error in my second method. It will indicate a match for
> the last
> position if the first data element is 1 and the last data element
> is 0. For
> example,
> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
> data={1,0,0,1,0,0,1,0};
> pos1[data]
> {3,6}
> pos2[data]
> {3,6,8}
> The correct method is
> pos3[data_]:=Position[Most[RotateLeft[data]]-Most[data],1]//Flatten;
> pos3[data]
> {3,6}
> The revision is still much faster than the original.
> data=Table[Random[Integer],{100000}];
> pos1[data]==pos3[data]
> True
> Timing[pos1[data]][[1]]
> 0.389007 Second
> Timing[pos3[data]][[1]]
> 0.132175 Second
> Bob Hanlon
===
>> Subject: finding the position of a
>> pattern in list
>> Here is a faster method than the one that I first suggested.
>> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
>> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
>> data=Table[Random[Integer],{100000}];
>> pos1[data]==pos2[data]
>> True
>> Timing[pos1[data]][[1]]
>> 0.39032 Second
>> Timing[pos2[data]][[1]]
>> 0.128189 Second
>> Bob Hanlon
===
> Subject: finding the position of a
> pattern in list
> data={0,0,1,1,1,0,0,1,1,1,0};
> Position[Partition[data,2,1],{0,1}]//Flatten
> {2,7}
> Bob Hanlon
>>
===
>> Subject: finding the position of a pattern
>> in list
>>
>> I am working on a program to do the following: My data is a list
>> of 0
>> and 1. For example, {0,0,1,1,1,0,0,1,1,1,0}. I want to find the
>> positions of all the pattern of {0,1}. In my previous example, the
>> first {0,1} is at 2 and and the second {0,1} appears at 7. I can
>> write a loop to do this, but I have several thousands such lists,
>> the computation will be time consuming using loop.
>>
>> My question is whether it is possible to use the pattern match
>> to do
>> this quickly. If not for the list, do I need to convert the
>> list to
>> much.
>>
>>
>> Gang Ma
>>
>>
>>
>>
===
Subject: Re: finding the position of a pattern in list (Correction)
I guess the easiest way to see what is gong on is to look at a very
simple example. Consider:
In[1]:=
ls=SparseArray[{0,1,0}]//InputForm
Out[1]//InputForm=
SparseArray[Automatic, {3}, 0, {1, {{0, 1}, {{2}}}, {1}}]
Look at the Output not the Input. Now you should understand what the
next step does
In[2]:=
ls/.SparseArray[_,_,_,p_]->p
Out[2]//InputForm=
{1, {{0, 1}, {{2}}}, {1}}
Andrzzej Kozlowski
> great, I learned a lot from them. Since Carl's solution is the
> fastest one, I will use it. However, its syntax is a bit
> mysterious for me, in particular the rule used in Carl SparseArray
> [_, _, _, p_] :> Flatten[p[[2, 2]]]. I checked the reference and
> found that SparseArray can have three arguments: data,dims, val.
> (Page 296 of Mathematica book 5th version) . But in Carl's rule, it
> has fourth arguments and the fourth one p is quite important.
> very much.
> Gang Ma
> It is possible to do it still much faster by applying the method
> advocated a number of times on this list by Carl Woll (who seems
> to have finally grown tired of doing so I am posting this
> instead ;-))
> Here is the Woll approach:
> pos4[l_] := SparseArray[
> Sign[ListConvolve[{-1,
> 1}, l] + 1] - 1] /. SparseArray[_, _, _, p_] :> Flatten[p
> [[2, 2]]]
> Let's compare it with pos3 below:
> pos3[data_] := Position[Most[RotateLeft[data]] - Most[data],
> 1] // Flatten;
> In[3]:=
> data = Table[Random[Integer], {10^5}];
> In[4]:=
> Timing[a = pos4[data]; ]
> Out[4]=
> {0.04354899999999995*Second, Null}
> In[5]:=
> Timing[b = pos3[data]; ]
> Out[5]=
> {0.12303199999999992*Second, Null}
> In[6]:=
> a == b
> Out[6]=
> True
>> Andrzej,
>> another matter. There's been a new addition to my family, and I've
>> been enjoying that.
>> Concerning your implementation, I would construct the sparse array
>> differently, avoiding ListConvolve:
>> pos5[li_] := Module[{m, r},
>> m = Most[li];
>> r = Rest[li];
>> SparseArray[(r - m)r] /. SparseArray[_,_,_,p_]:>Flatten[p[[2,2]]]
>> ]
>> Comparing:
>> d = Table[Random[Integer], {10^6}];
>> In[22]:=
>> r1=pos4[d];//Timing
>> r2=pos5[d];//Timing
>> Out[22]=
>> {0.266 Second,Null}
>> Out[23]=
>> {0.109 Second,Null}
>> Out[24]=
>> True
>> Carl Woll
>> Wolfram Research
> Andrzej Kozlowski
>> There is an error in my second method. It will indicate a match
>> for the last
>> position if the first data element is 1 and the last data
>> element is 0. For
>> example,
>>
>> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
>>
>> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
>>
>> data={1,0,0,1,0,0,1,0};
>>
>> pos1[data]
>>
>> {3,6}
>>
>> pos2[data]
>>
>> {3,6,8}
>>
>> The correct method is
>>
>> pos3[data_]:=Position[Most[RotateLeft[data]]-Most[data],1]//
>> Flatten;
>>
>> pos3[data]
>>
>> {3,6}
>>
>> The revision is still much faster than the original.
>>
>> data=Table[Random[Integer],{100000}];
>>
>> pos1[data]==pos3[data]
>>
>> True
>>
>> Timing[pos1[data]][[1]]
>>
>> 0.389007 Second
>>
>> Timing[pos3[data]][[1]]
>>
>> 0.132175 Second
>>
>>
>> Bob Hanlon
>>
>
>>
===
> Subject: finding the position of a
> pattern in list
>
> Here is a faster method than the one that I first suggested.
>
> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
>
> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
>
> data=Table[Random[Integer],{100000}];
>
> pos1[data]==pos2[data]
>
> True
>
> Timing[pos1[data]][[1]]
>
> 0.39032 Second
>
> Timing[pos2[data]][[1]]
>
> 0.128189 Second
>
>
> Bob Hanlon
>
>>
>>
===
>> Subject: finding the position of a
>> pattern in list
>>
>> data={0,0,1,1,1,0,0,1,1,1,0};
>>
>> Position[Partition[data,2,1],{0,1}]//Flatten
>>
>> {2,7}
>>
>>
>> Bob Hanlon
>>
>
>>
===
> Subject: finding the position of a
> pattern in list
>
> I am working on a program to do the following: My data is a
> list of 0
> and 1. For example, {0,0,1,1,1,0,0,1,1,1,0}. I want to find the
> positions of all the pattern of {0,1}. In my previous
> example, the
> first {0,1} is at 2 and and the second {0,1} appears at 7. I can
> write a loop to do this, but I have several thousands such
> lists,
> the computation will be time consuming using loop.
>
> My question is whether it is possible to use the pattern
> match to do
> this quickly. If not for the list, do I need to convert the
> list to
> very much.
>
>
> Gang Ma
>
>
>
>
>>
>
>>
===
Subject: Re: 3D Graphics suggestions?
Sensei,
You could try
<
Part of the inhumanity of the computer is that, once it is competently
programmed and working smoothly, it is completely honest. (Isaac Asimov)
===
Subject: Re: finding the position of a pattern in list (Correction)
great, I learned a lot from them. Since Carl's solution is the
fastest one, I will use it. However, its syntax is a bit mysterious
for me, in particular the rule used in Carl SparseArray[_, _, _,
p_] :> Flatten[p[[2, 2]]]. I checked the reference and found that
SparseArray can have three arguments: data,dims, val. (Page 296 of
Mathematica book 5th version) . But in Carl's rule, it has fourth
arguments and the fourth one p is quite important.
very much.
Gang Ma
>> It is possible to do it still much faster by applying the method
>> advocated a number of times on this list by Carl Woll (who seems
>> to have finally grown tired of doing so I am posting this
>> instead ;-))
>> Here is the Woll approach:
>> pos4[l_] := SparseArray[
>> Sign[ListConvolve[{-1,
>> 1}, l] + 1] - 1] /. SparseArray[_, _, _, p_] :> Flatten[p
>> [[2, 2]]]
>> Let's compare it with pos3 below:
>> pos3[data_] := Position[Most[RotateLeft[data]] - Most[data],
>> 1] // Flatten;
>> In[3]:=
>> data = Table[Random[Integer], {10^5}];
>> In[4]:=
>> Timing[a = pos4[data]; ]
>> Out[4]=
>> {0.04354899999999995*Second, Null}
>> In[5]:=
>> Timing[b = pos3[data]; ]
>> Out[5]=
>> {0.12303199999999992*Second, Null}
>> In[6]:=
>> a == b
>> Out[6]=
>> True
> Andrzej,
> matter. There's been a new addition to my family, and I've been
> enjoying that.
> Concerning your implementation, I would construct the sparse array
> differently, avoiding ListConvolve:
> pos5[li_] := Module[{m, r},
> m = Most[li];
> r = Rest[li];
> SparseArray[(r - m)r] /. SparseArray[_,_,_,p_]:>Flatten[p[[2,2]]]
> Comparing:
> d = Table[Random[Integer], {10^6}];
> In[22]:=
> r1=pos4[d];//Timing
> r2=pos5[d];//Timing
> Out[22]=
> {0.266 Second,Null}
> Out[23]=
> {0.109 Second,Null}
> Out[24]=
> True
> Carl Woll
> Wolfram Research
>> Andrzej Kozlowski
> There is an error in my second method. It will indicate a match
> for the last
> position if the first data element is 1 and the last data
> element is 0. For
> example,
> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
> data={1,0,0,1,0,0,1,0};
> pos1[data]
> {3,6}
> pos2[data]
> {3,6,8}
> The correct method is
> pos3[data_]:=Position[Most[RotateLeft[data]]-Most[data],1]//Flatten;
> pos3[data]
> {3,6}
> The revision is still much faster than the original.
> data=Table[Random[Integer],{100000}];
> pos1[data]==pos3[data]
> True
> Timing[pos1[data]][[1]]
> 0.389007 Second
> Timing[pos3[data]][[1]]
> 0.132175 Second
> Bob Hanlon
>>
===
>> Subject: finding the position of a
>> pattern in list
>>
>> Here is a faster method than the one that I first suggested.
>>
>> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
>>
>> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
>>
>> data=Table[Random[Integer],{100000}];
>>
>> pos1[data]==pos2[data]
>>
>> True
>>
>> Timing[pos1[data]][[1]]
>>
>> 0.39032 Second
>>
>> Timing[pos2[data]][[1]]
>>
>> 0.128189 Second
>>
>>
>> Bob Hanlon
>>
>
===
> Subject: finding the position of a
> pattern in list
>
> data={0,0,1,1,1,0,0,1,1,1,0};
>
> Position[Partition[data,2,1],{0,1}]//Flatten
>
> {2,7}
>
>
> Bob Hanlon
>
>>
===
>> Subject: finding the position of a
>> pattern in list
>>
>> I am working on a program to do the following: My data is a
>> list of 0
>> and 1. For example, {0,0,1,1,1,0,0,1,1,1,0}. I want to find the
>> positions of all the pattern of {0,1}. In my previous
>> example, the
>> first {0,1} is at 2 and and the second {0,1} appears at 7. I can
>> write a loop to do this, but I have several thousands such lists,
>> the computation will be time consuming using loop.
>>
>> My question is whether it is possible to use the pattern
>> match to do
>> this quickly. If not for the list, do I need to convert the
>> list to
>> very much.
>>
>>
>> Gang Ma
>>
>>
>>
>>
>
>>
===
Subject: Re: finding the position of a pattern in list
> Here is a faster method than the one that I first suggested.
> pos1[data_]:=Position[Partition[data,2,1],{0,1}]//Flatten;
> pos2[data_]:=Position[RotateLeft[data]-data,1]//Flatten;
> data=Table[Random[Integer],{100000}];
> pos1[data]==pos2[data]
> True
Whenever data has a leading 1 and a trailing 0, pos2 will include
the index of the last position, which pos1 will never do.
pos1[{1,0}]
pos2[{1,0}]
{}
{2}