TITLE: Linear and Commutative function over Square Matrices.
QUESTION [6 upvotes]: Find all functions $f$, such that $f(mA+nB) = mf(A) + nf(B)$ and  $f(AB) = f(BA)$ , where $A, B$ are square matrices and $ m,n$ are scalars. Need to find $f$ as an explicit function of any general matrix M.
I observed that $Trace(M)$ is a valid function satisfying the condition, but any methodical approach to find the functions would be helpful.

REPLY [5 votes]: Let $f$ be any such function.
For each $i$ and $j$ let $E_{ij}$ denote the $n \times n$ matrix with a $1$ in the row $i$, column $j$ entry and zeros everywhere else.  Let $I$ denote the $n \times n$ identity matrix.  You should be able to prove or convince yourself that for any $i$, $j$, $k$, and $l$ that
$$
E_{ij} E_{kl} = \delta_{jk} E_{il}
$$
where $\delta_{jk} = 1$ if $j = k$ and $\delta_{jk} = 0$ otherwise (it may help to think in terms of linear transformations instead of matrices here: $E_{ab}$ sends the $b$th standard basis vector to the $a$th standard basis vector, and sends and all other standard basis vectors to $0$).
We can deduce from this that for any $i$ one has
$$
f(E_{ii}) = f(E_{i1} E_{1i}) = f(E_{1i} E_{i1}) = f(E_{11}),
$$
and since $I = \sum_{i=1}^n E_{ii}$ it follows that $f(E_{ii}) = \frac{1}{n} f(I)$ for all $i$.
Since your assumptions imply that $f(0) = 0$, we can also deduce from the above that for any $i \neq j$ we have
$$
f(E_{ij}) = f(E_{i1} E_{1j}) = f(E_{1j} E_{i1}) = f(\delta_{ji} E_{11}) = f(0 E_{11}) = f(0) = 0.
$$
Conclusion: for any matrix $M = (a_{ij})_{i,j=1}^n$ we have
$$
f(M) = f\left(\sum_{i,j=1}^n a_{ij} E_{ij}\right) = \sum_{i,j=1}^n a_{ij} f(E_{ij}) = \sum_{i=1}^n a_{ii} f(E_{ii}) = \sum_{i=1}^n a_{ii} \left( \frac{f(I)}{n}\right) = \frac{f(I)}{n} \operatorname{trace}(M)
$$
so that $f$ is a scalar multiple of the usual trace (= the sum of the diagonal entries).  Since clearly any scalar multiple of the trace has the desired properties, this provides a complete characterization of the set of functions you were looking to describe.