Application: A Formula for the Inverse
Cofactors give an explicit formula for the inverse of any invertible matrix: , where the adjugate is the transposed matrix of cofactors. For it is the familiar "swap, negate, divide" rule; for and it is what game math libraries hard-code; and it explains why integer matrices with determinant have integer inverses.
The adjugate
For an matrix with cofactors (Minors and Cofactors), the cofactor matrix is and the adjugate (classical adjoint) is its transpose:
Theorem. For every square matrix ,
so if ,
Proof. The entry of is .
- If , this is the cofactor expansion of along row , so the diagonal entries equal .
- If , it is the cofactor expansion along row of the matrix obtained from by replacing row with a copy of row (the cofactors do not involve row , so they are the same for and ). has two equal rows, so its determinant is 0.
Hence . The other order follows the same way with column expansions. ∎
The case
For the cofactors are , , , , so
exactly the formula from Matrix Inverses.
A example
from sympy import Matrix
A = Matrix([[2, 3, 1],
[1, 2, 1],
[1, 1, 1]])
C = Matrix(3, 3, lambda i, j: A.cofactor(i, j)) # cofactor matrix
adj = C.T
print("cofactors:", C.tolist())
print("adj(A) :", adj.tolist(), " same as SymPy:", adj == A.adjugate())
print("det A :", A.det())
print("A adj(A) :", (A * adj).tolist())
print("A^-1 :", (adj / A.det()).tolist(), " correct:", adj / A.det() == A.inv())cofactors: [[1, 0, -1], [-2, 1, 1], [1, -1, 1]]
adj(A) : [[1, -2, 1], [0, 1, -1], [-1, 1, 1]] same as SymPy: True
det A : 1
A adj(A) : [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
A^-1 : [[1, -2, 1], [0, 1, -1], [-1, 1, 1]] correct: True
Because , the inverse is the adjugate itself and has integer entries.
Consequences
Integer inverses. If has integer entries, so does (cofactors are sums of products of entries). So has integer entries whenever . Such matrices are called unimodular. Conversely, if and are both integer matrices, with both factors integers, so .
Inverses mod . The formula only divides once, by . So is invertible modulo exactly when has an inverse mod , and then . This is how the Hill cipher key is inverted mod 26 (Application: Cryptography).
Continuity. Each entry of is a polynomial in the entries of divided by , so depends smoothly on as long as stays away from 0, and blows up as .
Cramer's rule, the next lesson, is the same formula applied to a system: .
In software
- Fixed-size inverses in game engines. GLM, DirectXMath, Unity and Unreal invert and matrices with hand-unrolled cofactor formulas: the sub-determinants are computed once and reused, giving a branch-free routine that maps well to SIMD. For general , libraries use LU instead (Matrix Inverse).
- Do you even need it? For rotation-plus-translation matrices, the inverse is cheaper still: transpose the rotation and rotate the negated translation. And for solving systems, prefer
solveover any explicit inverse. - Cost for large : computing cofactors, each an determinant, is even with fast determinants (and factorial with naive expansion), versus for Gauss-Jordan.
import numpy as np
def inv3(m):
# cofactor-based 3x3 inverse, the way small-matrix libraries write it
a, b, c = m[0]; d, e, f = m[1]; g, h, i = m[2]
A, B, C = e * i - f * h, -(d * i - f * g), d * h - e * g # cofactors of row 1
det = a * A + b * B + c * C
adj = np.array([[A, -(b * i - c * h), b * f - c * e],
[B, a * i - c * g, -(a * f - c * d)],
[C, -(a * h - b * g), a * e - b * d]])
return adj / det
M = np.array([[2.0, 0.5, 1.0], [0.0, 1.5, -1.0], [1.0, 2.0, 3.0]])
print(np.allclose(inv3(M), np.linalg.inv(M)), np.allclose(M @ inv3(M), np.eye(3)))True True
Exercises
Exercise 1: by the formula
Find the inverse of using the adjugate.
Answer
.
Solution
Exercise 2: One entry only
For , find only the entry in row 1, column 3 of .
Answer
.
Solution
.
from sympy import Matrix
A = Matrix([[2, 1, 0], [1, 3, 1], [0, 1, 4]])
print(A.inv()[0, 2], A.det())1/18 18
Exercise 3: Integer inverse?
Which of these integer matrices have integer inverses: , , ?
Answer
and do (); does not ().
Solution
, , (triangular). contains halves.
Exercise 4: Prove
For an invertible matrix, derive and check it for the matrix of Exercise 2.
Answer
for that matrix.
Solution
Take determinants of : . Divide by .
from sympy import Matrix
A = Matrix([[2, 1, 0], [1, 3, 1], [0, 1, 4]])
print(A.adjugate().det(), A.det() ** 2)324 324
Test yourself
What is for ?
What is for any square matrix ?
- 0
An integer matrix has . What can you say about ?
- It does not exist
- It has entries that are multiples of
- It equals
- It has integer entries