function x = SOR(A,b,x0,w,TOL,Nmax)
    n = length(b); x = x0;
    for k = 1:Nmax
        xold = x;
        for i = 1:n
        SUM = 0;
        for j = 1:i-1
            SUM = SUM - A(i,j)*x(j);
        end
        for j = i+1:n  
            SUM = SUM - A(i,j)*x(j);
        end
        x(i) = w*(SUM + b(i))/A(i,i)+(1-w)*xold(i);
        end 
        if max(abs(xold-x))/max(abs(x)) < TOL
            fprintf('Solution found in  %d iterations \n', k)
            break
        end
    end
    if k == Nmax
       fprintf('Maximum number of interations reached, Nmax = %i \n',Nmax)
    end
end
