One numerical measure of a matrix called its determinant. The determinant is one of the most important quantities in matrix algebra. When the determinant of a matrix equals zero, the matrix is singular and has no inverse. The determinant can be used as a test for singularity: this is its most important use.
For a 2 by 2 matrix, the determinant is:
The determinant of an n by n matrix Ann is written as follows:
In order to define the determinant of a matrix of order 3 by 3 or higher, we need to define some additional quantities.
The minor Mij of the matrix A is the n-1 by n-1 matrix formed by removing the ith row and the jth column from matrix A. For example, the minor M12 for the matrix A is:
The cofactor Cij is defined as:
The determinant |A| of an n by n matrix is the calculated as the sum, along any one row or column of A, of array elements multiplied by their corresponding cofactors:
Selecting any row or column will give the same result. Each minor is also a determinant of a square matrix. Each of these can be evaluated recursively using the same procedure. The recursion stops when the dimension reaches 2 x 2 where the simple equation shown above can be used to evaluate the determinant.
type matrix : array[N,N] of real
.
.
%
% Calculate determinate using recursive
% expansion by minors.
%
function det(var a : matrix, n : int) : real
var i, j, j1, j2 : int
var d : real := 0
var m : matrix
assert (n > 1)
if n = 2 then
d := a[1,1]*a[2,2] - a[2,1]*a[1,2]
else
d := 0
for j1 := 1...n do
% create minor
for i := 2...n do
j2 := 1
for j := 1...n do
continue when j = j1
m[i-1,j2] := a[i,j]
incr j2
end for
end for
% calculate determinant
d := d + (-1.0)^(1 + j1)*a[1,j1]*det(m, n-1)
end for
end if
return d
end function