# Loop Outputs as Lists [duplicate]

\[GothicCapitalR] = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{0, 1,
0}, {0, 0, 1}, {1, 0, 0}}, {{0, 0, 1}, {1, 0, 0}, {0, 1,
0}}, {{1, 0, 0}, {0, 0, 1}, {0, 1, 0}}, {{0, 0, 1}, {0, 1,
0}, {1, 0, 0}}, {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}};
i = 1;
j = 1;
det = 1;
a = Subsets[Range, {3}];
v = {x, y, z};
k = \[GothicCapitalR].v;
r = k[[a[[i]]]];
Det[r];
While[i < 21,
r = k[[a[[i]]]];
det = Factor[Det[r]];
Print[det]; i++]

-(x+y+z) (x^2-x y+y^2-x z-y z+z^2)
(x-y) (y-z) (x+y+z)
-(x-z) (y-z) (x+y+z)
-(x-y) (x-z) (x+y+z)
(x-z) (y-z) (x+y+z)
(x-y) (x-z) (x+y+z)
-(x-y) (y-z) (x+y+z)
-(x-z) (y-z) (x+y+z)
-(x-y) (y-z) (x+y+z)
-(x-y) (x-z) (x+y+z)
-(x-y) (x-z) (x+y+z)
(x-y) (y-z) (x+y+z)
-(x-z) (y-z) (x+y+z)
(x-y) (y-z) (x+y+z)
(x-y) (x-z) (x+y+z)
-(x-z) (y-z) (x+y+z)
-(x-y) (x-z) (x+y+z)
(x-z) (y-z) (x+y+z)
(x-y) (y-z) (x+y+z)
-(x+y+z) (x^2-x y+y^2-x z-y z+z^2)


Anyone have any suggestions on how to get the output of this loop to be a list of polynomials so that I can use the PolynomialLCM function on it? I will be adapting this loop to larger dimensions and will need to be able to have Mathematica perform this calculation for me.

• Do you mean so it isn't a string? Jul 6, 2015 at 15:53

Instead of While[i<21,...], use Table[...,{i,20}]. The ... part can be reduced to

r = k[[a[[i]]]];
Factor[Det[r]]


To find the PolynomialLCM, simply replace the head ( List) of the table with PolynomialLCM using Apply, or @@ for short:

PolynomialLCM @@ Table[...,{i,20}]

• This is indeed a much tighter means to create the same list, Is there a way to get the LCM of this output without selecting them manually? Jul 6, 2015 at 17:40
• Yes, see my edited post. You should probably read the doc's on Apply, Map and Table, as these are some of the cornerstones in Mathematica ;) Jul 6, 2015 at 18:45

Replace the Print[det] in the print with:

Paste[det]

\[GothicCapitalR] = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{0, 1,
0}, {0, 0, 1}, {1, 0, 0}}, {{0, 0, 1}, {1, 0, 0}, {0, 1,
0}}, {{1, 0, 0}, {0, 0, 1}, {0, 1, 0}}, {{0, 0, 1}, {0, 1,
0}, {1, 0, 0}}, {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}};
i = 1;
j = 1;
det = 1;
a = Subsets[Range, {3}];
v = {x, y, z};
k = \[GothicCapitalR].v;
PolynomialLCM @@ Table[Factor[Det[k[[a[[i]]]]]], {i, 1, 20}]