title: Jacobi iteration to Gauss-Seidel
body: <p>I have the following function written for the Jacobi method and need to modify it to perform Gauss-Seidel</p>
  
  <pre><code>function [ x,iter] = jacobi( A,b,tol,maxit )
  %jacobi iterations
  %   
  
  x=zeros(size(b));
  
  [n,m]=size(A);
  
  i=1;
  
  iter=maxit;
  
  for i=1:maxit
  
      for j=1:n
  
          y(j)=(b(j)-A(j,1:j-1)*x(1:j-1)-A(j,j+1:n)*x(j+1:n))/A(j,j)
  
      end
  
      if max(abs(A*y'-b))&lt;tol
          iter=i;
          break;
      end
      x=y';
  
  end
  </code></pre>
  
  <p>I know I need to get <code>x(1:j-1)</code> to update but am unsure of how to write it, thanks</p>