function [x, conv] = mysor(A, b, x0, tol, maxiter, omega)
%MYSOR  Solve A*x = b using SOR iterations 
    [n, ~] = size(A);
    d = diag(A);
    for i = 1:n
        A(i,i) = 0;
    end
    b = b ./ d;
    A = A ./ d;
    conv = [];
    rel = 2*tol;
    x = x0;
    iter = 0;
    while (rel > tol) && (iter < maxiter) 
        for k = 1:n
            x(k) = (1 - omega)*x(k) + omega*(b(k) - A(k,:)*x);
        end 
        rel = norm(x - x0)/norm(x0);
        x0 = x;
        conv = [conv, rel];
        iter = iter + 1;
    end
end
