Solution (source code)

= Solution

Choose a real unit <eigenvector> $e_1$ of the real <symmetric matrix> $Q$, with <eigenvalue> $\lambda_1$. Its <orthogonal complement> is an <invariant subspace>: for any $v$ with $e_1^Tv=0$,
$$
e_1^TQv=(Qe_1)^Tv=\lambda_1e_1^Tv=0.
$$
The restriction of $Q$ to this $(n-1)$-dimensional space is again real and symmetric. Applying the same argument inductively produces an <orthonormal basis> $e_1,\ldots,e_n$ of real <eigenvectors>. The base case $n=1$ is immediate. This proves the <spectral theorem for real symmetric matrices> without assuming that distinct <eigenvalues> are available.

One can also check that <eigenvectors> with different <eigenvalues> are automatically orthogonal: $\lambda_i e_i^Te_j=(Qe_i)^Te_j=e_i^TQe_j=\lambda_j e_i^Te_j$. Within a repeated <eigenspace>, the <Gram-Schmidt process> preserves the eigenvector property. Thus repeated <eigenvalues> cause no obstruction, and $\boxed{Q=ODO^T\text{ for an orthogonal }O\text{ and real diagonal }D}$.