determinants.mw

> with( linalg ):
 

In most linear algebra courses, the algorithm for finding the determinant involves  

computing the solutoin recursively using a cofactor expansion.  The problem with 

this approach is that it has complexity O(n!), which is clearly intractable for any  

nontrivial n. 

 

Using the LU decomposition leads to a polynomial time algorithm.  Essentially, we  

use the following theorem: 

 

Theorem 3.2.1 (Matrix Computations, Golub and Loan) 

Real, nxn matrix A has an LU factorization if det(A(1:k,1:k)) != 0 for k = 1:n-1. 

If an LU factorization exists and A is nonsingular, then the LU factorization is  

unique and det(A)=u_11..u_nn 

 

So essentially we use gaussian elimination to check if the matrix is nonsingular, and  

if its not we can use the results of the elimination, the product of the diagonal entries  

of U, to get the determinant.  

> A := matrix( 3, 3, [3,4,5,1,2,3,3,1,5] );
 

table( [( 2, 3 ) = 3, ( 3, 2 ) = 1, ( 1, 3 ) = 5, ( 1, 2 ) = 4, ( 2, 2 ) = 2, ( 1, 1 ) = 3, ( 3, 1 ) = 3, ( 3, 3 ) = 5, ( 2, 1 ) = 1 ] ) 

> B := LUdecomp( A );
 

table( [( 2, 3 ) = 4/3, ( 3, 2 ) = 0, ( 1, 3 ) = 5, ( 1, 2 ) = 4, ( 2, 2 ) = 2/3, ( 1, 1 ) = 3, ( 3, 1 ) = 0, ( 3, 3 ) = 6, ( 2, 1 ) = 0 ] ) 

> det( A );
 

12 

> B[1,1] * B[2,2] * B[3,3];
 

12 

>