title: MatLab algorithm for Jacobi method
body: <p>I have some difficulties in converting a pseudocode into a MatLab algorithm.  Specifically, there is one part I don't quite know how to do.  I will write the pseudocode up to the point where I am uncertain:</p>
  
  <pre><code> input n, (a_{ij}), (b_i), (x_i), M
      for k = 1 to M do
         for i = 1 to n do
  
             u_i = (b_i - sum[(from j = 1, (j ≠ i), to n) a_{ij} * x_j]) / a_{ii}
         end do
  </code></pre>
  
  <p>The difficulty I have is when I have to write the sum-part.  What I can't figure out is how to write the algorithm so that terms where j ≠ i are not included.  So far I have written:</p>
  
  <pre><code>function [k,x] = jacobimethod(A,b,M)
  n = length(A);
  u = zeros(1,n);
  x = zeros(1,n);
  for k = 1:M
      for i = 1:n
          u(i) = (b(i) - (A(i
  </code></pre>
  
  <p>And this is where I get stuck.  So far, all my algorithms have involved sums where all terms should be included, even those where j = i.  In this case, the sum term will simply be:</p>
  
  <pre><code>A(i,1:n)*x(1:n)'
  </code></pre>
  
  <p>But how can I modify this so that <code>A(i,i)</code> is not included?</p>
  
  <p>Any help will be greatly appreciated!</p>