Java Number Cruncher: The Java Programmer's Guide to Numerical Computing By Ronald Mak
Table of Contents
Chapter 11. Matrix Inversion, Determinants, and Condition Numbers
Once a square matrix A has been decomposed into matrices L and U, the determinant of A is the product of the diagonal elements of U. However, each row exchange that we do for partial pivoting during the decomposition flips the sign of the determinant:
In class LinearSystem of package numbercruncher.matrix (see Listing 10-0 in Chapter 10), variable exchangeCount keeps track of the number of row exchanges, and if this value is odd, we need to negate the value of the product of the diagonal elements of LU .
Using LU decomposition is a much more efficient way to compute a determinant than the traditional way, especially for larger matrices. The traditional way, expansion by cofactors, is actually a recursive algorithm.