0
$\begingroup$

My goal is to evaluate the total of each line of the following list:

f2 = {{c1, c2 Log[(En k T1)/(c^4 m^2)], c3 Log[(En k T1)/(c^4 m^2)]^2, c4 Log[(En k T1)/(c^4 m^2)]^3, c5 Log[(En k T1)/(c^4 m^2)]^4, c6 Log[(En k T1)/(c^4 m^2)]^5}, {c1, c2 Log[(En k T2)/(c^4 m^2)], c3 Log[(En k T2)/(c^4 m^2)]^2, c4 Log[(En k T2)/(c^4 m^2)]^3, c5 Log[(En k T2)/(c^4 m^2)]^4, c6 Log[(En k T2)/(c^4 m^2)]^5}, {c1, c2 Log[(En k T3)/(c^4 m^2)], c3 Log[(En k T3)/(c^4 m^2)]^2, c4 Log[(En k T3)/(c^4 m^2)]^3, c5 Log[(En k T3)/(c^4 m^2)]^4, c6 Log[(En k T3)/(c^4 m^2)]^5}, {c1, c2 Log[(En k T4)/(c^4 m^2)], c3 Log[(En k T4)/(c^4 m^2)]^2, c4 Log[(En k T4)/(c^4 m^2)]^3, c5 Log[(En k T4)/(c^4 m^2)]^4, c6 Log[(En k T4)/(c^4 m^2)]^5}, {c1, c2 Log[(En k T5)/(c^4 m^2)], c3 Log[(En k T5)/(c^4 m^2)]^2, c4 Log[(En k T5)/(c^4 m^2)]^3, c5 Log[(En k T5)/(c^4 m^2)]^4, c6 Log[(En k T5)/(c^4 m^2)]^5}, {c1, c2 Log[(En k T6)/(c^4 m^2)], c3 Log[(En k T6)/(c^4 m^2)]^2, c4 Log[(En k T6)/(c^4 m^2)]^3, c5 Log[(En k T6)/(c^4 m^2)]^4, c6 Log[(En k T6)/(c^4 m^2)]^5}, {c1, c2 Log[(En k T7)/(c^4 m^2)], c3 Log[(En k T7)/(c^4 m^2)]^2, c4 Log[(En k T7)/(c^4 m^2)]^3, c5 Log[(En k T7)/(c^4 m^2)]^4, c6 Log[(En k T7)/(c^4 m^2)]^5}}

To achieve that, I have used.

In[31]:= f3 = Table[Total[f2[[l]]], {l, Length[f2]}] 
Out[31]= {c1 + c2 Log[(En k T1)/(c^4 m^2)] + c3 Log[(En k T1)/(c^4 m^2)]^2 + c4 Log[(En k T1)/(c^4 m^2)]^3 + c5 Log[(En k T1)/(c^4 m^2)]^4 + c6 Log[(En k T1)/(c^4 m^2)]^5, c1 + c2 Log[(En k T2)/(c^4 m^2)] + c3 Log[(En k T2)/(c^4 m^2)]^2 + c4 Log[(En k T2)/(c^4 m^2)]^3 + c5 Log[(En k T2)/(c^4 m^2)]^4 + c6 Log[(En k T2)/(c^4 m^2)]^5, c1 + c2 Log[(En k T3)/(c^4 m^2)] + c3 Log[(En k T3)/(c^4 m^2)]^2 + c4 Log[(En k T3)/(c^4 m^2)]^3 + c5 Log[(En k T3)/(c^4 m^2)]^4 + c6 Log[(En k T3)/(c^4 m^2)]^5, c1 + c2 Log[(En k T4)/(c^4 m^2)] + c3 Log[(En k T4)/(c^4 m^2)]^2 + c4 Log[(En k T4)/(c^4 m^2)]^3 + c5 Log[(En k T4)/(c^4 m^2)]^4 + c6 Log[(En k T4)/(c^4 m^2)]^5, c1 + c2 Log[(En k T5)/(c^4 m^2)] + c3 Log[(En k T5)/(c^4 m^2)]^2 + c4 Log[(En k T5)/(c^4 m^2)]^3 + c5 Log[(En k T5)/(c^4 m^2)]^4 + c6 Log[(En k T5)/(c^4 m^2)]^5, c1 + c2 Log[(En k T6)/(c^4 m^2)] + c3 Log[(En k T6)/(c^4 m^2)]^2 + c4 Log[(En k T6)/(c^4 m^2)]^3 + c5 Log[(En k T6)/(c^4 m^2)]^4 + c6 Log[(En k T6)/(c^4 m^2)]^5, c1 + c2 Log[(En k T7)/(c^4 m^2)] + c3 Log[(En k T7)/(c^4 m^2)]^2 + c4 Log[(En k T7)/(c^4 m^2)]^3 + c5 Log[(En k T7)/(c^4 m^2)]^4 + c6 Log[(En k T7)/(c^4 m^2)]^5}

This seems correct, but when I check the length of each element, this is.

In[32]:= Length[f3[[1]]]
Out[32]= 6

so, I can't use it as a list of 7 elements since it has a higher dimension. Do you know why? Is there a way to "flatter" these elements?

I tried also the function Sum but it works in the same way.

$\endgroup$
5
  • $\begingroup$ Check: Dimensions@f3 $\endgroup$
    – Syed
    Feb 23 at 11:00
  • 1
    $\begingroup$ f3 has a length of 7. f3[[1]] is the first element of f3, consisting of a sum of 6 elements. $\endgroup$ Feb 23 at 11:12
  • $\begingroup$ Try Length[Plus[x, y, z]]. It gives the length of any expression, not just of lists. Note that using the level spec, Total[f2, {2}], yields f3. $\endgroup$
    – Goofy
    Feb 23 at 11:25
  • 1
    $\begingroup$ Do you mean: "Total of each sublist" under the words: "total of each line of the following list?" If yes, try this: Map[Total, f2]. $\endgroup$ Feb 23 at 11:39
  • $\begingroup$ In your example, Length[f3[[1]]] is 6 because there are six terms in the expression. See the $Scope$ section of the Length documentation. $\endgroup$
    – creidhne
    Feb 23 at 12:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.