function x = gausseidel(A,b,x0,tol,MAX_ITER)

%%%%%
% This is a Jacobi method to solve Ax = b using the max norm for tolerance
%%%%%

N = length(b);
c = zeros(N,1);
T = zeros(N);
x = zeros(N,1);
strformat = ['%d'];
for i=1:N,
    c(i) = b(i)/A(i,i);
    T(i,:) = -A(i,:)/A(i,i);
    T(i,i) = 0;
    strformat = [strformat,'  %1.4f  '];
end
strformat = [strformat,' \n'];

k = 0;
fprintf('---------------------------------\n');
fprintf('  k              x           \n');
fprintf('---------------------------------\n');
while( k < MAX_ITER )
    fprintf(1,strformat,k,x0);
    xt = x0;
    for j=1:N,
        x(j) = T(j,:)*x0' + c(j);
        x0(j) = x(j);
    end
    test = max(abs(xt-x'));
    x0 = x';
    k = k+1;
    if(test < tol)
        fprintf(1,strformat,k,x0);
        return;
    end    
end



