Diagonalize Matrix Calculator
Enter the entries of your 2x2 or 3x3 square matrix and this calculator will find its eigenvalues and eigenvectors, construct the diagonalizing matrix P and the diagonal matrix D, compute P-inverse, and verify the decomposition A = PDP-1 with a worked step-by-step solution. If the matrix is not diagonalizable over the real numbers, it will tell you why.
What does it mean to diagonalize a matrix?
Diagonalizing a matrix A means finding an invertible matrix P and a diagonal matrix D such that A = P D P-1. The diagonal entries of D are the eigenvalues of A, and the columns of P are the corresponding eigenvectors. Once you have this factorization, many otherwise painful computations become trivial: for example, to compute A raised to a large power k you just raise each diagonal entry of D to the k-th power and sandwich it with P and P-1, giving A^k = P D^k P-1. This also makes it easy to solve systems of differential equations, compute matrix exponentials, and understand the long-run behavior of linear dynamical systems.
How to diagonalize a matrix: step-by-step
The procedure has four main stages. First, compute the characteristic polynomial det(A - lambda I) = 0 and solve for the eigenvalues. For a 2x2 matrix this is a quadratic equation; for 3x3 it is a cubic. Second, for each eigenvalue lambda_i, find the null space of (A - lambda_i I) by row reduction. Each non-zero vector in this null space is an eigenvector. Third, check that you have found n linearly independent eigenvectors (one per column of P). If you cannot, the matrix is defective and cannot be diagonalized using the standard method. Fourth, build P by placing the eigenvectors as columns in the same order as their matching eigenvalues appear on the diagonal of D. Invert P with Gauss-Jordan elimination and verify that PDP-1 reproduces A.
When is a matrix not diagonalizable?
Not every square matrix can be diagonalized. A matrix fails to be diagonalizable when it does not have enough linearly independent eigenvectors. This happens in two main situations. The first is when the matrix has complex eigenvalues, which occurs whenever the characteristic polynomial has non-real roots. Such a matrix is diagonalizable over the complex numbers but not over the real numbers. The second is when an eigenvalue has algebraic multiplicity greater than one but geometric multiplicity less than one, meaning the null space of (A - lambda I) has dimension smaller than the number of times lambda appears as a root. These are called defective or non-semisimple matrices, and they have a Jordan normal form rather than a true diagonalization.
Practical uses of matrix diagonalization
Diagonalization appears throughout science and engineering. In quantum mechanics, the energy levels of a physical system are the eigenvalues of its Hamiltonian matrix, and diagonalizing that matrix is literally finding the observable states. In data science, principal component analysis (PCA) diagonalizes the covariance matrix of a dataset to find the directions of greatest variance. In control theory, diagonalizing the system matrix decouples a set of coupled differential equations into independent scalar equations. In network analysis, eigenvalues of the adjacency or Laplacian matrix reveal community structure, connectivity, and diffusion rates. Even Google uses an eigenvector computation (PageRank) to rank web pages.
Diagonalizability quick reference
| Condition | Diagonalizable? | Notes |
|---|---|---|
| All eigenvalues distinct (real) | Yes | Distinct real eigenvalues guarantee n independent eigenvectors |
| Repeated eigenvalue, full geometric multiplicity | Yes | Enough independent eigenvectors still exist |
| Repeated eigenvalue, deficient geometric multiplicity | No | Defective matrix; use Jordan form instead |
| Complex eigenvalues (non-symmetric real matrix) | No (over R) | Diagonalizable over C but not R |
| Symmetric real matrix (A = A^T) | Always yes | Spectral theorem guarantees real eigenvalues and orthogonal P |
| Identity matrix I_n | Yes | Already diagonal; P = I, D = I |
| Zero matrix 0_n | Yes | Already diagonal; D = 0 |
Common conditions that determine whether a square matrix can be diagonalized.
Frequently asked questions
What is the difference between the P matrix and the D matrix?
P is the matrix of eigenvectors: each column of P is one eigenvector of A, placed in the same position as its corresponding eigenvalue. D is the diagonal matrix that holds those eigenvalues in the same order along its main diagonal, with zeros everywhere else. Together they satisfy A = PDP-1. D is simpler to work with because raising a diagonal matrix to any power only requires raising each diagonal entry to that power.
Can every square matrix be diagonalized?
No. A square matrix can be diagonalized over the real numbers only if it has n real eigenvalues (counting multiplicity) and n linearly independent real eigenvectors. A symmetric matrix always satisfies this (the spectral theorem guarantees it). Matrices with complex or repeated eigenvalues may not, depending on the geometric multiplicity of those eigenvalues.
What is the geometric multiplicity of an eigenvalue?
The geometric multiplicity of an eigenvalue lambda is the dimension of its eigenspace, the null space of (A - lambda I). It counts how many linearly independent eigenvectors share that eigenvalue. A matrix is diagonalizable if and only if the geometric multiplicity of every eigenvalue equals its algebraic multiplicity (the number of times it appears as a root of the characteristic polynomial).
How do I use diagonalization to compute matrix powers?
If A = PDP-1, then A^k = P D^k P-1 for any positive integer k. Because D is diagonal, D^k is computed by raising each diagonal entry to the k-th power independently, with no matrix multiplication needed. Then you sandwich the result: multiply P on the left and P-1 on the right. This approach is far faster than multiplying A by itself k times when k is large.
What is the verification step and why does the error not equal zero exactly?
The verification step recomputes PDP-1 from the calculated P, D, and P-inverse and compares it entry-by-entry with the original matrix A. In exact arithmetic the error would be zero. In floating-point arithmetic, tiny rounding errors accumulate through the eigenvector computation and the matrix inversion. An error on the order of 1e-10 or smaller means the factorization is numerically reliable. An error larger than 1e-4 is a warning that the matrix may be nearly singular or that the computation lost significant precision.