function [u,k] = GaussSeidel(A,b,u0,prec,maxIters)

u = u0;
n = length(b);
r = b-A*u;
initNorm = norm(r);

D = diag(1./diag(A));
L = tril(A);
U = triu(A);

for k=1:maxIters        

    u = u + (D+L)\r;
    r = b-A*u;
%     for i=1:n
%         u(i) = u(i) + (1/A(i,i))*r(i);
%         r = b-A*u;    
%     end

    if norm(r)/initNorm < prec
        break;
    end
end

