title: Vectorize matrix multiplication
body: <p>I have a school project about running a SOR algorithm on Octave, but mine is very inefficient. So I have this snippet of code:</p>
  
  <pre><code>for ii=1:n
      r = 1/A(ii,ii);
      for jj=1:n
          if (ii!=jj)
              A(ii,jj) = A(ii,jj)*r;
          end;
      end;
      b(ii,1) = b(ii,1)*r;
      x(ii,1) = b(ii,1);
  end;
  </code></pre>
  
  <p>How can I vectorize this? My first attempt was this:</p>
  
  <pre><code>for ii=1:n
      r = 1/A(ii,ii);
      A(find(eye(length(A))!=1)) = A(find(eye(length(A))!=1))*r;
      b(ii,1) = b(ii,1)*r;
      x(ii,1) = b(ii,1);
  end;
  </code></pre>
  
  <p>But I'm not sure it helped much. Is there a better and/or more efficient way to do it? </p>
  
  <p>Thanks!</p>