Understanding the matrix diagonalization calculator — concept and principle
This calculator diagonalizes a square matrix, writing it as A = P·D·P⁻¹ with the eigenvalues on the diagonal of D and the eigenvectors as the columns of P. It reports P, D, P⁻¹ and the algebraic and geometric multiplicity of each eigenvalue, or explains why the matrix cannot be diagonalized. Use it for linear algebra homework, matrix powers and systems of differential equations.
How it is calculated
- Find the eigenvalues as the roots of the characteristic polynomial det(A − λI) = 0.
- For each eigenvalue λ, solve (A − λI)v = 0 for a basis of its eigenspace.
- Compare the eigenspace dimension (geometric multiplicity) with the number of times λ is a root (algebraic multiplicity).
- If all eigenvalues are real and the two multiplicities agree for each, put the eigenvectors in P and the matching eigenvalues in D.
- n distinct eigenvalues are always enough. Eigenvalues within 10⁻⁷ of a whole number are rounded to it; eigenvectors are scaled so a free variable equals 1.
The principle
A diagonal matrix just stretches each coordinate axis. Diagonalizing A means finding a set of axes, the eigenvectors, along which A acts as pure stretching by the eigenvalues. P changes into those axes, D does the stretching, and P⁻¹ changes back. This needs n independent eigenvectors; a repeated eigenvalue with too few eigenvectors (a "shear") breaks it. Diagonal form makes powers easy: Aᵏ = P·Dᵏ·P⁻¹.
Worked example
Default input: A = [1 3 3; −3 −5 −3; 3 3 1].
- Characteristic polynomial: (λ − 1)(λ + 2)², so eigenvalues 1 and −2 (twice).
- λ = 1: eigenvector (1, −1, 1); multiplicity 1 / 1.
- λ = −2: A + 2I has rank 1, giving two eigenvectors (−1, 1, 0) and (−1, 0, 1); multiplicity 2 / 2.
- Diagonalizable? Yes — A = P·D·P⁻¹, with D = [1 0 0; 0 −2 0; 0 0 −2] and P = [1 −1 −1; −1 1 0; 1 0 1].
- P⁻¹ = [1 1 1; 1 2 1; −1 −1 0].
How to read the result
Each column of P is paired with the entry of D in the same position. You can check one pair directly: A × (1, −1, 1) = (1, −1, 1), so it is stretched by 1. Any non-zero multiple of an eigenvector, or any other basis of the same eigenspace, gives an equally valid P.
Common mistakes
- Ordering the columns of P differently from the eigenvalues in D.
- Assuming a repeated eigenvalue always prevents diagonalization; here it does not.
- Forgetting complex eigenvalues, which prevent real diagonalization.
- Confusing P·D·P⁻¹ with P⁻¹·D·P.
Frequently asked questions
When is a matrix diagonalizable?
When it has n linearly independent eigenvectors; n distinct eigenvalues guarantee this.
What do algebraic and geometric multiplicity mean?
How often λ is a root of the characteristic polynomial, and how many independent eigenvectors it has.
Why diagonalize a matrix?
To compute powers and functions of A easily and to decouple linear systems.
Sources: A. Davis, P. Zachlin et al., Coordinated Linear Algebra (University of Nebraska–Lincoln), §6.1–6.2