Solution (source code)

= Solution

With $A_0=A$, repeat the shifted <QR algorithm>:
$$
\boxed{A_k-\mu_kI=Q_kR_k,\qquad A_{k+1}=R_kQ_k+\mu_kI.}
$$
The <QR shift> $\mu_k$ is chosen from $A_k$, for example its bottom-right entry or an <eigenvalue> of a trailing two-by-two block. Explicitly using the <orthogonality> of $Q_k$ gives
$$
A_{k+1}=Q_k^T(A_k-\mu_kI)Q_k+\mu_kI=Q_k^TA_kQ_k.
$$
Thus each update is a <matrix similarity> preserving <eigenvalues>. Accumulate $Q_0Q_1\cdots Q_k$ if <eigenvectors> or the full reduction are wanted. Once a subdiagonal entry is negligible, <block deflation in the QR algorithm> separates the corresponding blocks and iteration continues on the active block.