Example runs using cg, bicg, bicgstab, cgs and qmr on Matrix Market’s sherman5. Also illustrates condest, nnz and spy. Example suitable for Matlab 5.3 or Matlab 7.0.

(1) We first go to the University of Florida Sparse matrix site and find the sherman5 matrix. This is most easily done by using google to search for “UF sparse sherman5” but also can be done by going to http://www.cise.ufl.edu/research/sparse/matrices/list_by_id.html and searching for sherman5.

(2) Next we download the matrix market version of sherman5 by right clicking on “MM” for sherman5 or by right clicking on “download in matrix market format”. Select “save as” and save the sherman5 file to the folder that has loadmatrix and my other routines. You do not need to unzip the file.

(3) Move in Matlab to the folder with loadmatrix and my other routines. Type:

matrixname = ‘sherman5’;

loadmatrix

(4) Run bicg:

max_it = 500 % too small

tol = 1.e-8

[x,error,iter,flag]=bicg(A,x0,b,M,max_it,tol);

flag = 1 % did not converge

% So max_it is too small, reset it

max_it=5000;

tic,[x,error,iter,flag]=bicg(A,x0,b,M,max_it,tol);t_bicg=toc

semilogy(0:iter,error),grid

title('bicg')

xlabel('error')

ylabel('iteration'), shg

% Note: to create plots use edit / copy figure from the Matlab figure window

% and in MS Word use insert / text box and paste.

%To get some information about A:

condest(A)

ans = 3.9023e+005

nnz(A)

ans = 20793

[m, n] = size(A)

ans = 3312 3312

flag = 0 %converged

iter = 1678

t_bicg = 9.2297e-01

(5) Run bicgstab:

tic,[x,error,iter,flag]=bicgstab(A,x0,b,M,max_it,tol);t_bicgstab=toc

semilogy(0:iter,error),grid

title('bicgstab')

xlabel('error')

ylabel('iteration'), shg

iter = 2392

t_bicgstab = 1.5942e+00

(6) Run cgs:

tic,[x,error,iter,flag]=cgs(A,x0,b,M,max_it,tol);t_cgs=toc

semilogy(0:iter,error),grid

title('cgs')

xlabel('error')

ylabel('iteration'), shg

t_cgs = 7.4419e-01

iter = 1241

(7) Run qmr:

tic,[x,error,iter,flag]=qmr(A,x0,b,M,max_it,tol);t_qmr=toc

semilogy(0:iter,error),grid

title('qmr')

xlabel('error')

ylabel('iteration'), shg

t_qmr = 1.7716e+00

iter = 1672

(7) Run gmres:

restrt = max_it

tic,[x,error,iter,flag]=gmres(A,x0,b,M,restrt,max_it,tol);t_gmres=toc

semilogy(0:iter,error),grid

title('gmres')

xlabel('error')

ylabel('iteration'), shg

t_gmres = 2.6265e+01

iter = 913

(7) Run gmres with restart:

restrt = 100;

tic,[x,error,iter,flag]=gmres(A,x0,b,M,restrt,max_it,tol);t_gmres=toc

semilogy(0:iter,error),grid

title('gmres')

xlabel('error')

ylabel('iteration'), shg

t_gmres = 1.6610e+01

iter = 5000 %did not converge