0
$\begingroup$

I have a question about the following code:

Den[n_,l_,m_]:=(Sqrt[(2/n)^3*(n-l-1)!/(2*n*(n+l)!)]*Exp[-r/n]*((2*r/n)^l)*LaguerreL[n-l-1,2*l+1,2*r/n]*SphericalHarmonicY[l,m,theta,phi])*Conjugate[Sqrt[(2/n)^3*(n-l-1)!/(2*n*(n+l)!)]*Exp[-r/n]*((2*r/n)^l)*LaguerreL[n-l-1,2*l+1,2*r/n]*SphericalHarmonicY[l,m,theta,phi]]
       shan[n_,l_,m_]:=-NIntegrate[Den[n,l,m]*Log[Den[n,l,m]]*Sin[theta]*r^2,{r,0,Infinity},{theta,0,Pi},{phi,0,2*Pi}]

Ciclo=Table[{n,l,m,shan[n,l,m]},{n,1,2},{l,0,n-1},{m,0,l}]

(* {{{{1,0,0,4.14473}}},{{{2,0,0,8.11093}},{{2,1,0,7.2649},{2,1,1,7.57175+0. I}}}} *)

Tabla=TableForm[SortBy[Flatten[Chop[Ciclo],2],#[[2]]&&#[[1]]&]]


1  0  0  4.14473
2  0  0  8.11093
2  1  0  7.2649
2  1  1  7.57175

Export["sumas.xlsx",Tabla,"XLSX"];

My question is: how can I add a column after sorting my data (SortBy)? Something like this:

1  1  0  0  4.14473
2  2  0  0  8.11093
3  2  1  0  7.2649
4  2  1  1  7.57175

I wanted to add that column and then plot the data with a ListLinePlot.

Note: The SortBy is important, because I actually work with many "n" values. Here I put an example with only 2 values of "n", so as not to copy a huge list of data.

$\endgroup$
  • 1
    $\begingroup$ See Join command documentacion is useful $\endgroup$ – bullitohappy Mar 11 '18 at 18:22
0
$\begingroup$

This would work if you just want to add a column at the beginning or at the end (in this case just reverse the arguments of Join):

Join[{#} & /@ Range[4], Tabla, 2]

1 1 0 0 4.144729893771763
2 2 0 0 8.110929417877866
3 2 1 0 7.264898399958045
4 2 1 1 7.571750374855915
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.