2
$\begingroup$

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?

$\endgroup$
10
  • 1
    $\begingroup$ Could you post a smaller example? Lest say with a 5x3 matrix. $\endgroup$
    – Sumit
    Nov 3, 2021 at 15:58
  • $\begingroup$ best I could think of..but with numbers. so I need to get mat1 from mat2. thanx mat1 = Table[RandomInteger[100], {ii, 1, 3}, {jj, 1, 3}]; mat2 = Append[mat1, mat1[[3]]]; mat2 = Transpose[mat2]; mat2 = Join[mat2, {mat2[[1]] + mat2[[3]], mat2[[2]] - mat2[[3]]}]; mat2 = Transpose[mat2]; $\endgroup$
    – Jelena
    Nov 3, 2021 at 16:15
  • 3
    $\begingroup$ What is the relation between the {24,33} and {23,23} matrix? $\endgroup$ Nov 3, 2021 at 16:52
  • 1
    $\begingroup$ I fully concur with the @DanielHuber comment. You have to say how the resulting {23,23} matrix should be related to the initial {24,33} matrix. $\endgroup$
    – yarchik
    Nov 3, 2021 at 17:49
  • $\begingroup$ long story, I got bigger matrix from homogenous system of linear equations, it is overdetermined, I need to calculate its determinant and it has to square matrix. $\endgroup$
    – Jelena
    Nov 3, 2021 at 17:49

2 Answers 2

2
$\begingroup$

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}

$\endgroup$
1
  • $\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$
    – Jelena
    Nov 3, 2021 at 17:41
0
$\begingroup$

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.

$\endgroup$
3
  • $\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$
    – Jelena
    Nov 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$
    – MikeY
    Nov 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$
    – Jelena
    Nov 9, 2021 at 13:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.