%% Specify Rank Tolerance
% Calculate the rank of a matrix using a tolerance.
%
% Create a 4-by-4 diagonal matrix. The diagonal has one small value equal to 1e-15.

A = [10 0 0 0; 0 25 0 0; 0 0 34 0; 0 0 0 1e-15]

%
% Calculate the rank of the matrix.

rank(A)

%
% The matrix is not considered to be full rank, since the default algorithm calculates the number of singular values larger than max(size(A))*eps(norm(A)). For this matrix, the small value on the diagonal is excluded since it is smaller than the tolerance.
% Calculate the rank of the matrix again, but specify a tolerance of 1e-16.

rank(A,1e-16)

% Copyright 2012 The MathWorks, Inc.