% cd c:\working@PC\tex\Beijing2009\MATLAB
%
% This is an example of a Deflated CG method for computing the first few smallest 
% eigenvalue of a Hermitian matrix
%
% RCL 6/28/2009

load SiNa
load eigSiNa
A=Problem.A;
[m,n]=size(A);
if m~= n
   disp('A is NOT square');
end

bds=bdeigest(A); nrmA=max(abs(bds(1:2))); tol=1e-6;
U=[]; lambs=[]; infos=[]; ress=[];
for k=1:3,
    x=randn(n,1);
    [lamb, y, res, info]=CG(A, x, k, U, nrmA, tol);
    U=[U y]; lambs=[lambs; lamb]; infos=[infos; info];
    ress=[ress; res];
end

err=(lambs(1:k)-eigA(1:k))./eigA(1:k);
