function [x, iter]=myjacobi(a,xexact,x0,tol)

    b=a*xexact;
    
    n=length(x0);
    u0=x0;
    x=x0;
    
    iter = 0;
    error=1;
   
    while error > tol
        for i=1:n
            x(i) = a(i,1:i-1)*x0(1:i-1)+a(i,i+1:n)*x0(i+1:n);
            x(i)=(b(i)-x(i))/a(i,i);
        end
        error=norm(x-xexact)/norm(u0-xexact);
        x0=x;
        iter = iter + 1;
     end
end