This part of the discussion considers only square matrices, that is, the linear transformation corresponding to matrix maps vectors to vectors.
Since practical problems often require repeated transformations, merely saying that the linear transformation corresponding to matrix transforms the identity matrix into is too abstract. The best approach is to look for fixed points, that is, parts of the transformation that remain unchanged.
However, the linear transformation corresponding to matrix may have no fixed points at all. We therefore look instead for collinear parts or parts resembling a simple transformation.
Eigenvalues and Eigenvectors
Under the linear transformation corresponding to matrix , the directions of some vectors do not change; only their magnitudes are scaled.
Let be a vector space over , and let be a linear transformation on . If there exist an element of , denoted by , and a nonzero vector in , denoted by , such that:
then is called an eigenvalue of , and is called an eigenvector of belonging to the eigenvalue .
Eigenvectors on the same line retain their direction under a linear transformation (compressing them to zero is also regarded as preserving direction). An eigenvector is not unique: every vector collinear with an eigenvector is also an eigenvector, but the zero vector is not an eigenvector by definition, since a vector with a direction is necessarily nonzero. The eigenvalue of an eigenvector is the factor by which it is scaled.
In applications, for eigenvectors with the same eigenvalue, one usually chooses a basis as a representative of the whole set.
Let be a basis of , and let the matrix of in this basis be , that is:
Let be an eigenvalue of , let be an eigenvector of belonging to the eigenvalue , and let a nonzero vector satisfy:
Then:
Therefore, the corresponding determinant is also .
Characteristic Polynomial
Consider an matrix , where . Let be a parameter. The matrix is called the characteristic matrix of .
The determinant of the characteristic matrix is called the characteristic polynomial of . It is an -th degree polynomial whose roots are the eigenvalues of , and is denoted by :
Here is an identity matrix. Some sources define it as , which differs from our definition only by the sign . With our definition, is always monic, whereas the other definition is monic only when is even. Note that the determinant of a matrix is well-defined as .
The nonzero solution vector of , denoted by , is called an eigenvector of belonging to .
The linear transformation has eigenvalue if and only if matrix has eigenvalue .
The linear transformation has eigenvector if and only if matrix has eigenvector , where:
By the fundamental theorem of algebra, the characteristic polynomial can be factored as:
The are called the algebraic multiplicity of the eigenvalue . The sum of all algebraic multiplicities is the dimension of the space.
Finding All Eigenvalues and Eigenvectors of a Matrix
The process consists of the following steps:
- Compute the determinant .
- Find all roots of the polynomial in the field ; these are the eigenvalues of .
- For each eigenvalue of , denoted by , solve the homogeneous linear system and find a fundamental solution system . Then all eigenvectors of belonging to are:
The in this expression are not all zero.
- The eigenvectors of the linear transformation belonging to are:
Therefore, all eigenvectors belonging to are:
The in this expression are not all zero.
Whether eigenvalues and eigenvectors exist depends on the field containing .
Similarity Transformation
Introduction
If an matrix is an upper-triangular matrix of the form
then
The characteristic polynomial of a lower-triangular matrix can be obtained similarly. If is neither of these two types, a similarity transformation is needed to put the matrix into a form whose characteristic polynomial is easier to compute.
Definition
For matrices and , if there exists an invertible matrix satisfying
then matrices and are similar, and the transformation is called a similarity transformation. The matrices and have the same characteristic polynomial.
Consider
This proves the claim; the case of is the same. Also, , because , so .
Theorem: Similar matrices have the same characteristic polynomial and eigenvalues, but the converse is not true.
The theorem shows that the characteristic polynomial of the matrix of a linear transformation is independent of the choice of basis and is determined directly by the linear transformation. It can therefore be called the characteristic polynomial of the linear transformation.
The characteristic polynomial of matrix , namely , is a monic polynomial. By Vieta's formulas, its coefficient of degree is:
Here is called the trace of and is the sum of the entries on the main diagonal of .
By Vieta's formulas, the constant term of the characteristic polynomial is:
Theorem: Similar matrices have the same trace.
Sylvester's Determinant Identity
Theorem: Whether or not matrices and are square, as long as their product is defined, the trace of equals the trace of .
One proof is by direct expansion. Another proof uses Sylvester's determinant identity.
Theorem: Let be an -by- matrix and an -by- matrix. Then:
This formula shows that and have the same nonzero eigenvalues.
Schur's Lemma
Every -th order matrix is similar to an upper-triangular matrix. In other words, there exists a full-rank matrix such that is upper triangular, with all eigenvalues of on its main diagonal.
Corollary: Let have eigenvalues , and let be any polynomial. Then the matrix polynomial has the eigenvalues:
In particular, the eigenvalues of are , and those of are .
Similarity Transformations Using Gaussian Elimination
Gaussian elimination can be performed on an matrix using elementary row operations.
After applying the above operations to a matrix (left-multiplying by elementary matrices), right-multiplying by the inverse elementary matrix gives a similarity transformation. The left multiplication is a row operation, and the right multiplication is correspondingly a column operation.
If a matrix can be transformed into upper- or lower-triangular form by similarity transformations, its characteristic polynomial can be obtained easily. However, applying to an element on the main diagonal may cause the following operation to restore a previously eliminated zero: first apply to eliminate the element in row , column , then right-multiply by , which adds the -column indexed by multiplied by to column . Thus the matrix may fail to become upper or lower triangular.
The following section shows that applying transformations to elements on the subdiagonal still produces a matrix whose characteristic polynomial can be computed easily.
Upper Hessenberg Matrix
For , a matrix of the form
is called an upper Hessenberg matrix, where is the subdiagonal.
We can obtain an upper Hessenberg matrix by using similarity transformations to eliminate all elements below the subdiagonal. The characteristic polynomial of an upper Hessenberg matrix can then be computed in time.
Let be the matrix obtained from by retaining only its first rows and first columns, and let . Then
When computing a determinant, we usually expand along a row or column with as many zeros as possible. The corresponding minor is the matrix obtained by deleting the row and column containing the selected element. Here we expand along the last row:
Observing the pattern and generalizing, for we have
This completes the algorithm, which is generally called the Hessenberg algorithm.
Cayley–Hamilton Theorem
For any -th order matrix with characteristic polynomial , we have .
There is a corresponding result for a linear transformation : if is the characteristic polynomial of , then is the zero transformation.
This theorem implies that every matrix has a polynomial that annihilates it.
Minimal Polynomial
Let be an -dimensional vector space. Since the matrix corresponding to a linear transformation has entries, all linear transformations form an -dimensional vector space.
For a particular linear transformation , the transformations obtained by applying it from through times give linear transformations in total, and their corresponding matrices must be linearly dependent. Therefore, there is a nonzero polynomial such that is the zero transformation; we say that transformation satisfies polynomial . Among all polynomials satisfied by , one denoted by has minimum degree.
The monic polynomial of minimum degree that annihilates matrix is called the minimal polynomial of , denoted by .
By the Euclidean algorithm for polynomials, the minimal polynomial is unique and divides every polynomial that annihilates . In particular, the minimal polynomial divides the characteristic polynomial.
Theorem: Ignoring multiplicities, matrix 's characteristic polynomial and minimal polynomial have the same roots.
Theorem: Eigenvectors of matrix belonging to distinct eigenvalues are linearly independent.
Applications
In informatics, we usually consider matrices over , with usually prime, so the similarity transformations above are straightforward. When is composite, we can use an approach similar to the Euclidean algorithm.
Implementation
#include <cassert>
#include <iostream>
#include <random>
#include <vector>
using Matrix = std::vector<std::vector<int>>;
using i64 = int64_t;
Matrix to_upper_Hessenberg(const Matrix &M, int mod) {
Matrix H(M);
int n = H.size();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if ((H[i][j] %= mod) < 0) H[i][j] += mod;
}
}
for (int i = 0; i < n - 1; ++i) {
int pivot = i + 1;
for (; pivot < n; ++pivot) {
if (H[pivot][i] != 0) break;
}
if (pivot == n) continue;
if (pivot != i + 1) {
for (int j = i; j < n; ++j) std::swap(H[i + 1][j], H[pivot][j]);
for (int j = 0; j < n; ++j) std::swap(H[j][i + 1], H[j][pivot]);
}
for (int j = i + 2; j < n; ++j) {
for (;;) {
if (H[j][i] == 0) break;
if (H[i + 1][i] == 0) {
for (int k = i; k < n; ++k) std::swap(H[i + 1][k], H[j][k]);
for (int k = 0; k < n; ++k) std::swap(H[k][i + 1], H[k][j]);
break;
}
if (H[j][i] >= H[i + 1][i]) {
int q = H[j][i] / H[i + 1][i], mq = mod - q;
for (int k = i; k < n; ++k)
H[j][k] = (H[j][k] + i64(mq) * H[i + 1][k]) % mod;
for (int k = 0; k < n; ++k)
H[k][i + 1] = (H[k][i + 1] + i64(q) * H[k][j]) % mod;
} else {
int q = H[i + 1][i] / H[j][i], mq = mod - q;
for (int k = i; k < n; ++k)
H[i + 1][k] = (H[i + 1][k] + i64(mq) * H[j][k]) % mod;
for (int k = 0; k < n; ++k)
H[k][j] = (H[k][j] + i64(q) * H[k][i + 1]) % mod;
}
}
}
}
return H;
}
std::vector<int> get_charpoly(const Matrix &M, int mod) {
Matrix H(to_upper_Hessenberg(M, mod));
int n = H.size();
std::vector<std::vector<int>> p(n + 1);
p[0] = {1 % mod};
for (int i = 1; i <= n; ++i) {
const std::vector<int> &pi_1 = p[i - 1];
std::vector<int> &pi = p[i];
pi.resize(i + 1, 0);
int v = mod - H[i - 1][i - 1];
if (v == mod) v -= mod;
for (int j = 0; j < i; ++j) {
pi[j] = (pi[j] + i64(v) * pi_1[j]) % mod;
if ((pi[j + 1] += pi_1[j]) >= mod) pi[j + 1] -= mod;
}
int t = 1;
for (int j = 1; j < i; ++j) {
t = i64(t) * H[i - j][i - j - 1] % mod;
int prod = i64(t) * H[i - j - 1][i - 1] % mod;
if (prod == 0) continue;
prod = mod - prod;
for (int k = 0; k <= i - j - 1; ++k)
pi[k] = (pi[k] + i64(prod) * p[i - j - 1][k]) % mod;
}
}
return p[n];
}
bool verify(const Matrix &M, const std::vector<int> &charpoly, int mod) {
if (mod == 1) return true;
int n = M.size();
std::vector<int> randvec(n), sum(n, 0);
std::mt19937 gen(std::random_device{}());
std::uniform_int_distribution<int> dis(1, mod - 1);
for (int i = 0; i < n; ++i) randvec[i] = dis(gen);
for (int i = 0; i <= n; ++i) {
int v = charpoly[i];
for (int j = 0; j < n; ++j) sum[j] = (sum[j] + i64(v) * randvec[j]) % mod;
std::vector<int> prod(n, 0);
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
prod[j] = (prod[j] + i64(M[j][k]) * randvec[k]) % mod;
}
}
randvec.swap(prod);
}
for (int i = 0; i < n; ++i)
if (sum[i] != 0) return false;
return true;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, mod;
std::cin >> n >> mod;
Matrix M(n, std::vector<int>(n));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) std::cin >> M[i][j];
std::vector<int> charpoly(get_charpoly(M, mod));
for (int i = 0; i <= n; ++i) std::cout << charpoly[i] << ' ';
assert(verify(M, charpoly, mod));
return 0;
}
The Hessenberg algorithm above is not numerically stable, so matrices over need to be preprocessed with another algorithm or handled with a different numerically stable algorithm.
The characteristic polynomial can be connected with constant-coefficient homogeneous linear recurrences. Together with the Cayley–Hamilton theorem and polynomial modular reduction, it can also accelerate algorithms for computing matrix powers over some fields.
The Cayley–Hamilton theorem states
Here is the zero matrix, , and is the characteristic polynomial of .
If we need for a large , we can first compute and then use .
Clearly, . Let and . Then
Taking , we see that computing requires approximately matrix-matrix multiplications.
References
- Rizwana Rehman, Ilse C.F. Ipsen.La Budde’s Method for Computing Characteristic Polynomials.
- Marshall Law.Computing Characteristic Polynomials of Matrices of Structured Polynomials.
- Mike Paterson.On the Number of Nonscalar Multiplications Necessary to Evaluate Polynomials.