2

Im looking to create a matrix of rank k. The dimension of the matrix is m x n. The input k satisfies that condition that k < min(m,n).

m2016b
  • 534
  • 5
  • 19
Learner
  • 962
  • 4
  • 15
  • 30

3 Answers3

4

It's not really so clear what you are aiming for.

But in order to create a matrix B with specific rank k, from a matrix A (with rank at least k), you may like to utilize svd and proceed like:

>>> A= rand(7, 5);
>>> rank(A)
ans =  5
>>> [U, S, V]= svd(A);
>>> k= 3;
>>> B= U(:, 1: k)* S(1: k, 1: k)* V(:, 1: k)';
>>> rank(B)
ans =  3
eat
  • 7,440
  • 1
  • 19
  • 27
3

Well, a trivial method is to produce a matrix that looks like:

1 0 0 0 0
0 1 0 0 0
0 0 1 1 1
0 0 0 0 0

i.e. k columns of the identity matrix, then repeat the last column n-k times (or m-k times, depending on orientation).

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
1

A matrix of rank 1 can be created by the outer product of two vectors, for example:

A = randn(10,1) * randn(1,10);

Add together k of these and you will have a matrix of rank k. Like this:

>> A = zeros(10);
>> for i = 1:4, A = A + randn(10,1) * randn(1,10); end
>> rank(A)

ans =  4
  • 2
    to be precise, your method produces a matrix of rank <= k. It might be the case where two random vectors would be linearly dependent (not very likely, but possible, especially if k is close to m or n) – Shai Dec 16 '12 at 16:22
  • 2
    while you're at it, it can be done without the loop `A = rand(m, k)*rand(k,n); rank(A)` – Shai Dec 16 '12 at 17:05