Diagonalize Matrix Calculator

To diagonalize a matrix, write it as A = PDP⁻¹: D has the eigenvalues on its diagonal, and the columns of P are matching eigenvectors. For A = [4 1; 2 3] the eigenvalues are 5 and 2, so D = diag(5, 2) and P has columns (1, 1) and (1, −2) (see it worked out). Enter any matrix from 2 × 2 to 5 × 5 to get P, D and P⁻¹, or a clear reason why it cannot be done.

Diagonalize a matrix

Type the entries of A, or paste the whole matrix into any cell. Results update as you type.

Fractions such as 1/2 work. Empty cells count as 0 when you press Diagonalize.

Optional. Also gives Aᵏ, worked out as PDᵏP⁻¹.
Examples:

How to Use This Calculator

  1. Enter the matrix

    Pick the size and type the entries, or paste the whole matrix into one cell. Fractions such as 1/2 and negative numbers work.

  2. Read the eigenvalues

    You get exact eigenvalues, the factored characteristic polynomial and a verdict: diagonalizable, only with complex numbers, or not at all.

  3. Check P, D and P⁻¹

    Pick an eigenvalue to see its column in P and its entry in D. Add a power k to get Aᵏ as well.

What does it mean to diagonalize a matrix?

A square matrix A is diagonalizable if you can write it as A = PDP⁻¹, where D is a diagonal matrix (zeros everywhere off the main diagonal) and P is an invertible matrix. Finding P and D is called diagonalizing A. Both matrices come from A itself: the diagonal of D lists the eigenvalues of A, and each column of P is an eigenvector for the eigenvalue in the same position of D.

An eigenvector is a direction that A does not turn. A only stretches it, by a factor called the eigenvalue: Av = λv. Most vectors get turned as well as stretched. The figure shows this for A = [4 1; 2 3]. The vector (1, 0) lands on (4, 2), off its own line. The eigenvectors (1, 1) and (1, −2) stay on theirs and are stretched by 5 and by 2.

Av₁ = 5v₁ Av₂ = 2v₂ v₁ v₂ Au u
A = [4 1; 2 3] stretches v₁ = (1, 1) by 5 and v₂ = (1, −2) by 2. Both stay on their blue lines. The vector u = (1, 0) is turned off its line, so it is not an eigenvector.

Measured along the eigenvectors instead of along x and y, A only stretches each direction by its own amount, and a matrix that only stretches is diagonal. P switches to eigenvector coordinates, D does the stretching, and P⁻¹ switches back.

How to diagonalize a matrix

The method is the same for every size. Here it is for A = [4 1; 2 3].

  1. Write the characteristic polynomial. Subtract λ from each entry on the diagonal and take the determinant: det(A − λI) = (4 − λ)(3 − λ) − 1·2 = λ² − 7λ + 10.
  2. Find the eigenvalues. Set it to 0 and solve: (λ − 5)(λ − 2) = 0, so λ = 5 and λ = 2.
  3. Find an eigenvector for each eigenvalue. Solve (A − λI)v = 0. For λ = 5, A − 5I = [−1 1; 2 −2], whose rows both say x = y, so v₁ = (1, 1). For λ = 2 the rows say 2x + y = 0, so v₂ = (1, −2).
  4. Build P and D. Put the eigenvectors in P as columns and the eigenvalues on the diagonal of D, in the same order.
  5. Find P⁻¹ and check. For a 2 × 2 matrix, swap the diagonal entries, change the signs of the other two, and divide by det P = −3. Then P · D · P⁻¹ should multiply back to A.
4123A 111−2P 5002D 2/31/31/3−1/3P⁻¹

Show [4 1; 2 3] in the calculator

A quick way to check step 3: A times the eigenvector must equal λ times the eigenvector. Here A(1, 1) = (5, 5) = 5·(1, 1) and A(1, −2) = (2, −4) = 2·(1, −2). The calculator runs the same check under the chain of matrices.

Diagonalizing a 3 × 3 matrix

A 3 × 3 matrix works the same way, but det(A − λI) is a cubic. Try small whole numbers that divide the constant term first. Once you find one root, divide it out and solve the quadratic that is left. Take B = [1 1 3; 1 5 1; 3 1 1]. Its characteristic polynomial is −λ³ + 7λ² − 36, and λ = 6 is a root. Dividing it out leaves λ² − λ − 6 = (λ − 3)(λ + 2), so the eigenvalues are 6, 3 and −2.

