# Cofactor matrix

This tool is a cofactor matrix calculator.

## Cofactor matrix

The cofactor matrix of a square matrix M of size n, also called comatrix and noted com(M), is a square matrix of size n defined as follows :

We note c(i, j) the element in row i and column j of the comatrix. Then,

c(i,j) = (-1)^(i+j) det( M(i,j) ), where
'det' represents the determinant.
M(i,j) is the square submatrix of size n - 1 obtained from M by deleting the row i and the column j. The determinant of M(i,j) is called 'Minor' of matrix M.

c (i, j) is called cofactor of index i, j.

Example of calculating a 2 x 2 comatrix :

M = [[1,2],[-3,6]]

We calculate the cofactors as explained above,

c(1,1) = (-1)^(1+1) det( (6) ) = 6

c(1,2) = (-1)^(1+2) det( (-3) ) = 3

c(2,1) = (-1)^(2+1) det( (2) ) = -2

c(2,2) = (-1)^(2+2) det( (1) ) = 1

Therefore,

\text{com(M)} = [[6,3],[-2,1]]

Example of calculation of a 3x3 comatrix :

M = [[1,5,4],[-2,7,-2],[9,8,0]]

By applying the cofactors formula of cofactors, we get,

c(1,1) = (-1)^(1+1) det([[7,-2],[8,0]]) = 16

c(1,2) = (-1)^(1+2) det([[-2,-2],[9,0]]) = -18

c(1,3) = (-1)^(1+3) det([[-2,9],[7,8]]) = -79

c(2,1) = (-1)^(2+1) det([[5,4],[8,0]]) = 32

c(2,2) = (-1)^(2+2) det([[1,4],[9,0]]) = -36

c(2,3) = (-1)^(2+3) det([[1,5],[9,8]]) = 37

c(3,1) = (-1)^(3+1) det([[5,4],[7,-2]]) = -38

c(3,2) = (-1)^(3+2) det([[1,4],[-2,-2]]) = -6

c(3,3) = (-1)^(3+3) det([[1,5],[-2,7]]) = 17

Then we have,

\text{com(M)} = [[16,-18,-79],[32,-36,37],[-38,-6,17]]