Sum of squares for matrix valued data over $\mathbb{R}$ and $\mathbb{C}$
Essentially you want to pick a function that will give you the &quot;size&quot; of a matrix. The most obvious way I can think of is by choosing a matrix norm, which is a map $\lVert \cdot \rVert \colon \mathbb{R}^{k, k} \to [0, \infty)$ (or you could generalise to a complex $k \times k$ matrix if you wished).
Your suggestion seems similar to computing
$$S = \sum_i (M_i - \hat M_i)^2$$
then using the Frobenius norm $\lVert S \rVert_F$ to turn this into a real number. The Frobenius norm essentially means &quot;squash $S$ into a vector of dimension $k \times k$, then compute the Euclidean norm&quot;.
There are plenty of other norms you could consider, such as the operator norms. Interestingly enough it can be proved that any two matrix norms are equivalent up to a constant scaling factor, so your choice of norm isn't particularly important, and minimising the &quot;sum of squares&quot; under any norm should be more or less the same.