Eigenvalues and eigenvectors of B = [1 1 3; 1 5 1; 3 1 1], with the check Bv = λv
Eigenvalue λ Eigenvector v Check: Bv
6 (1, 2, 1) (6, 12, 6) = 6·(1, 2, 1)
3 (1, −1, 1) (3, −3, 3) = 3·(1, −1, 1)
−2 (1, 0, −1) (−2, 0, 2) = −2·(1, 0, −1)

So P has columns (1, 2, 1), (1, −1, 1) and (1, 0, −1), and D = diag(6, 3, −2). Two quick checks: the eigenvalues add up to the trace, 6 + 3 − 2 = 7, and they multiply to the determinant, 6 · 3 · (−2) = −36. B is symmetric, so its eigenvectors are also at right angles to each other, which matters further down.

Show the 3 × 3 example in the calculator

When is a matrix diagonalizable?

An n × n matrix is diagonalizable exactly when it has n linearly independent eigenvectors, because P needs n columns and must be invertible. Three facts settle most homework questions:

  • If the n eigenvalues are all different, the matrix is diagonalizable. Each eigenvalue brings its own eigenvector, and eigenvectors for different eigenvalues are always independent.
  • If an eigenvalue repeats, count. The number of times it appears as a root is its algebraic multiplicity. The number of independent eigenvectors it gives (the size of its eigenspace) is its geometric multiplicity. The matrix is diagonalizable only if the two are equal for every eigenvalue.
  • A real symmetric matrix (A = Aᵀ) is always diagonalizable, with real eigenvalues.

The geometric multiplicity of λ is n minus the rank of A − λI. For the shear [1 1; 0 1] and λ = 1, A − I = [0 1; 0 0] has rank 1, so λ = 1 has only 2 − 1 = 1 eigenvector even though it is a double root. The table lists common cases. Each row opens in the calculator.

Example matrices, their eigenvalues, and whether they can be diagonalized
Matrix Eigenvalues Why Diagonalizable?
[4 1; 2 3] 5, 2 Two different eigenvalues Yes
[1 2; 3 4] (5 ± √33)/2 Two different eigenvalues Yes
[3 0; 0 3] 3, 3 λ = 3 twice, 2 eigenvectors Yes
[1 1; 0 1] 1, 1 λ = 1 twice, 1 eigenvector No
[0 −1; 1 0] i, −i Complex eigenvalues Over ℂ only
[4 −1 6; 2 1 6; 2 −1 8] 9, 2, 2 λ = 2 twice, 2 eigenvectors Yes
[2 1 1; 1 2 1; 1 1 2] 4, 1, 1 Symmetric Yes

Matrices that cannot be diagonalized

A matrix that is short of eigenvectors is called defective. The shear [1 1; 0 1] is the standard example. It slides every point sideways in proportion to its height, so only the x-axis stays on its own line. There is one eigenvector direction and P would need two. The best you can do is the Jordan form, a matrix that is almost diagonal, with a 1 just above a repeated eigenvalue. For a matrix like this the calculator shows which eigenvalue is short of eigenvectors and by how many.

Show why the shear cannot be diagonalized

Complex eigenvalues

The rotation [0 −1; 1 0] turns every vector a quarter turn, so no real direction stays on its line. Its characteristic polynomial is λ² + 1, with roots i and −i. Over the real numbers it cannot be diagonalized. If complex numbers are allowed, it can: the eigenvectors are (i, 1) and (i, −1), and A = PDP⁻¹ with D = diag(i, −i). Your course decides which answer it wants. Most first courses mean the real numbers unless they say otherwise. The calculator works over the complex numbers and labels the result "over ℂ only".

Show the rotation with complex eigenvalues

Symmetric matrices: orthogonal diagonalization

For a real symmetric matrix you can do better than PDP⁻¹. Its eigenvectors for different eigenvalues are at right angles, so after dividing each one by its length they form an orthogonal matrix Q. The inverse of an orthogonal matrix is its transpose, so A = QDQᵀ and no inverse needs to be computed. This is the spectral theorem.

For [2 1; 1 2] the eigenvalues are 3 and 1 with eigenvectors (1, 1) and (1, −1). Both have length √2, so Q has columns (1, 1)/√2 and (1, −1)/√2. When an eigenvalue repeats, its eigenvectors may not be at right angles. Run Gram-Schmidt on them first. For [2 1 1; 1 2 1; 1 1 2] the calculator turns the pair (1, −1, 0), (1, 0, −1) for λ = 1 into (1, −1, 0)/√2 and (1, 1, −2)/√6. Switch the chain to QDQᵀ to see Q.

Show the symmetric 3 × 3 as QDQᵀ

