Advertisement
Advertisement
LINEAR ALGEBRA

Matrix Diagonalization Calculator — find P, D and P inverse

Diagonalise a 2×2 or 3×3 matrix into P D P inverse, see the reconstruction error, and get a written explanation naming the deficient eigenvalue when the matrix is defective.

One row per line, values separated by spaces, commas or tabs. Must be square, either 2×2 or 3×3.
Internal arithmetic is full double precision; this controls display only. Eigenvectors are scaled to unit length.
Diagonalisable?
 
Matrix size
Distinct eigenvalues
Independent eigenvectors
Reconstruction error
Matrices:
Working:
Tip: the reconstruction error is the largest entry-by-entry difference between P D P inverse and the matrix you entered. It is the only line on this page that proves the factorisation is right rather than merely plausible, so read it before anything else.
Advertisement

The matrix diagonalization calculator above factors a square matrix A into P D P−1, where D is diagonal and holds the eigenvalues and P holds the corresponding eigenvectors as its columns. It then multiplies the three factors back together and reports the largest discrepancy against your original matrix, so the answer arrives with its own proof attached.

Not every matrix can be diagonalised, and the ones that cannot are the interesting ones. When a matrix is defective this page names the eigenvalue at fault, gives its algebraic and geometric multiplicities, and explains what that gap means — rather than returning a page of NaN. Our eigenvalue calculator finds the spectrum and the characteristic polynomial; this page takes the further step of assembling the factorisation and verifying it.

What This Matrix Diagonalization Calculator Does

It builds the characteristic polynomial, solves it exactly in closed form — a quadratic for 2×2, a cubic by the trigonometric method for 3×3 — and groups the roots into distinct eigenvalues with their algebraic multiplicities. For each distinct eigenvalue it computes the null space of A − λI by Gaussian elimination, which gives the eigenvectors and, by counting them, the geometric multiplicity.

If the geometric multiplicities sum to the size of the matrix, there are enough independent eigenvectors to fill P and the matrix is diagonalisable. The tool then inverts P, forms the product P D P−1, and compares it entry by entry with A. That figure should be zero or at the level of floating-point rounding, and it is displayed in scientific notation precisely so you can see which.

If any eigenvalue has fewer independent eigenvectors than its algebraic multiplicity, the matrix is defective and no diagonalisation exists. The tool reports which eigenvalue is short, by how much, and what that implies. Complex eigenvalues are handled as a third case: the matrix is diagonalisable over the complex numbers but not over the reals, and the tool names the conjugate pair rather than pretending the roots do not exist.

How to Use It

  1. Enter the matrix one row per line with values separated by spaces, commas or tabs. Every row needs the same number of entries as there are rows.
  2. Read the headline first. It states whether a diagonalisation exists before showing you anything that assumes one does.
  3. Check the independent eigenvector count against the matrix size. Those two numbers being equal is the whole condition.
  4. Confirm the reconstruction error is effectively zero. If it is not, the factorisation has broken down numerically even though the algorithm completed.
  5. Use the presets to see all four outcomes: distinct eigenvalues, repeated but diagonalisable, defective, and complex.

The Formula and How It Is Calculated

A square matrix A is diagonalisable when it can be written A = P D P−1. Wolfram MathWorld's page on matrix diagonalization states exactly that decomposition, with P composed of the eigenvectors of A and D the diagonal matrix built from the corresponding eigenvalues. The order of the columns of P must match the order of the entries of D, which is why they are always presented together.

The condition is stated separately. MathWorld's page on diagonalizable matrices gives it as: an n×n matrix A is diagonalizable if and only if A has n linearly independent eigenvectors. That is the only condition, and everything else — distinct eigenvalues being sufficient, symmetric matrices always working — is a consequence of it.

Work the default through. A has rows (5, −6, −6), (−1, 4, 2) and (3, −6, −4). Its trace is 5 + 4 − 4 = 5 and its determinant is 4, so the eigenvalues must sum to 5 and multiply to 4. They are 1, 2 and 2. The eigenvalue 2 is repeated, but A − 2I has rank 1, so its null space is two-dimensional and supplies two independent eigenvectors. Together with the one for λ = 1 that is three, which fills P, and the matrix is diagonalisable despite the repetition.

Advertisement

Algebraic Versus Geometric Multiplicity

Every eigenvalue carries two counts. Its algebraic multiplicity is how many times it appears as a root of the characteristic polynomial. Its geometric multiplicity is the dimension of its eigenspace, that is, how many linearly independent eigenvectors it supplies. The geometric multiplicity is always at least one and never exceeds the algebraic multiplicity, but it can fall short of it.

A matrix is diagonalisable exactly when the two counts agree for every eigenvalue. When they agree, adding up the geometric multiplicities gives n and P has enough columns. When any eigenvalue is short, the total falls below n, P cannot be filled with independent columns, and no diagonalisation exists over any field. Such a matrix is called defective, and the eigenvalue responsible is the deficient one.

Press the defective preset and the tool loads the matrix with rows (2, 1, 0), (0, 2, 1) and (0, 0, 2). Its characteristic polynomial is (2 − λ)³, so λ = 2 has algebraic multiplicity 3. But A − 2I has rank 2, so its null space is one-dimensional and λ = 2 supplies a single eigenvector. Three needed, one available: the matrix is defective and the tool says which eigenvalue is short and by how many.

