I have the two variables L,m such that
L=0 => m=0
L=1 =>m=-1,0,1
L=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 like
list= {{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=2
What should be the code for this list? kindly help and sorry for mistake in the text
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}}}
Thanks David !! it really works ![]()
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}}}