0
|
2735 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

how to get the required list

Posted 11 years ago
 I have the two variables L,m such thatL=0 => m=0L=1 =>m=-1,0,1L=2 =>m = -2,-1,0,1,2 (for each value of L, m is from -L to +L with increment 1)now I want to generate a list with the order likelist= {{0,0},{1,0},{2,0},{1,-1},{2,-1},{1,1},{2,1},{2,-2},{2,2}}//   //all values of L for m=0    all values of L for m=-1    all values of L for m=1    all values of L for m=-2    all values of L for m=2What should be the code for this list? kindly help and sorry for mistake in the text
3 Replies
Sort By:
Posted 11 years ago
 Just an alternative:m[l_] := Range[-l, l]You can produce list:res = Join @@ Function[x, {x, #} & /@ m[x]] /@ Range[0, 2]This yields:{{0, 0}, {1, -1}, {1, 0}, {1, 1}, {2, -2}, {2, -1}, {2, 0}, {2, 1}, {2, 2}}Gathering:GatherBy[res, Last]yields:{{{0, 0}, {1, 0}, {2, 0}}, {{1, -1}, {2, -1}}, {{1, 1}, {2, 1}}, {{2, -2}}, {{2, 2}}}
Posted 11 years ago
 Hi Adil,Happy QM work! In[70]:= (* create the list *) nestedList = Table[{l, m}, {l, 0, 2}, {m, -l, l}];  In[71]:= (* flatten to individual states *) lMlist = Flatten[nestedList, 1];  In[72]:= (* gather by the m state *) gatherdByM = GatherBy[lMlist, #[[2]] &] Out[72]= {{{0, 0}, {1, 0}, {2, 0}}, {{1, -1}, {2, -1}}, {{1, 1}, {2,    1}}, {{2, -2}}, {{2, 2}}}
Posted 11 years ago
 Thanks David !!  it really works