% Code: compLinSlvrs % % This code compares GMRES with Precond GMRES % % It is set up to solve the Sherman 2 problem from Harwell Bowing % collection (available from Matrix Market). The banded % matrix consiting of bands [-10:10] is used as a pre-conditioner. % % Assumes files sherman2.mtx sherman2_rhs1.mtx % % from Matrix Market exist % %------------------- % % D.C. Sorensen % 30 Mar 01 % A = mmread('sherman2.mtx'); b = mmread('sherman2_rhs1.mtx'); h1 = 1; h2 = 2; h3 = 3; % % Construct a preconditioner from the diagonals [-10:10] % d = [-10:10]; B = spdiags(A,d); [n,n] = size(A); M = spdiags(B,d,n,n); figure(h1) clf spy(A) hold disp('Strike Key') pause k = 150; tol = 100*sqrt(eps); [x,r] = Gmres(A,b,k,tol); figure(h2) clf semilogy(r) hold semilogy(r,'*') hold disp('Strike Key') pause figure(h1) clf spy(A) hold spy(M,'r') hold disp('Strike Key') pause dtol = 1e-6; [L,U] = lu(M); %opts = struct('droptol',dtol,'milu',1,'udiag',1); %[L,U] = luinc(A,opts); spy(L,'r') hold spy(U) hold disp('Strike Key') pause k = 150; tol = 100*sqrt(eps); [x,r] = GmresP(A,L,U,b,k,tol); semilogy(r) hold semilogy(r,'*') hold