 function  bds=bdeigest(A)
%
% A primitive and fast way to bound from below the smallest eigenvalue
% of a Hermitian A and from above the largest eigenvalue.
%
% Reference:
%
%    Ren-Cang Li and Yunkai Zhou,
%    Bounding the Spectrum of Large Hermitian Matrices, 2009
%    submitted.
%
%  Input:
%
%      A      (n-by-n) Hermitian
%
%  Output:
%
%      bds    4-by-1  bds(1) = lower bound of the smallest eigenvalue
%             bds(2) = upper bound of the largest eigenvalue
%             bds(3) = lower bound of the smallest eigenvalue (less sharp)
%             bds(4) = upper bound of the largest eigenvalue (less sharp)
%
%                                RCL 06/28/09
 [m,n]=size(A);
 if m ~= n,
    disp('bdeigest: the input matrix is not square');
    return
 end
 
 v0=randn(n,1); k=8;
 [V, T]=symlanz(A, v0, k);

 [Q,D]=eig(T(1:k,1:k)); D=diag(D);
 [dmin,imin]=min(D); [dmax,imax]=max(D);
 
 bds=zeros(2,1);
 u=V(:,1:k)*Q(:,imin);
 bds(1)=dmin-abs( Q(k,imin)*T(k+1,k)/norm(u) );
 bds(3)=dmin-abs(T(k+1,k)/norm(u));
 
 u=V(:,1:k)*Q(:,imax);
 bds(2)=dmax+abs( Q(k,imax)*T(k+1,k)/norm(u) );
 bds(4)=dmax+abs(T(k+1,k)/norm(u));
 
