Generate a random matrix with a certain rank

I am wondering how you can generate an n ร— n matrix in Matlab with a specific rank (number of rotation columns). I know that you can use the randi(IMAX, m, n) command randi(IMAX, m, n) to generate the mxn matrix with random entries between 1 and IMAX, but is it possible, for example, to create a 4 x 4 matrix with random entries, but only 2 rotation columns? Thanks in advance.

+7
source share
3 answers

I realized that since randi(IMAX, m, n) forms the mxn matrix with as many columns as possible, you can create an nxn A matrix with k rotary columns and random elements between 1 and IMAX with the following code:

 A = randi(IMAX, n, k)*randi(IMAX, k, n) 

Since each of randi(IMAX, n, k) and randi(IMAX, k, n) has only columns with rotary columns k , therefore their product will have only k columns.

+8
source

One (admittedly inefficient) method could be to generate a full matrix (4x4 in your example) and then split it using SVD decomposition and zero some special values โ€‹โ€‹(2 entries in your case). I believe that the reformulated matrix will have the desired rank.

+1
source

Alternatively, if you are interested in managing the singular values โ€‹โ€‹of the generated matrix, you can use the randSVD function from the gallery of test matrices: (link)

+1
source

All Articles