function [x,  conv]=myjacobi(A, b, tol, maxit)
% MYJACOBI - solve Ax=b using Jacobi iterations
%            use c as the initial approximation for x.

%            Educational version - returns the solution 
%            and the convergence information.
    [n, ~] = size(A);
    T = A;
    d = diag(A);
    for i = 1:n
         T(i,i) = 0;
    end
    c = b ./ d;
    T = T ./ d;
    x = c;
    r = A*x - b;
    delta = r'*r;
    conv = delta;
    delta0 = delta;
    iter = 0;
    while (iter < maxit) && (delta > delta0*tol)
        x = c - T*x;
        r = A*x - b;
        delta = r'*r;
        conv = [conv delta];
        iter = iter + 1;
    end
end
