%
% Driver to use ``Expertly extended Locally Optimal Block 
% Preconditioned 4d Conjugate Gradient'' 
% for computing the few smallest positive eigenvalues of 
% a linear response eigenvalue problem.
%
% This driver essentially reproduce the numerical results 
% presented in 
%
%  Zhaojun Bai, Ren-cang Li and Wenwei Lin,  Linear response
%  eigenvalue problem solved by extended locally optimal 
%  preconditioned conjugate gradient methods, Science China 
%  Mathematics Vol.59, pp.1443-1460, 2016.
%  
% Note that the plot on the convergence history is different from
% the one presented in the above paper, but they are the same. 
% Additional data processing is necessary to produce the plot as
% shown in the paper. 
%
% Originally written by Ren-cang Li, and modified by Zhaojun Bai  
%
% Contact: bai@cs.ucdavis.edu
%

clear

load Kna2; load Mna2; load Hna2eig;
n = 1862; 

disp('xeLOBP4dCG: Expertly extended Locally Optimal Block Preconditioned 4d Conjugate Gradient');

nrmKM=[norm(K,1); norm(M,1)]; 

V=[]; nb=4; Nd=10; Ne=3;
tol=1e-8; 
      
Z0=randn(2*n,nb); shift=10.0;

opts.precond_sgm=0.6;  % needed when opts.precond=3
opts.precond=1;
opts.precond_one=2;    % needed when opts.precond=1
opts.precond_two=1;    % needed when opts.precond=2

[lam, Z, res, hsty, info]=...
xeLOBP4dCG(K, M, Z0, V, nrmKM, Nd, shift, tol, Ne, opts);

figure(1);
semilogy(hsty.res,'LineWidth',2); 
xlabel('iteration i');
ylabel('normalize residual')
title('XELOBP4dCG with deflation (m=3)');
%   print -depsc na2xeLOBP4dCG.eps
