function [x,count]=jacob1(a,b)
% Jacobi method to solve equations iteratively - not vectorized
n=length(a);
% initial guess
x=diag(zeros(n));
error=1;
count=0;
while error > 1.e-6
   for i=1:n
      sum=0;
      for j=1:n
         sum=sum+a(i,j)*x(j);
      end
      err(i)=(b(i)-sum)/a(i,i);
      xn(i)=err(i)+x(i);
   end
   error=norm(err)/norm(xn);
   count=count+1;
   x=xn;
end
