# How do I diagonalize matrix A?

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

- Page: https://www.acalculator.org/math/matrix-diagonalization-calculator
- JSON spec: https://www.acalculator.org/math/matrix-diagonalization-calculator.json
- Version: 01b65648b613

## Default answer

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

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| a | Matrix A | A square matrix, 1 to 6 rows; cells may be fractions such as 1/3. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| verdict | Diagonalizable? | Whether A = P D P⁻¹ with D diagonal. |
| p | P | Eigenvectors as columns, rows separated by semicolons. |
| d | D | The eigenvalues on the diagonal, in the order of the columns of P. |
| pinv | P⁻¹ | The inverse of 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.

## Assumptions

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

## Worked examples

1. a = 2 or 0 or 1 or 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. a = 1 or 1 or 0 or 1 gives verdict = Not diagonalizable: the eigenvalue 1 is a root 2 times but has only 1 independent eigenvector..

## FAQ

### 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.

## Sources

- Ken Kuttler, A First Course in Linear Algebra, section 7.2 Diagonalization (LibreTexts, CC BY): https://math.libretexts.org/Bookshelves/Linear_Algebra/A_First_Course_in_Linear_Algebra_(Kuttler)/07%3A_Spectral_Theory/7.02%3A_Diagonalization
- Ken Kuttler, A First Course in Linear Algebra, section 7.1 Eigenvalues and Eigenvectors of a Matrix (LibreTexts, CC BY): https://math.libretexts.org/Bookshelves/Linear_Algebra/A_First_Course_in_Linear_Algebra_(Kuttler)/07%3A_Spectral_Theory/7.01%3A_Eigenvalues_and_Eigenvectors_of_a_Matrix
