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