% P2X

% For unit vector v...

% f(mu) = norm( (A + mu*i*I)v ,2)^2
%       = v'( (A + mu*i*I)'(A + mu*i*I) ) v  
%       = v'( (A' - mu*i*I)(A + mu*i*I) ) v
%       = v'( A'A - mu*i*A + mu*i*A' - mu*mu*I ) v
%       = (Av)'(Av) + mu*i*(v'A'v - v'Av) - mu*mu*v'*v
%       = norm(Av,2)^2 - 2*mu*imag(v'Av) + mu^2 
 

% If mu >= norm(A,2) ) then

% f'(mu) =  2*mu        - 2*imag(v'Av)
%        >= 2*norm(A,2) - 2|imag(v'Av)| 
%        >= 2*norm(A,2) - 2*norm(A,2) = 0 (cuz |imag(v'Av)|<=|v'Av'|<=norm(A,2)
%                         
% Now suppose norm(A) <= mu1 < mu2. Suppose v is the right singular vector
% associated with the smallest singular value of A - mu2*i*I. Then
%
%  sig_min(A - mu1*i*I) <= norm((A - mu1*i*I)v) 
%                       <= norm((A - mu2*i*I)v) = sig_min(A - mu2*i*I)

% This shows sig_min(A - mu*i*I) is monotone increasing for mu > norm(A).
% The argument for mu < -norm(A) is similar.

 N = 400;
 n = 20;
 i = sqrt(-1);
 I = eye(n,n);
 A = randn(n,n);
 clc
 for eg = 1:10
     v = randn(n,1); v = v/norm(v); 
    
     M = norm(A);
     mu = linspace(-2*M,2*M,N);
     f = [];
     for k=1:N
         f = [f norm((A+i*mu(k)*I)*v,2)^2 ];
     end
     plot(mu,f,[-M -M],[0 max(abs(f))],'r',[M M],[0 max(abs(f))],'r')
     title('Check f(mu) outside of [-norm(A),norm(A)]')
     xlabel('mu')
     ylabel('f(mu)')
     shg
     pause(1)
 end
     