Cramer's rule and adjugate matrices #
The adjugate matrix is the transpose of the cofactor matrix.
It is calculated with Cramer's rule, which we introduce first.
The vectors returned by Cramer's rule are given by the linear map cramer
,
which sends a matrix A
and vector b
to the vector consisting of the
determinant of replacing the i
th column of A
with b
at index i
(written as (A.update_column i b).det
).
Using Cramer's rule, we can compute for each matrix A
the matrix adjugate A
.
The entries of the adjugate are the determinants of each minor of A
.
Instead of defining a minor to be A
with row i
and column j
deleted, we
replace the i
th row of A
with the j
th basis vector; this has the same
determinant as the minor but more importantly equals Cramer's rule applied
to A
and the j
th basis vector, simplifying the subsequent proofs.
We prove the adjugate behaves like det A • A⁻¹
.
Main definitions #
matrix.cramer A b
: the vector output by Cramer's rule onA
andb
.matrix.adjugate A
: the adjugate (or classical adjoint) of the matrixA
.
References #
- https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix
Tags #
cramer, cramer's rule, adjugate
cramer
section #
Introduce the linear map cramer
with values defined by cramer_map
.
After defining cramer_map
and showing it is linear,
we will restrict our proofs to using cramer
.
cramer_map A b i
is the determinant of the matrix A
with column i
replaced with b
,
and thus cramer_map A b
is the vector output by Cramer's rule on A
and b
.
If A ⬝ x = b
has a unique solution in x
, cramer_map A
sends the vector b
to A.det • x
.
Otherwise, the outcome of cramer_map
is well-defined but not necessarily useful.
Equations
- A.cramer_map b i = (A.update_column i b).det
cramer A b i
is the determinant of the matrix A
with column i
replaced with b
,
and thus cramer A b
is the vector output by Cramer's rule on A
and b
.
If A ⬝ x = b
has a unique solution in x
, cramer A
sends the vector b
to A.det • x
.
Otherwise, the outcome of cramer
is well-defined but not necessarily useful.
Equations
- A.cramer = is_linear_map.mk' A.cramer_map _
Use linearity of cramer
and vector evaluation to take cramer A _ i
out of a summation.
adjugate
section #
Define the adjugate
matrix and a few equations.
These will hold for any matrix over a commutative ring.
The adjugate matrix is the transpose of the cofactor matrix.
Typically, the cofactor matrix is defined by taking the determinant of minors,
i.e. the matrix with a row and column removed.
However, the proof of mul_adjugate
becomes a lot easier if we define the
minor as replacing a column with a basis vector, since it allows us to use
facts about the cramer
map.
Since the map b ↦ cramer A b
is linear in b
, it must be multiplication by some matrix. This
matrix is A.adjugate
.
A stronger form of Cramer's rule that allows us to solve some instances of A ⬝ x = b
even
if the determinant is not a unit. A sufficient (but still not necessary) condition is that A.det
divides b
.
Note that this is not true for fintype.card n = 1
since 1 - 2 = 0
and not -1
.
A weaker version of matrix.adjugate_adjugate
that uses nontrivial
.