Is the rank function reliable?
Show older comments
In doing econometrics i need to check if a spicy numerically determined matrix has full rank.
Is it reliable to just evaluate rank or should one do tricks as rank(A)=rank(A'A) so that one can evaluate det(A'A) and see if it is close to zero. If so, when is the determinant so close to zero that one would consider it to not have full rank?
Thanks!
p.s. I'm new to this forum, sorry if you broke some rules and I really don't know which tag to apply.
Accepted Answer
More Answers (1)
Regardless of what you decide about rank as a measure of singularity, I prefer not to use Matlab's RANK command to compute it, or at least not with the default tolerance on the singularity. It has a very funny way of choosing this default,
s = svd(A);
if nargin==1
tol = max(size(A)) * eps(max(s));
end
r = sum(s > tol);
Why the tolerance should be set relative to size(A) has always eluded me.
I use the function below which is somewhat similar to using cond() as John suggested. In addition to estimating rank, it can also pick out the linearly independent columns of the matrix and their locations for you, as additional output arguments.
function [r,idx,Xsub]=lindep(X,tol)
%Extract a linearly independent set of columns of a given matrix X
%
% [r,idx,Xsub]=lindep(X)
%
%in:
%
% X: The given input matrix
% tol: A rank estimation tolerance. Default=1e-10
%
%out:
%
% r: rank estimate
% idx: Indices (into X) of linearly independent columns
% Xsub: Extracted linearly independent columns of X
if ~nnz(X) %X has no non-zeros and hence no independent columns
r=0; Xsub=[]; idx=[];
return
end
if nargin<2, tol=1e-10; end
[Q, R, E] = qr(X,0);
diagr = abs(diag(R));
%Rank estimation
r = find(diagr >= tol*diagr(1), 1, 'last'); %rank estimation
if nargout>1
idx=sort(E(1:r));
idx=idx(:);
end
if nargout>2
Xsub=X(:,idx);
end
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!