Solution (source code)

= Solution

Write $\widehat A=\operatorname{diag}(\lambda_1,\ldots,\lambda_n)$ and $v_i=P^{-1}e_i$, where $e_i$ are the <standard basis> <vectors>. Since $AP^{-1}=P^{-1}\widehat A$,
$$
Av_i=P^{-1}\widehat Ae_i=\lambda_iv_i.
$$
Thus \b[the columns of $P^{-1}$ form an <eigenbasis>], and the requested <ordered basis> is $D=(P^{-1}e_1,\ldots,P^{-1}e_n)$. Its <basis matrix> is $P^{-1}$, giving $[t]_D=PAP^{-1}=\widehat A$. More completely, for each distinct <eigenvalue> $\lambda$, its <eigenspace> is
$$
E_\lambda(A)=\operatorname{span}\{P^{-1}e_i:\lambda_i=\lambda\}.
$$
All nonzero <vectors> in these <eigenspaces> are <eigenvectors>; when an <eigenvalue> repeats, they need not be individual columns of $P^{-1}$.