Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Compute a matrix logarithm or square root

Use when: you need \log A or \sqrt A for a diagonalizable matrix A

Goal: the matrix \log A or \sqrt A, correctly flagged as real, complex, or undefined based on A's eigenvalues

Taught in Matrix logarithms and square roots

  1. 1

    Find A's eigenvalues and a full set of independent eigenvectors, then write A = PDP^{-1} with D diagonal.

    Example

    Take A=\begin{bmatrix}5&4\\1&2\end{bmatrix}. Its characteristic equation is \lambda^2-7\lambda+6=0, factoring as (\lambda-6)(\lambda-1)=0, so \lambda=6 or \lambda=1. Solving (A-6I)\mathbf v=\mathbf 0 gives eigenvector (4,1); solving (A-I)\mathbf v=\mathbf 0 gives eigenvector (1,-1). P=\begin{bmatrix}4&1\\1&-1\end{bmatrix}, \quad D=\begin{bmatrix}6&0\\0&1\end{bmatrix}, \quad P^{-1}=\begin{bmatrix}1/5&1/5\\1/5&-4/5\end{bmatrix}

    ⚡ Shortcut

    If A is already diagonal, skip this step entirely: D=A and P=I, so the remaining steps just apply f to each diagonal entry directly. Every worked example below starts from exactly this shortcut.

    Why: applying \log or \sqrt{\cdot} entrywise to D and conjugating back by P is only valid once A is written in exactly this factored form.

  2. 2

    Look at every eigenvalue on D's diagonal and sort each one into exactly one of three cases before applying \log or \sqrt{\cdot} to it.

    Example

    Both eigenvalues of the running example, 6 and 1, are positive, so both fall under the first case: use the real-valued function directly.

    • eigenvalue is positive — apply the ordinary real-valued function directly.
    • eigenvalue is negative — apply the complex-valued formula instead (\log(-r)=\log r+i\pi, or \sqrt{-r}=i\sqrt r); the result is genuinely complex.
    • eigenvalue is exactly zero and f=\log — no logarithm exists for this matrix at all; stop here.
    • eigenvalue is exactly zero and f=\sqrt{\cdot} — \sqrt0=0 exactly; continue normally.

    Why: this determines which formula gets applied entrywise in the next step, and misclassifying even one eigenvalue produces a wrong result or a spurious complex answer.

  3. 3

    Replace each diagonal entry of D with f applied to it, using the branch selected in Step 2 for that entry.

    Example

    \log6\approx1.792 and \log1=0, both real since both eigenvalues were positive. f(D)=\begin{bmatrix}1.792&0\\0&0\end{bmatrix}

    Why: this is the one step where the choice of function, and the branch from Step 2, actually gets used; everything before and after it is bookkeeping.

  4. 4

    Multiply the three matrices back together in that order to get the final answer as one genuine matrix.

    Example

    f(A)=\begin{bmatrix}4&1\\1&-1\end{bmatrix}\begin{bmatrix}1.792&0\\0&0\end{bmatrix}\begin{bmatrix}1/5&1/5\\1/5&-4/5\end{bmatrix}\approx\begin{bmatrix}1.433&1.433\\0.358&0.358\end{bmatrix}

    Both entries come out equal since \log1=0 erases that eigenvector's contribution from every column.

    Why: the eigendecomposition only carries meaning once it's been reassembled; D or f(D) alone says nothing about A itself.

  5. 5

    Apply the inverse operation to the answer (exponentiate a logarithm, or square a square root) and confirm the original A comes back.

    Example

    e^{f(A)} recovers A=\begin{bmatrix}5&4\\1&2\end{bmatrix} exactly, confirmed by reversing the same eigendecomposition: Pe^{f(D)}P^{-1}=PDP^{-1}=A.

    Why: this catches an arithmetic slip in the eigenvectors, the logarithm, or the matrix multiplication before it's mistaken for a genuine final answer.

Common mistakes

  • Applying \log or \sqrt{\cdot} to A's entries directly, instead of to the eigenvalues on D's diagonal.
  • Treating a zero eigenvalue the same way for \log and \sqrt{\cdot}; \log has no value there at all, but \sqrt0=0 is perfectly fine.
  • Forgetting that a single negative eigenvalue is enough to make the entire matrix answer complex, even when every other eigenvalue is positive.
  • Skipping the reversal check in Step 5 and trusting the eigenvector arithmetic without confirming it.