Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So to calculate the determinant of a NxN matrix, you need to strike out the first row, then strike out columns one by one, and calculate determinants of the resulting bunch of (N-1)x(N-1) matrices. And to calculate those determinants, you need to strike the first row of the smaller matrices (which would be the <em>second</em> row of the original matrix) and then strike out additional columns one by one, and so on. </p> <p>So it's easy to figure out what to do with the rows at each recursion level: at level 0 you go through row 0, at level 1 you go through level 1 and so on.</p> <p>But columns are more involved. If at level 0 you strike out row 7, and at level 1 you strike out row 12 of the <em>current</em> matrix (which would be row 13 of the <em>original</em> matrix) and at level 2 you strike out row 10 of the <em>current</em> matrix, which is also row 10 of the matrix <em>one level up</em>, which is row 11 of the matrix <em>two levels up</em>, which is the original matrix... it would be pretty hard to determine which column of the original matrix to access at the lower levels of recursion.</p> <p>It is possible of course to copy the entire matrix, sans the column that should be striken out, and pass the copy down the recursion level. But that would be rather wasteful.</p> <p>It is more elegant to strike out column <em>numbers</em> instead of columns themselves. To achieve that, we create an one-dimensional array of column numbers. Initially it should contain numbers 0..(N-1) in order. As you prepare to compute each submatrix determinant, you copy that array, remove one column index from the copy, and pass it down the recursive computation.</p> <p>So your recursive function would look approximately like this (in pseudocode)</p> <pre><code>float recursive_determinant (int N, float[N][N] matrix, int[N] column_array, int level) if level == N-1 return matrix[level][column_array[0]] result = 0 for each i in 0 .. N - level copy_of_column_array = column_array copy_of_column_array.remove_element(i) subdeterminant = recursive_determinant (N, matrix, copy_of_column_array, level+1) result = result + subdeterminant * matrix[level][column_array[i]] * (-1)^(i+1) return result float determinant (int N, float[N][N] matrix) result = recursive_determinant (N, matrix, {0, 1, ..., N-1}, 0) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload