acalculator

How do I diagonalize matrix A?

Type a square matrix up to 6 × 6; cells may be fractions such as 1/3. The page finds P and D with A = P D P⁻¹ in exact fractions, or says why A is not diagonalizable.

Your numbers

Matrix A
Diagonalizable?
Diagonalizable: A = P D P⁻¹

Diagonalizable: A = P D P⁻¹.

P
[-2, 1, 0; 1, 0, -1; 0, 1, 2]
D
[2, 0, 0; 0, 2, 0; 0, 0, 6]
P⁻¹
[-1/4, 1/2, 1/4; 1/2, 1, 1/2; -1/4, -1/2, 1/4]

Diagonalizable?: Diagonalizable: A = P D P⁻¹. Diagonalizable: A = P D P⁻¹.

How to calculate

Diagonalize matrix A as P D P⁻¹ in exact fractions, or show why A cannot be diagonalized.

Example with the default inputs (Matrix A [2, 0, 0; 1, 4, -1; -2, -4, 4]): Diagonalizable: A = P D P⁻¹.

Method: Exact eigenvalues from the characteristic polynomial; eigenvectors from the null space of A − λI by Gauss-Jordan elimination in fractions; A P = P D is checked exactly.

  • Cells are exact: 0.1 is 1/10, 1/3 is 1/3.
  • Only eigenvalues that are fractions are handled exactly.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. Matrix A 2, 0, 0; 1, 4, -1; -2, -4, 4 gives P [-2, 1, 0; 1, 0, -1; 0, 1, 2], D [2, 0, 0; 0, 2, 0; 0, 0, 6].Source: Kuttler, A First Course in Linear Algebra, 7.2, Example 7.2.1. https://math.libretexts.org/Bookshelves/Linear_Algebra/A_First_Course_in_Linear_Algebra_(Kuttler)/07%3A_Spectral_Theory/7.02%3A_Diagonalization
  2. Matrix A 1, 1; 0, 1 gives Diagonalizable? Not diagonalizable: the eigenvalue 1 is a root 2 times but has only 1 independent eigenvector..

How it works

Reading the cells. A cell typed as a decimal with up to 15 significant digits is that decimal exactly: 0.8 is 4/5. A cell typed as a fraction such as 1/3 reaches the page as a rounded number; it is read as the fraction with the smallest denominator (up to 1,000,000) that rounds to the same number.

Eigenvalues. The characteristic polynomial det(λI − A) comes from the Faddeev-LeVerrier recurrence in exact fractions. Its fraction roots are found as on the characteristic polynomial calculator: the page takes the square-free part s = p ÷ gcd(p, p′) (exact), whose zeros are those of p, each once. While s has degree 2 or more, it finds the complex roots of s numerically (Durand-Kerner iteration, 800 rounds, starting on a circle whose radius is Fujiwara’s bound 2 × max |aₙ₋ₖ/aₙ|^(1/k), with a₀ halved). For each root whose imaginary part is within 10⁻⁷ × max(1, |real part|) of 0, it tries in turn the convergents of the continued fraction of the real part that lie within 10⁻³ × max(1, |root|) of it, with denominators up to 10¹²; a convergent r is a zero when s divided by (λ − r) leaves remainder exactly 0. Then s is divided by (λ − r) and the roots are found again. Before this, each diagonal entry of A is tried the same way, so a triangular matrix always gets its eigenvalues exactly. When s has degree 1, its zero −s₀/s₁ is a fraction. The multiplicity k of r is the number of times λ − r divides the polynomial exactly. If some part q of the polynomial has no root found as a fraction, the page gives no P and D and says "No verified answer: no fraction with a denominator up to 10¹² was found as a root of q (its roots may be irrational, complex, or fractions with larger denominators), so P and D cannot be given in exact fractions."

Eigenvectors. For each eigenvalue r, from smallest to largest, the page reduces A − rI to reduced row echelon form by Gauss-Jordan elimination in fractions. Each column with no pivot is a free variable; setting it to 1 and the other free variables to 0 gives one basic solution of (A − rI)v = 0. If there are fewer basic solutions than k, A is not diagonalizable and the page says which eigenvalue fails. Otherwise each basic solution is multiplied by the least common multiple of its denominators and divided by the greatest common divisor of its entries, so it has whole-number entries with no common factor.

