2

I found a nice way to generate a random $5\times 7$ matrix with rank 3.

MatrixForm[A = RandomInteger[5, {5, 3}].RandomInteger[5, {3, 7}]]
MatrixRank[A]

Let me store an example output, because each time we use RandomInteger, the matrix changes. So, we'll work with this one, an output from the strategy above.

A = {{18, 29, 20, 17, 37, 22, 38}, {12, 16, 10, 4, 14, 14, 16}, {6, 
   16, 12, 17, 28, 9, 27}, {10, 11, 9, 6, 18, 10, 17}, {14, 20, 17, 
   18, 39, 15, 36}}

If we use:

MatrixForm[RowReduce[A]]

Then we can identify the pivot columns. Then we can select the pivot columns and store them in matC.

MatrixForm[matC = A[[All, 1 ;; 3]]]

I am just wondering if there is a cute Mathematica command I haven't encountered that will automatically select the independent columns or the independent rows of a matrix.

David
  • 14,883
  • 4
  • 44
  • 117
  • Sounds like you may want the NullSpace of the matrix. – Edmund Jul 04 '16 at 20:49
  • 1
    I don't think you're question makes all that much sense. Consider a matrix a={{1,0,0},{0,1,0},{1,1,0}, of rank 2. The first two columns are independent. But so are the first and third and so are the second and third. Which if these would you pick? – bill s Jul 04 '16 at 20:49
  • You might find "Interpolative Decomposition" worth investigating. There are some results (that I found surprising) relating to factorising a matrix using a selection of its independent columns or rows. – mikado Jul 04 '16 at 21:02
  • 3
    Just for record,if thoes matrice of 53 and 37 's rank is not both 3,then your matrix generate by your nice way will not be 3 any more.:) – yode Jul 04 '16 at 22:11
  • @yode Nice information. Thanks. Counterexample using Mathematica? – David Jul 05 '16 at 22:55
  • 1
    @David Just try this pair={SeedRandom[#];A=RandomInteger[5,{5,3}].RandomInteger[5,{3,7}];MatrixRank[A],#}&/@Range[10000]; Select[pair,First[#]!=3&],I mean you have a probability of 0.08% to get a matrix whose rank is not 3 by your method. :) – yode Jul 05 '16 at 23:17
  • Is this a duplicate of https://mathematica.stackexchange.com/q/34142/12 ? – Szabolcs Aug 08 '17 at 10:44

1 Answers1

6

I believe that the following code selects the columns of the matrix that provides an approximate "Interpolative Decomposition". This means that all the other columns can be written as linear combinations of the selected columns with minimal coefficients. There are some interesting results (I believe) on how small these coefficients need be (never greater that 2 if I recall correctly).

{q, r, p} = QRDecomposition[N[A], Pivoting -> True];
id = A.p[[All, 1 ;; MatrixRank[A]]]

Pivoting only seems to take effect for inexact arithmetic.

If you want the coefficient matrix, this can be computed using

coeff = LinearSolve[id,A]

so that

id.coeff == A // FullSimplify
mikado
  • 16,741
  • 2
  • 20
  • 54