function x=jacobi(A,b,x0,e) [k,l]=size(A) for i=1:k B(i,:)=A(i,:)/(-A(i,i)) B(i,i)=0 c(i)=b(i)/A(i,i) endfor c=c' q=norm(B,inf) if q<1 & k==l z=0 x=B*x0+c while q/(1-q)*norm(x-x0,inf)>0 z=z+1 x0=x x=B*x0+c endwhile else disp('A is not diagonally dominant or not square matrix') endif x=x0