% A=[4 -1 -1;-2 6 1;-1 1 7]
% [3 9 -6]'
% x_0=[0 0 0]'
function Gauss_Seidel_method(A,b,x_0,number_of_digits)
epsilon = 10^(-number_of_digits);
n = size(A);
iter = 0;
while iter < 100
    x_old = x_0;
        for i = 1:n
            sigma = 0;
                for j = 1 : i-1
                    sigma = sigma + A(i,j) * x_0(j);
                end
                for j = i + 1:n
                    sigma = sigma + A(i,j) * x_old(j);
                end
                x_0(i) = (1/A(i,i)) * (b(i)-sigma);
        end
    iter=iter+1
    x_0
    if ~(max(abs(x_old-x))>epsilon)
        fprintf('Počet iterácii je %d\n\n', iter);
        fprintf('Približné riešenie je: %f\n\n')
        for l=1:n
            fprintf('%f\n', round(x(l),number_of_digits))
        end
        break
    end
end