P, D and P⁻¹. P has these vectors as columns, eigenvalue by eigenvalue, free variables from left to right. D is diagonal with each column’s eigenvalue. P⁻¹ comes from Gauss-Jordan elimination on [P | I]. The page checks A P = P D and P P⁻¹ = I exactly.

How answers are written

  • Diagonalizable?: "Diagonalizable: A = P D P⁻¹", or "Not diagonalizable: the eigenvalue r is a root k times but has only m independent eigenvector(s)."
  • P, D, P⁻¹: matrices in brackets, entries in a row separated by commas, rows separated by semicolons, entries as exact fractions in lowest terms: [−1/4, 1/2, 1/4; 1/2, 1, 1/2; …].

Assumptions

  • Cells are exact: 0.1 is 1/10 and 1/3 is 1/3.
  • Only eigenvalues that are fractions are handled; a matrix with irrational or complex eigenvalues gets a message, not decimals. A fraction eigenvalue with a denominator over about 10⁷ that is not a diagonal entry can be missed; the message then says so.

Worked examples by hand

A = [2, 0, 0; 1, 4, −1; −2, −4, 4] (Kuttler, A First Course in Linear Algebra, section 7.2, Example 7.2.1). det(λI − A) = (λ − 2)((λ − 4)² − 4) = (λ − 2)²(λ − 6). For λ = 2, A − 2I reduces to the one row [1, 2, −1], with free variables y and z: y = 1 gives (−2, 1, 0) and z = 1 gives (1, 0, 1). For λ = 6, A − 6I reduces to x = 0, y + z/2 = 0, so z = 1 gives (0, −1/2, 1), scaled to (0, −1, 2). So P = [−2, 1, 0; 1, 0, −1; 0, 1, 2] and D = [2, 0, 0; 0, 2, 0; 0, 0, 6]. The book’s third column is (0, 1, −2), the same eigenvector times −1.

A = [1, 1; 0, 1] (Example 7.2.2). det(λI − A) = (λ − 1)², so 1 is an eigenvalue twice, but A − I = [0, 1; 0, 0] has one free variable, so one basic solution (1, 0): not diagonalizable.

Other questions people ask

What does it mean to diagonalize a matrix?

To diagonalize a square matrix A is to write it as A = P D P⁻¹, where D is a diagonal matrix and P is invertible. The diagonal entries of D are the eigenvalues of A, and the columns of P are eigenvectors, column j going with the jth diagonal entry. Then powers are easy: Aᵏ = P Dᵏ P⁻¹.

When can a matrix be diagonalized?

An n × n matrix is diagonalizable exactly when it has n linearly independent eigenvectors: for each eigenvalue, the number of independent eigenvectors (the geometric multiplicity) must equal the number of times it is a root of the characteristic polynomial (the algebraic multiplicity). A matrix with n different eigenvalues is always diagonalizable.

Why is [1, 1; 0, 1] not diagonalizable?

Its characteristic polynomial is (λ − 1)², so 1 is an eigenvalue twice, but A − I = [0, 1; 0, 0] has only one independent solution of (A − I)v = 0, the vector (1, 0). With one eigenvector there is no invertible 2 × 2 matrix P of eigenvectors.

Why is P different from my textbook?

Any nonzero multiple of an eigenvector is an eigenvector too, and the columns can come in another order, so P is not unique. The page lists the eigenvalues from smallest to largest and scales each eigenvector to whole numbers with no common factor. Your P and D are right if A P = P D.

What if the eigenvalues are irrational or complex?

This page works in exact fractions, so it needs every eigenvalue to be a fraction (a rational number). When it finds no such fraction, such as for [1, 2; 3, 4] with eigenvalues (5 ± √33)/2, it says so. The eigenvector calculator gives decimal eigenvalues and eigenvectors for any matrix, including complex ones.

How is the answer checked?

In exact fractions, the page checks that A times P equals P times D and that P times P⁻¹ is the identity matrix. With no rounding anywhere, a passing check means the answer is exact.