Solution (source code)

= Solution

The candidate $\Pi$ is tacitly required to belong to $S$, as in the usual <variational characterization of convex projection>; this feasibility holds for the candidate constructed in part (b). Use the Frobenius inner product
$$
\langle A,B\rangle_F=\operatorname{Tr}(A^TB).
$$
For any $Z\in S$,
$$
M-Z=(M-\Pi)-(Z-\Pi),
$$
and hence
$$
\begin{aligned}
\|M-Z\|_F^2
&=\|M-\Pi\|_F^2+\|Z-\Pi\|_F^2
-2\langle M-\Pi,Z-\Pi\rangle_F\\
&\geq\|M-\Pi\|_F^2+\|Z-\Pi\|_F^2\\
&\geq\|M-\Pi\|_F^2.
\end{aligned}
$$
Thus $\Pi$ minimizes the squared Frobenius distance over $S$. Since that objective is strictly convex,
$$
\boxed{\Pi=\pi(M)}.
$$