function x = jacobi(A, b, n) D = diag(A); x = b; for k = 1:n x = (b+D.*x-A*x)./D; end