This is a small version of my code (for n=2):
V0 = {{{3, 3, 2, 2}}};
S0 = {{{1, 2, 0, 4}}, {{0, 3, 2, 2}}, {{2, 2, 0, 3}}, {{1, 2, 1, 2}}};
S1 = Join @@@ Tuples[{S0, V0}];
S2 = Pick[DeleteDuplicatesBy[Sort]@S1,
MatrixRank[#] == 2 & /@ DeleteDuplicatesBy[Sort]@S1];
S3 = Join @@@ Tuples[{S0, S2}];
S4 = Pick[DeleteDuplicatesBy[Sort]@S3,
MatrixRank[#] == 3 & /@ DeleteDuplicatesBy[Sort]@S3];
S5 = Join @@@ Tuples[{S0, S4}];
S6 = Pick[DeleteDuplicatesBy[Sort]@S5,
MatrixRank[#] == 4 & /@ DeleteDuplicatesBy[Sort]@S5];
MatrixForm /@ S6
As you can see, it repeats the action of joining the matrices with the last set, deleting the duplicates and picking those with maximal rank. The final result is a set of 4×4 matrices. In general, for a given $n\in\Bbb N$, I have to manually write $2(n^n-1)$ lines. Is there I way to automate this procedure?
The aim of the code: Obtain the set of all invertible matrices with {3,3,2,2}
as the first line and elements of S0
as the other ones.
I could generate the the set of $3\times4$ matrices formed by elements of S0
and then Prepend
the vector {3,3,2,2}
to each one, but the task "pick those with rank 4" (or "with non null determinant") is harder for the computer. Because of this, I add one line per time and take out those matrices whose rank is not maximal. The example above is very easy, but for sets with 1 million matrices, calculate the rank of each one may take a while.
Fold
orNest
helpful, but to help further, could you explain in words what you are trying to achieve with your code? $\endgroup$ – MarcoB Oct 2 '17 at 18:37