MLCrack

    ML MATH & LINEAR ALGEBRA · INTERVIEW QUESTION

    Explain the relationship between eigendecomposition and diagonalization. Why is it useful?

    🔴 advanced · Linear Algebra

    Hint: A = PDP⁻¹ where D is diagonal with eigenvalues.

    Answer

    A square matrix AA can be diagonalized as:

    A=PDP−1A = PDP^{-1}

    where PP contains eigenvectors as columns and DD is diagonal with eigenvalues.

    Why is this useful?

    1. Matrix powers: An=PDnP−1A^n = PD^nP^{-1} — just raise diagonal entries to power nn
    2. Matrix exponential: eA=PeDP−1e^A = Pe^DP^{-1} — used in continuous-time models
    3. PCA: eigendecomposition of covariance matrix gives principal components
    4. Spectral clustering: eigendecomposition of graph Laplacian
    python
    import numpy as np A = np.array([[2, 1], [1, 2]]) eigenvalues, P = np.linalg.eig(A) D = np.diag(eigenvalues) # Verify: A = P @ D @ P^{-1} A_reconstructed = P @ D @ np.linalg.inv(P) print(np.allclose(A, A_reconstructed)) # True # Matrix power made easy A_cubed = P @ np.diag(eigenvalues**3) @ np.linalg.inv(P)

    Not all matrices are diagonalizable (need nn linearly independent eigenvectors). Symmetric matrices are always diagonalizable with orthogonal eigenvectors (spectral theorem).