3
$\begingroup$

I have tried to figure out how to make these changes, but it mostly just ends up with me making it ten times worse.

Insert[
 Multicolumn[
  Flatten[
   Table[
    {p, TraditionalForm@FullSimplify[ ((p - 2) n^2 - (p - 4) n)/2]},
    {p, 3, 32, 1}
    ]
   ],
  {12, 5}
  ],
 Alignment -> Center,
2
]

Needs to become

this is what the code needs to become

$\endgroup$
6
$\begingroup$
{p, ((p - 2) n^2 - (p - 4) n)/2 // Distribute} /. p -> Range[3, 32] // Transpose;
TraditionalForm@TableForm[Partition[%, 5], TableAlignments -> Center]

enter image description here

Explanation

Since most arithmetic operations are performed element-wise over lists (e.g. {a, b} + 1 -> {a + 1, b + 1}), we can strip the Table and just replace p with the list of given values. Then we can use Distribute to bring in the 1/2 term. And finally, since the list now has the structure

{
  {3,           4,   5,            ...},
  {n^2/2 + n/2, n^2, 3n^2/2 + n/2, ...}
}

and we want to pair up the elements in each column, we can use a good ol' fashion Transpose.

Then for the formatting into a grid, we need to Partition the list of lists into a 5x7x2 array, and then use TableForm with the TableAlignments option, and finally, to make it all pretty, we wrap the whole thing in a TraditionalForm.

$\endgroup$
4
$\begingroup$

Welcome to MSE. Here is one way

table = Table[{p, TraditionalForm@Expand[((p - 2) n^2 - (p - 4) n)/2]}, {p, 3, 32}];
table // Map[Column[#, Center] &] // Partition[#, 5] & // Grid

enter image description here

$\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.