Matlab has a built-in function for calculating rank of a matrix with decimal numbers as well as finite field numbers. However if I am not wrong they calculate only the lowest rank (least of row rank and column rank). I would like to calculate only the row rank, i.e. find the number of independent rows of a matrix (finite field in my case). Is there a function or way to do this?
-
1There's a function [`gfrank`](http://www.mathworks.com/help/comm/ref/gfrank.html) that seems to do what you require. Why not try it, and if it doesn't solve your problem, post a more specific question? – Dan Becker Nov 20 '12 at 19:21
-
And what's wrong with just [`rank`](http://www.mathworks.com/help/matlab/ref/rank.html)? – Eitan T Nov 20 '12 at 19:22
-
Say a matrix of 2 X 3 elements. If all the columns and rows are independent, I get a rank of 2 i.e. no. of independent columns (I guess rank function returns least of row rank and column rank). I would like to calculate only the row rank! – schwarz Nov 20 '12 at 19:29
2 Answers
In linear algebra the column rank and the row rank are always equal (see proof), so just use rank
(if you're computing the the rank of a matrix over Galois fields, consider using gfrank
instead, like @DanBecker suggested in his comment):
Example:
>> A = [1 2 3; 4 5 6]
A =
1 2 3
4 5 6
>> rank(A)
ans =
2
Perhaps all three columns seem to be linearly independent, but they are dependent:
[1 2; 4 5] \ [3; 6]
ans =
-1
2
meaning that -1 * [1; 4] + 2 * [2; 5] = [3; 6]

- 32,660
- 14
- 72
- 109
-
I think he's working over a finite field, in which case `rank` won't work. I think `gfrank` might work, don't know enough about this field to know for sure. – Dan Becker Nov 20 '12 at 21:34
-
@DanBecker I decided not to include `gfrank` in my answer since it was your suggestion. If you approve it, I'll gladly extend my answer and propose `gfrank` as well. – Eitan T Nov 20 '12 at 21:39
-
The rank function works just fine in Galois fields as well! However, my initial problem remains unsolved from these suggestions. I am working on networks and whenever a new packet arrives, I would like to check if its vector is linearly independent with the previous ones stored in a buffer. So I have to compare all rows. At the present, the only solution I see is that I compare the newest row with each previous row SEPARATELY and see if its independent. I would have liked although to just see if all the rows were independent! But of course you are right that column and row rank are equal! – schwarz Nov 21 '12 at 00:06
-
-
@EitanT - I think I have to rephrase my problem ... How to check if the rows of a matrix are linearly independent? Does the solution I posted above seem legit to you i.e. taking each row and finding its rank with all the other rows one by one? If you would suggest gaussian elimination, then it would be very helpful if you can share an implementation in matlab ... otherwise of course I will try it myself! – schwarz Nov 21 '12 at 12:35
-
1@schwarz Yes, you can either check if the number of rows equals the rank (and if so, they are independent) or check it by solving the equation set like I have shown with the columns in my example. – Eitan T Nov 21 '12 at 13:18
Schwartz,
Two comments:
You state in a comment "The rank function works just fine in Galois fields as well!" I don't think this is correct. Consider the example given on the documentation page for
gfrank
:A = [1 0 1; 2 1 0; 0 1 1]; gfrank(A,3) % gives answer 2 rank(A) % gives answer 3
But it is possible I am misunderstanding things!
You also said "How to check if the rows of a matrix are linearly independent? Does the solution I posted above seem legit to you i.e. taking each row and finding its rank with all the other rows one by one?"
I don't know why you say "find its rank with all the other rows one by one". It is possible to have a set of vectors which are pairwise linearly independent, yet linearly dependent taken as a group. Just consider the vectors
[0 1]
,[1 0]
,[1 1]
. No vector is a multiple of any other, yet the set is not linearly independent.Your problem appears to be that you have a set of vector that you know are linearly independent. You add a vector to that set, and want to know whether the new set is still linearly independent. As @EitanT said, all you need to do is combine the (row) vectors into a matrix and check whether its
rank
(orgfrank
) is equal to the number of rows. No need to do anything "one-by-one".Since you know that the "old" set is linearly independent, perhaps there is a nice fast algorithm to check whether the new vector makes thing linearly dependent. Maybe at each step you orthogonalize the set, and perhaps that would make the process of checking for linear independence given the new vector faster. That might make an interesting question somewhere like mathoverflow.

- 1,196
- 10
- 18