function [u,k] = BlockJacobi(A,b,u0,prec,maxIters,I1,I2)

u = u0;
r = b-A*u;
initNorm = norm(r);
n1 = length(I1);
n2 = length(I2);
M = [ inv(A(I1,I1)) , zeros(n1,n2) ; zeros(n2,n1) , inv(A(I2,I2)) ];

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

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

