%
% Plot the eigenvalues of A and computed RR values
% ================================================
%
subplot(2,2,1)
if eig_ext == 1,  
   plot(real(aeig),imag(aeig),'b+');
   hold on
   xlabel('real part');
   ylabel('imaginary part');
%   title('Exact Eigenvalues (blue +) and Rayleigh-Ritz values (red o)')
   title('Figure 1')
   fprintf('Figure 1: Exact Eigenvalues (blue +) and RR values (red o)\n')
else 
   xlabel('real part');
   ylabel('imaginary part');
%   title('All Rayleigh-Ritz values (red o)')
   title('Figure 2') 
   fprintf('All Rayleigh-Ritz values (red o)\n')
   hold on
end 
plot(real(ritzvalue(1:szoft)),imag(ritzvalue(1:szoft)),'ro');
hold on
if precond == 1,  
   plot(real(alpha),imag(alpha),'w*') 
elseif precond == 2, 
   plot(real(alpha),imag(alpha),'w*') 
   plot(real(beta),imag(beta),'m*') 
end 
%
% if wone wants to plot the converged Ritz values, uncommon the 
% following line
%
%plot(real(ritz(1:neig)),imag(ritz(1:neig)),'bx');
%
hold off
%
% ----------------------------------------------------------------------
%
% Plot the residuals
% ==================
%
subplot(2,2,2)
semilogy(resr(1:szoft),'b+')
hold on
semilogy(resl(1:szoft),'bx')
%
if (fulldual == 1 | semidual == 1) & neig > 0,
   semilogy(resl_e(1:neig),'rx')
   semilogy(resr_e(1:neig),'r+')
end 
xlabel('Rayleigh Ritz values')
ylabel('residual norm')
%title('Left (+) and Right (x) Residual Norms (exact_red, algo_blue)')
title('Figure 2')
fprintf('Figure 2: Left(+), Right(x) Residual Norms (exact_red, algo_blue)\n')
hold off
%
% ----------------------------------------------------------------------
%
% Plot the accuracy of computed eigenvalues
% =========================================
%
if eig_ext == 1,  
   subplot(2,2,3);
   conveig = 0; 
   for k = 1:szoft,
       err(k) = min( abs(ritzvalue(k)*ones(n,1) - aeig))/abs(ritzvalue(k));
       if err(k) <= tolconv,
          conveig = conveig + 1; 
       end 
   end
%   fprintf('The number of Eigenvalue Accuracy in tolconv = %4i\n', conveig)  
   semilogy(err(1:szoft),'b+')
   hold on; 
%  
   for k = 1:neig, 
       err1(k) = min( abs(ritz(k)*ones(n,1) - aeig))/abs(ritz(k));
   end  
   semilogy(err1(1:neig),'ro')
%   
   xlabel('Rayleigh Ritz values')
   ylabel('Accuracy')
   title('Figure 3')
   fprintf('Figure 3: Eig-accuracy, all Ritz error (b+), converged error(ro)\n')
   hold off 
end 
%
% ----------------------------------------------------------------------
%
% Plot the Estimates of Duality and exact duality or the matrix T_j
% =================================================================
%
if semidual == 1, 
   subplot(2,2,4);
   sz = max( size( omega ) );
   sz = min( sz, max( size( exdual ) ) ) ;
   semilogy( [1:sz],duality(1:sz),'b-.',[1:sz],exdual(1:sz),'r-');
   axis( [ 1 j eps 1 ] );
   xlabel('Lanczos step')
   ylabel('duality')
%   title('Estimated (dash dot) and Exact (solid) Duality, Omega (+)')
   title('Figure 4')
   fprintf('Figure 4: Estimated (b-.) and Exact (r-) Duality, Omega (g+)\n')
   hold on;
   semilogy( abs( omega ), 'g+');
   hold off;
end
