% A=[4 -1 -1;-2 6 1;-1 1 7]
% b=[3 9 -6]'
% x_0=[0 0 0]'
function Jacobi_method(A,b,x_0,number_of_digits)
epsilon = 10^(-number_of_digits);
n = size(A);
iter = 0;
x=x_0;
while iter < 100
    x_old = x;
        for i = 1:n
            sigma = 0;
                for j = 1:n
                        if j ~= i
                            sigma = sigma + A(i,j) * x_old(j);
                        end
                end
                x(i) = (1/A(i,i)) * (b(i)-sigma);
        end
    iter=iter+1
    x
    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