Powers of a matrix with diagonalization

Diagonalizing makes large powers easy. In Aᵏ = (PDP⁻¹)(PDP⁻¹)⋯(PDP⁻¹), every P⁻¹P in the middle cancels, which leaves

Aᵏ = P Dᵏ P⁻¹,  Dᵏ = diag(λ₁ᵏ, …, λₙᵏ)

Raising D to a power only raises each diagonal entry to that power. For A = [4 1; 2 3], D¹⁰ = diag(5¹⁰, 2¹⁰) = diag(9,765,625, 1,024), and P · D¹⁰ · P⁻¹ gives A¹⁰ = [6,510,758 3,254,867; 6,509,734 3,255,891]. Multiplying A by itself ten times gives the same matrix with far more work.

Show A¹⁰ in the calculator

The same idea gives a formula for the Fibonacci numbers. [1 1; 1 0]ᵏ holds the Fibonacci numbers, and [1 1; 1 0]¹⁰ = [89 55; 55 34]. Its eigenvalues are (1 + √5)/2 and (1 − √5)/2, the golden ratio and its partner. Diagonalizing it leads straight to Binet's formula. The same trick solves recurrences, Markov chains and systems of differential equations, where e^(At) = P e^(Dt) P⁻¹.

Show the Fibonacci matrix to the 10th power

Quick checks and common mistakes

  • The eigenvalues, counted with repeats, add up to the trace (the sum of the diagonal) and multiply to the determinant. If they do not, recheck the characteristic polynomial.
  • Subtract λ from every diagonal entry, not just the first. A − λI changes only the diagonal.
  • Keep the order. Column i of P must belong to the i-th diagonal entry of D. Swapping columns without swapping eigenvalues gives a wrong answer.
  • An eigenvector is never the zero vector. If (A − λI)v = 0 only has v = 0 as a solution, λ is not an eigenvalue. Go back to step 2.
  • Your P may differ from the book's. Scaled or reordered eigenvectors are just as correct, as long as D matches.
  • A repeated eigenvalue does not mean "not diagonalizable". Count its eigenvectors before you decide.

Frequently Asked Questions

What does it mean to diagonalize a matrix?

It means writing the matrix as A = PDP⁻¹, where D is diagonal. The diagonal of D holds the eigenvalues of A, and the columns of P are matching eigenvectors. For A = [4 1; 2 3] that gives D with 5 and 2 on the diagonal and P with columns (1, 1) and (1, −2).

Show [4 1; 2 3] diagonalized

How do you know if a matrix is diagonalizable?

An n × n matrix is diagonalizable when it has n linearly independent eigenvectors. In practice, check each eigenvalue: the number of times it appears as a root of det(A − λI) must equal the number of independent eigenvectors it gives. If all n eigenvalues are different, the matrix is always diagonalizable.

Can every matrix be diagonalized?

No. The shear matrix [1 1; 0 1] has λ = 1 twice but only one eigenvector direction, (1, 0), so there are not enough columns for P. Over the real numbers, a rotation such as [0 −1; 1 0] cannot be diagonalized either, because its eigenvalues are i and −i.

Try the shear matrix

Can a matrix with repeated eigenvalues be diagonalized?

Sometimes. It works when each repeated eigenvalue gives as many independent eigenvectors as the number of times it repeats. [4 −1 6; 2 1 6; 2 −1 8] has λ = 2 twice and two eigenvectors for it, so it is diagonalizable. [1 1; 0 1] has λ = 1 twice and only one eigenvector, so it is not.

Show the repeated eigenvalue example

Why is my P different from the answer key?

Because P is not unique. Any nonzero multiple of an eigenvector is still an eigenvector, so (1, −2) and (−2, 4) are both fine. The columns can also come in any order, as long as D lists the eigenvalues in the same order. Every correct P still gives PDP⁻¹ = A.

What is the difference between A = PDP⁻¹ and P⁻¹AP = D?

They say the same thing. Multiply A = PDP⁻¹ by P⁻¹ on the left and by P on the right and you get P⁻¹AP = D. Some textbooks write the first form and some the second, but P and D are the same matrices in both.

How do you orthogonally diagonalize a symmetric matrix?

Find the eigenvalues and eigenvectors as usual, make the eigenvectors of each repeated eigenvalue perpendicular with Gram-Schmidt, then divide every eigenvector by its length. Those unit vectors are the columns of Q, and A = QDQᵀ. For [2 1; 1 2] the columns are (1, 1)/√2 and (1, −1)/√2.

Show [2 1; 1 2] as QDQᵀ