function RankRevelation()
% Shows how QR with column pivoting and the SVD can be used to
% shed light on the rank of a matrix.

% A = Random Matrix with geometrically decaying singular values...
m = 500;
n = 100;
kappa = 10^12;
mode = 3;
A = gallery('randsvd', [m,n],kappa,3);
b = randn(m,1);
s3 = svd(A);
semilogy(s3)
shg
clc
disp(' tol rank via QRP rank via SVD ')
disp('--------------------------------------------------------------')
for d=1:11
tol = 10^(-d);
% The two solvers...
[xB,rhoxB,rQR] = LSviaQRP(A,b,tol);
[xLS,rhoxLS,rSVD] = LSviaSVD(A,b,tol);
fprintf('%20.12f %3d %3d\n',tol,rQR,rSVD)
end