Generate some random matrix with given rank

2.8k Views Asked by At

Very often for creating new exercises (I teach basic matrix algebra), I need to a find a matrix $A$ such that:

  • it has integer coefficients, not too big (in order to avoid big numbers computations)

  • it has a given format (ex : (3,4) ), has a given rank (ex : 2)

  • the computations in order to perform a row echelon form are not too complicated...

Do you know how I can easily generate such matrix (online tool?)

Of course I could do a Maple or Python program to do that, but I wanted to know if such a ready-to-use tool already exists.

1

There are 1 best solutions below

5
On

Parts $1$ and $2$ are very easy:

If you want an $m \times n$ rank $r$ matrix, then compute $UPV$ where

  • $U$ is $m \times m$ invertible

  • $V$ is $n \times n$ invertible and

  • $P$ the $m \times n$ matrix that looks like $$P = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{pmatrix}$$ with $r$ ones.

If you generate $U$ and $V$ at random, they are highly likely to be invertible.

Part 3 is a bit tricky, because what makes echelon computations hard is a bit subjective. I would start with the matrix in row echelon form and apply a small number of random row operations.