{
  "id": "matrix-diagonalization",
  "version": "01b65648b613",
  "status": "published",
  "name": "Matrix Diagonalization Calculator",
  "question": "How do I diagonalize matrix A?",
  "summary": "Diagonalize matrix A as P D P⁻¹ in exact fractions, or show why A cannot be diagonalized.",
  "category": "math",
  "subcategory": "linear-algebra",
  "url": "https://www.acalculator.org/math/matrix-diagonalization-calculator",
  "markdown": "https://www.acalculator.org/math/matrix-diagonalization-calculator.md",
  "kind": "function",
  "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."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "a": {
        "title": "Matrix A",
        "description": "A square matrix, 1 to 6 rows; cells may be fractions such as 1/3.",
        "type": "array",
        "items": {
          "type": "array",
          "items": {
            "type": "number"
          }
        }
      }
    }
  },
  "outputs": {
    "verdict": {
      "label": "Diagonalizable?",
      "description": "Whether A = P D P⁻¹ with D diagonal.",
      "format": "text"
    },
    "p": {
      "label": "P",
      "description": "Eigenvectors as columns, rows separated by semicolons.",
      "format": "text"
    },
    "d": {
      "label": "D",
      "description": "The eigenvalues on the diagonal, in the order of the columns of P.",
      "format": "text"
    },
    "pinv": {
      "label": "P⁻¹",
      "description": "The inverse of P.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "a": "2,0,0;1,4,-1;-2,-4,4"
    },
    "outputs": {
      "verdict": "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]",
      "pinv": "[-1/4, 1/2, 1/4; 1/2, 1, 1/2; -1/4, -1/2, 1/4]"
    },
    "text": "Diagonalizable: A = P D P⁻¹."
  },
  "examples": [
    {
      "given": {
        "a": [
          [
            2,
            0,
            0
          ],
          [
            1,
            4,
            -1
          ],
          [
            -2,
            -4,
            4
          ]
        ]
      },
      "expect": {
        "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"
    },
    {
      "given": {
        "a": [
          [
            1,
            1
          ],
          [
            0,
            1
          ]
        ]
      },
      "expect": {
        "verdict": "Not diagonalizable: the eigenvalue 1 is a root 2 times but has only 1 independent eigenvector."
      },
      "source": "Kuttler, A First Course in Linear Algebra, 7.2, Example 7.2.2"
    }
  ],
  "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"
  ],
  "related": [
    "eigenvector",
    "characteristic-polynomial",
    "inverse-matrix",
    "rref"
  ],
  "changelog": []
}
