% function [x,j] = gs(A,b,x0,maxiter,tol)
%
%     Gauss-Seidel method for solving linear systems iteratively
%
% inputs
%	A       system matrix
%	b       system right hand side
%	x0      initial guess
%	maxiter max number of iterations
%       tol     tolerance between  two consecutive iterates (in l_inf norm)
%
% outputs
%	x	current solution
%	j       iteration number
function [x,j] = gs(A,b,x0,maxiter,tol)
n = size(A,1); x = zeros(size(x0));
for j=1:maxiter
 % print only first few iterates

 % Gauss-Seidel update

 % check for convergence
 if norm(x-x0,'inf')/norm(x0,'inf')<tol return; end;
end;
fprintf('Maximum number of iterations reached and tolerance not met\n');
