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

u = u0;
r = b-A*u;
initNorm = norm(r);
invD = diag(1./diag(A));

for k=1:maxIters        
    
    u = u + invD*r;    
    r = b-A*u;    

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

