Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Surprised by "inconsistent" behaviour of Matlab's rank function on small, integer-valued matrices

Tags:

matlab

rank

Today I was quite surprised by this:

>> M = [0, 0, 0;6, 1, 3;1, 7, 0];
>> rank(M)

ans = 

    3

>> rank(M')

ans = 

    2

I'm aware of the fact that the rank function is not necessarily numerically stable since it thresholds the singular values. I was however expecting problems to happen for matrices that are either large in size or large in elements and not a 3 by 3 matrix of small integers.

I checked what happens and in fact svd(M) gives singular values 7.82, 5.93, 2.91e-15, while the default tolerance is only max(size(A))*eps(max(s)) = 2.665e-15. On the other hand, svd(M') gives 0 as third singular values (probably due to a whole column being zero).

Of course I can manually increase the tolerance in calling rank, but how would I know how far to increase it?

Is there another numerically stable method to compute the rank (say that we know that the matrix is integer)?

edit: I just found that this behavior is version-dependent. The above test was carried out with Matlab 2014a. On Matlab 2016b, svd(M) returns the third singular value as 4.15e-16 and rank works properly. So maybe there was indeed an issue with svd that was fixed between version. Still, I'm not sure anymore how far I can trust rank, so I believe my question remains valid.

like image 972
Florian Avatar asked Jan 11 '17 15:01

Florian


1 Answers

Matlab 2015a/2015b seem to work (see below)

>> M = [0, 0, 0;6, 1, 3;1, 7, 0];
>> rank(M)

ans =

     2

>> rank(M')

ans =

     2

>> 
like image 199
zhqiat Avatar answered Oct 22 '22 16:10

zhqiat