I have matrix with dimensions {24,33} and matrix rank 23, it is symbolic. Is there a way to get matrix with dimension {23,23} by using built-in Mathematica functions? I would know how to get it simple..by taking one by one row which increases rank and than transpose it and do the same again. Is there a easier way?
2 Answers
This might work.
a = RandomChoice[Alphabet[], {5, 5}];
(*add some extra rows*)
a = Insert[a, 2 a[[1]], 4];
a = Insert[a, 3 a[[2]], 6];
MatrixForm[a]
\begin{pmatrix} \text{f} & \text{s} & \text{j} & \text{v} & \text{p} \\ \text{j} & \text{v} & \text{k} & \text{m} & \text{b} \\ \text{m} & \text{v} & \text{i} & \text{h} & \text{n} \\ 2 \text{f} & 2 \text{s} & 2 \text{j} & 2 \text{v} & 2 \text{p} \\ \text{z} & \text{e} & \text{k} & \text{n} & \text{x} \\ 3 \text{j} & 3 \text{v} & 3 \text{k} & 3 \text{m} & 3 \text{b} \\ \text{i} & \text{n} & \text{l} & \text{d} & \text{o} \\ \end{pmatrix}
Dimensions[a]
MatrixRank[a]
{7,5}
5
b = Transpose@RowReduce@Transpose@a;
c = a[[Position[b, 1][[All, 1]]]];
MatrixForm[c]
\begin{pmatrix} \text{f} & \text{s} & \text{j} & \text{v} & \text{p} \\ \text{j} & \text{v} & \text{k} & \text{m} & \text{b} \\ \text{m} & \text{v} & \text{i} & \text{h} & \text{n} \\ \text{z} & \text{e} & \text{k} & \text{n} & \text{x} \\ \text{i} & \text{n} & \text{l} & \text{d} & \text{o} \\ \end{pmatrix}
-
$\begingroup$ thank but no :( sorry I don't know how to insert new lines..try with this example: a = {{2 I A + 2 I B, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 2, 2 G1, 0, 0, 0, 0, 2 I A + 2 I B}, {0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2 I A + 2 I B, 0}, {0, 0, 0, 2, 0, 0, 0, 0, 0, 2 I A + 2 I B - G1 - G2, 0, 0}, {0, 0, 2, 0, 0, 0, 0, 0, 2 I A + 2 I B, 0, 0, 0}, {0, 2, 0, 0, 0, 0, 2 G2, 2 I A + 2 I B, 0, 0, 0, 0}}; $\endgroup$– JelenaNov 3, 2021 at 17:41
OK, here's a solution. My assumption is you want the candidate smaller matrix to have the same elements in the same order as the larger one, but with extra rows and columns removed. This generates all possible solutions.
Use your matrix in the comments
a = {{2 I A + 2 I B, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 2, 2 G1, 0, 0, 0, 0, 2 I A + 2 I B},
{0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2 I A + 2 I B, 0},
{0, 0, 0, 2, 0, 0, 0, 0, 0, 2 I A + 2 I B - G1 - G2, 0, 0},
{0, 0, 2, 0, 0, 0, 0, 0, 2 I A + 2 I B, 0, 0, 0},
{0, 2, 0, 0, 0, 0, 2 G2, 2 I A + 2 I B, 0, 0, 0, 0}};
Get the rank
mr=MatrixRank@a
(* 6 *)
Get the dimensions
{rise, run} = Dimensions@a
Get all possible permutations of the indices
rises = Subsets[Range[rise], {mr}];
runs = Subsets[Range[run], {mr}];
Get all permutations of matrices
matrices = Flatten[Outer[a[[#1, #2]] &, rises, runs, 1], 1];
There are lots of them
Length@matrices
(* 924 *)
Get just the ones that satisfy your requirement that they be full rank
goodmatrices = Select[matrices, MatrixRank[#] == mr &];
Of which there are still quite a few
Length@goodmatrices
(* 64 *)
This can all be combined into a neat function.
-
$\begingroup$ thank you, it looks ok. my question was more if it can be done with rowreduce of some transformation already implemented in mathematica, something like Sumit suggested. I know how to do it ... $\endgroup$– JelenaNov 5, 2021 at 13:30
-
$\begingroup$ You were never clear on exactly what you wanted, that the start matrix would be transformed into. It's still an open question. $\endgroup$– MikeYNov 5, 2021 at 18:46
-
$\begingroup$ let's say to reduce matrix by eliminating dependent columns and rows, but by using mathematica builtin functions, like rowreduce or something else. this is the way, and there are other, but I wonder is there something simpler: ll = Table[MatrixRank[Take[mat, ii]], {ii, 1, Length[mat]}]; gde = Table[FirstPosition[ll, ii], {ii, 1, MatrixRank[mat]}] // Flatten; Rmat = mat[[gde]]; Rmat = Transpose[Rmat]; ll = Table[MatrixRank[Take[Rmat, ii]], {ii, 1, Length[Rmat]}]; gde = Table[FirstPosition[ll, ii], {ii, 1, MatrixRank[Rmat]}] // Flatten; Rmat = Rmat[[gde]]; $\endgroup$– JelenaNov 9, 2021 at 13:16
{23,23}
matrix should be related to the initial{24,33}
matrix. $\endgroup$