What Happens When Diagonalisation Fails

A defective matrix has a Jordan normal form instead. That form is block diagonal, with each block having the eigenvalue on the diagonal and ones on the superdiagonal, and it is as close to diagonal as such a matrix can get. Everything diagonalisation is used for — powers, exponentials, decoupling a linear system — still works through the Jordan form, but the arithmetic is heavier because the blocks do not commute away.

The practical difficulty is that defectiveness is not numerically stable. An arbitrarily small perturbation of a defective matrix generally has distinct eigenvalues and is therefore diagonalisable, but with a P that is nearly singular. So in floating point, a defective matrix rarely announces itself cleanly; it appears as a diagonalisation with an enormous condition number on P, which is a warning rather than a result. Our matrix rank calculator is useful for inspecting the rank of A − λI directly.

Complex eigenvalues are a different failure, and a milder one. A rotation matrix has no real eigenvectors because it maps no real direction to a multiple of itself, but it is perfectly diagonalisable over the complex numbers. This tool works in real arithmetic and reports the conjugate pair rather than the factorisation, since a real P does not exist. Our complex number calculator handles arithmetic in that field.

Which Matrices Are Guaranteed to Work

Two conditions are worth memorising. First, if all n eigenvalues are distinct, the matrix is diagonalisable — eigenvectors for distinct eigenvalues are automatically independent, so there are always enough. This is sufficient but not necessary, and the default example proves it: it has a repeated eigenvalue and diagonalises anyway.

Second, every real symmetric matrix is diagonalisable, with real eigenvalues and an orthogonal P whose inverse is simply its transpose. That is the spectral theorem, and it is the reason symmetric matrices are so much easier to work with numerically. Press the symmetric preset to see it: the tridiagonal matrix with 2 on the diagonal and −1 off it has eigenvalues 2 and 2 ± √2, all real, all with independent eigenvectors.

A symmetric positive definite matrix has the further property that every eigenvalue is strictly positive, which is what our Cholesky decomposition calculator exploits to factor it far more cheaply than a general decomposition allows. For non-symmetric matrices there is no guarantee at all, and the only way to know is to compute the eigenspaces and count. Our matrix inverse calculator and determinant calculator supply the supporting quantities.

Need a factorisation that verifies itself?

Arb Digital builds free linear algebra tools that reconstruct the input from the factors and show you the error.

Browse All Free Tools Talk To Our Team

Common Mistakes to Avoid

  • Assuming a repeated eigenvalue blocks diagonalisation — it does not. What matters is whether that eigenvalue supplies as many independent eigenvectors as its algebraic multiplicity.
  • Mismatching the column order of P with the diagonal of D — the k-th column of P must be an eigenvector for the k-th entry of D, or the reconstruction fails.
  • Treating a tiny reconstruction error as failure — anything near machine epsilon is rounding. It is a large error that signals a genuinely ill-conditioned P.
  • Expecting a real factorisation from complex eigenvalues — a rotation has none. The matrix is diagonalisable over the complex numbers only.
  • Reading defectiveness as a numerical accident — it is an exact structural property. In floating point it usually shows up as a nearly singular P rather than as a clean failure.

Related Free Tools From Arb Digital

Find the spectrum and characteristic polynomial with the eigenvalue calculator, invert a matrix with the matrix inverse calculator, get the determinant with the determinant calculator, factor a symmetric positive definite matrix with the Cholesky decomposition calculator, or check rank with the matrix rank calculator. The full free online tools hub lists every linear algebra tool we publish.

Frequently Asked Questions

When is a matrix diagonalisable?

Exactly when it has as many linearly independent eigenvectors as its size. Equivalently, when every eigenvalue's geometric multiplicity equals its algebraic multiplicity.

What is a defective matrix?

One where some eigenvalue supplies fewer independent eigenvectors than its algebraic multiplicity. Such a matrix has no diagonalisation at all, over any field, and needs a Jordan normal form instead.

Does a repeated eigenvalue prevent diagonalisation?

No. The identity matrix has one eigenvalue repeated n times and is already diagonal. What matters is the dimension of the eigenspace, not how many times the root appears.

What is the reconstruction error?

The largest entry-by-entry difference between P D P inverse and the matrix you entered. It should be zero or at the level of floating-point rounding, and it is the only check that the factorisation is genuinely correct.

Are symmetric matrices always diagonalisable?

Yes. Every real symmetric matrix has real eigenvalues and a full set of orthogonal eigenvectors, which is the spectral theorem, and its P can be chosen so that its inverse is simply its transpose.

What if the eigenvalues are complex?

The matrix has no real diagonalisation, because no real direction is mapped to a multiple of itself. It is still diagonalisable over the complex numbers, and this tool names the conjugate pair instead of returning a factorisation.

Is the factorisation unique?

No. Eigenvectors can be scaled by any non-zero constant and reordered along with the diagonal, and a repeated eigenvalue allows any basis of its eigenspace. D is unique only up to the ordering of its entries.

Why diagonalise at all?

Because powers become trivial: A to the k equals P times D to the k times P inverse, and raising a diagonal matrix to a power just raises each entry. The same trick handles matrix exponentials and decouples systems of linear differential equations.

This page explains a numerical linear algebra method for educational purposes. Results are computed in double-precision floating point, so a matrix very close to defective may factor successfully while producing a P that is unreliable to invert.

Advertisement
Advertisement

Take it further