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}]]

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:


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.

  • $\begingroup$ Sounds like you may want the NullSpace of the matrix. $\endgroup$
    – Edmund
    Commented Jul 4, 2016 at 20:49
  • 1
    $\begingroup$ 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? $\endgroup$
    – bill s
    Commented Jul 4, 2016 at 20:49
  • $\begingroup$ 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. $\endgroup$
    – mikado
    Commented Jul 4, 2016 at 21:02
  • 3
    $\begingroup$ Just for record,if thoes matrice of 5*3 and 3*7 's rank is not both 3,then your matrix generate by your nice way will not be 3 any more.:) $\endgroup$
    – yode
    Commented Jul 4, 2016 at 22:11
  • 1
    $\begingroup$ @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. :) $\endgroup$
    – yode
    Commented Jul 5, 2016 at 23:17

1 Answer 1


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
  • $\begingroup$ Powerful,Just cannot show the coefficients matix like wiki? $\endgroup$
    – yode
    Commented Jul 4, 2016 at 21:53
  • $\begingroup$ the above mentioned answer is not true. If the first and second column are the same or just their multiplication and the matrix Rank is 2 it returns the first and second columns!!! The Answer has big Flaw!!! $\endgroup$ Commented Aug 8, 2017 at 10:27

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.