4

I am new to MATLAB and I have a question which looks pretty obvious but I don't quite understand how to do it.

Let's say I have 100 x 100 matrix and it's rank is 50. How can I reduce its dimensions so it will be 50 x 100? That is, how do I eliminate those rows that don't contribute to its rank?

rayryeng
  • 102,964
  • 22
  • 184
  • 193
Yaeli778
  • 215
  • 3
  • 12
  • Do you want to remove the dependent vectors in your matrix? The rank is the number of linearly independent vectors. – CroCo Jan 19 '15 at 17:41
  • 1
    @CroCo - Yes that is the equivalent operation – rayryeng Jan 19 '15 at 17:43
  • A similar question is here: http://stackoverflow.com/questions/24547255/find-dependent-rows-columns-of-a-matrix-using-matlab But it looks like rayryeng's answer might be the better one. – eigenchris Jan 19 '15 at 17:49
  • I don't think its exactly the same, I was looking to reduce null dimensions when I already know its possible because of the rank, anyway rayryeng answer is great. – Yaeli778 Jan 19 '15 at 17:53
  • @Yaeli778 - A better description of your question would be "How do I eliminate the rows of my matrix that don't contribute to its rank?" – rayryeng Jan 19 '15 at 17:54
  • possible duplicate of [Extracting the largest set of linearly independent vectors from a set of vectors in matlab](http://stackoverflow.com/questions/27907115/extracting-the-largest-set-of-linearly-independent-vectors-from-a-set-of-vectors) – knedlsepp Jan 19 '15 at 23:00
  • 1
    @Yaeli778: I have to add, that the choice of those vectors is not in any way unique. Consider the matrix `A = [1,0; 1,1; 0,1]`. You could choose every combination of two rows and they would suffice your question. In some sense all these rows contribute to the rank, just not at the same time! – knedlsepp Jan 19 '15 at 23:05
  • @knedlsepp - That is very true. I assumed that the OP just wants a valid linearly independent combination, and `rref` will certainly give that. Judging from the context and the question, it doesn't sound like the order matters. Either way, good comment. – rayryeng Jan 20 '15 at 02:28
  • @rayryeng: Oh yeah, the other question definitely ignores the order of the vectors, whereas here it might still be relevant. Didn't actually see that at first. Linking the questions should however give the other perspective *linear independency* of the same problem *contribution to rank*. – knedlsepp Jan 20 '15 at 12:04

1 Answers1

8

You can use rref to determine which columns in your matrix form the column space, and hence which vectors determine the rank of your matrix. Given your matrix that you're examining A, you would call rref like so:

[R,RB] = rref(A);

R would be your matrix decomposed into row-reduced echelon form while RB denotes the column indices that form the basis of your matrix A. Therefore, to seek what you're asking, you would simply do:

Areduced = A(:,RB);

Areduced will be the matrix that only consists of those basis vectors that form the column space of A and hence reduce your matrix A so that it only consists of those columns that allowed your matrix to be full rank.


However, judging from your question, you want to operate along the rows instead of the columns. Therefore, you can transpose your matrix first, use rref on the result, then transpose back when you're finished:

Atranspose = A.';
[R,RB] = rref(Atranspose);
Areduced = Atranspose(:,RB).';
rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • Thanks, its working. I think you just need to change the order: Areduced = R(RB,:); – Yaeli778 Jan 19 '15 at 17:49
  • @Yaeli778 - Oops! The code should have been `Areduced = A(:,RB);` above. However, you said you wanted to operate along the rows, and so what you're doing is not quite correct. See my updated answer. – rayryeng Jan 19 '15 at 17:51