title: Nested for loops are too slow in all situations?
body: <p>I'm coding numeric methos of undergradute course in Matlab and I looked that codes that use a lot of nest for loops are too slowly instead codes with a lot of floating point operations (add, multiply, etc). Does anyone know if exist a paper or study about this fact (nest for loops are slow). I undestand that in most of times this depend of how optimiced is the code but, in genereally is true?. In Google, I couldn't find any paper about this fact.</p>
  <p>I have this code in matlab</p>
  <pre><code>function [L,operaciones]=CholeskyInc(A)
  tic
  [n,m]=size(A);
  operaciones = 0;
  if n~= m; error('A no es cuadrada');
  else
      L=speye(n,n);
      for k=1:n
         L(k,k)=sqrt(A(k,k));
         for i=k+1:n
             if A(i,k)~=0
                 L(i,k)=A(i,k)/A(k,k);
             end
         end
         for j=k+1:n
             for i=j:n
                 if (A(i,j))~=0
                     L(i,j)=A(i,j)-A(i,k)*A(j,k);
                 end
             end
         end
      end
      L = tril(A);
  toc
  end
  </code></pre>
  <p>For large matrix (for example 625x625) this code takes more than 2 minutes in compute the matrix but it's appear to be a simple code</p>