% A2P3
% Checks PosDefFact

% Generate an example with known, logarithmically decreasing eigenvalues...
randn('seed',0)
n = 15;
The_Eigs_Of_A = logspace(1,-14,n)'
[Q,R] = qr(randn(n,n));
A = Q*diag(The_Eigs_Of_A)*Q' ;

disp(' ')
disp('   tol    Est Rank        Residual    ')
disp('-------------------------------------')
for k=2:16
   tol = 1/10^k;
   [G11,G21,P] = PosSemiDefFact(A,tol);
   [r,r] = size(G11);
   Residual = norm(P*A*P'- [G11;G21]*[G11;G21]',1);
   fprintf(' %10.1e      %2d        %10.3e \n',tol,r,Residual)
end
