A very useful function from square matrices to scalars is the determinant. Its definition is not usually relevant to computation, being defined in terms of a sum of products:
where the sum is taken over all permutations of and the sign of the permutation is 0 if it is a product of 3-cycles and 1 otherwise. However, one can see from the definition that the determinant of an integer matrix is an integer, which is a useful fact.
Determinants can be calculated by expansion by minors, also called the method of Laplace or Laplace expansion, or by Gaussian elimination, which is much cheaper in fixed-precision arithmetic. To expand a determinant by minors, choose a row or column of the (n by n) matrix, say for example the row . Then for each entry in the row, form the n-1 by n-1 matrix that you get by deleting the row and column of the entry. Compute these n smaller order determinants, and call the determinant corresponding to by the name (if the matrix is 1 by 1, the determinant is just the entry). Then we compute the final determinant as
This recursive procedure is most useful when most of the are zero, whence we do not actually need to form or compute the order n-1 determinants.
Determinants are useful because the linear equations Ax = b have a unique solution precisely when . We will see that this is not the whole story when data errors or uncertainty enter the picture.
det(A, sparse)will find the determinant of A by expansion by minors, which is the classical method taught in high school. This method is appropriate if A is sparse. Experiment with dense matrices and the
time()command to see if
det(A,sparse)is faster, and by how much.