function rv = rank(x,tol)
%rv=rank(x,tol)
%computes the rank of the matrix x (using SVD)

%       S.Halevy 7/31/92
%       Copyright (c) 1992 by the MathWizards

s = svd(x);
if nargin<2
   tol=max(size(x))*s(1)*eps; 
end
rv=sum(s>tol);
