  function P3()
 %Checks out ConstrainedMinEig
  clc
  
  for id = [17 18 22]
     randn('seed',0)
     Problem = UFget(id);
     A = Problem.A;
     [n,n] = size(A); v = randn(n,1); v = v/norm(v);
     muCVL = ConstrainedMinEigCVL(A,v);
     muYou = ConstrainedMinEig(A,v);
     %mu1 = DenseVersion(A,v)
     fprintf('\n\nUFid = %3d, n = %3d\n     muCVL = %15.10f\n     muYou = %15.10f\n',id,n,muCVL,muYou) 
  end
  

  function mu = ConstrainedMinEigCVL(A,v)
% A is an n-by-n symmetric matrix in sparse format
% v is a column n-vector with unit 2-norm
% mu is the minimum value of f(x) = x'*A*x / x'*x subject to the constraint
% that v'*x = 0.

% Compute unit vector z so that if Q = I- 2z*z' then Pv is a multiple
% of I(:,1)
z = v;
if v(1)>0
    z(1) = z(1) + norm(v);
else
    z(1) = z(1) - norm(v);
end
z = z/norm(z);

% Call eigs...
OPTS.issym = 1; 
OPTs.isreal = 1;
nm1 = length(z)-1;
mu = eigs(@(x) MyProd(x,A,z),nm1,1,'SA',OPTS);
  
  

  function y = MyProd(x,A,z)
% x is a column (n-1)-vector
% A is an n-by-n symmetric matrix in sparse format.
% z is column n-vector
% y = A1*x where A1 = Atilde(2:n,2:n) with 
%            Atilde = (I - 2zz')*A*(I - 2zz')

% Note that if xtilde = [0;x] is a column n-vector and 
% ytilde = Atilde*xtilde, then y = ytilde(2:n).
  
  n = length(z);
  xtilde = [0;x];
  ytilde = xtilde - 2*(z'*xtilde)*z;
  ytilde = A*ytilde;
  ytilde = ytilde - 2*(z'*ytilde)*z;
  y = ytilde(2:n);
  


          
       