title: Laplace expansion for determinants with Octave
body: <p>I'm trying to calculate the determinant of a matrix using <a href="http://en.wikipedia.org/wiki/Laplace_expansion" rel="nofollow">Laplace expansion</a> in Octave. I use two functions:</p>
  
  <ul>
  <li><p><code>submatrix</code>, gets <a href="http://en.wikipedia.org/wiki/Minor_(linear_algebra)" rel="nofollow">submatrix</a> given matrix and indices:</p>
  
  <pre><code>function A = submatrix(A, i, j)
     A(i,:) = [];
     A(:,j) = [];
  endfunction
  </code></pre></li>
  <li><p><code>determinant</code>, for recursively calculating the determinant:</p>
  
  <pre><code>function d = determinant(A) 
      [m,n] = size(A);
  
      if m == 2
          # Base case are 2x2 matrices
          d = A(1,1)*A(2,2) - A(1,2)*A(2,1);
      else
          d = 0;
          for j = 1:n
              d = d + (-1).^(1+j)*determinant(submatrix(A,1,j));
          endfor
      endif
  endfunction
  </code></pre></li>
  </ul>
  
  <p>The function works correctly with 3 by 3 matrices, yet it always returns 0 (or -0) for bigger matrices (4 by 4 and bigger).</p>
  
  <p><strong>Question:</strong> Why does <code>determinant</code> returns 0 for matrices bigger than 3 by 3?</p>