# Trace of a matrix product

For an arbitrary matrix $A$ and a given matrix $B$, is is possible to generate a matrix $C$ such that

$\text{Trace}(ABC) = \text{Trace}(AB)$

barring the trivial identity case?

If not in the general case, is it possible if $B$ is symmetric? Entries in all the matrices are real. Any tips are appreciated

• As you have worded it, $C$ is allowed to depend on $A$. Is this so, or you mean $C$ to be the same for all $A$? Commented Feb 16, 2018 at 8:41
• I do not know what $A$ is. Basically, I have a black box which given a B, returns a vector which depends on $A$ and a bunch of other parameters, all of which are unknown to me. The dependence on $A$ is only through a term of the form Trace($AB$). I know that if Trace($AB$) is preserved, the vector will always be the same. I am wondering if it is possible to feed in a different matrix ($BC$) to obtain the same answer from the black box
– Sid
Commented Feb 16, 2018 at 8:52
• @ancientmathematician I've just considered both cases in my answer... Commented Feb 16, 2018 at 9:28

1) If we want the same $C$ for all $A$:
1.a) If $B$ is singular ($\det(B)=0$) then there exists a matrix $V$ such that $BV=0$ ($B$ has $0$ as eigenvalue; pick $V=(v\ v \ \ldots \ v)$ with $v$ an eigenvector for $0$). Then with $C:=I+V$ we have $$\text{trace}(AB(I+V))=\text{trace}(ABI)+\text{trace}(ABV)=\text{trace}(AB).$$
1.b) If $B$ is regular it is impossible. Consider $A:=XB^{-1}$ with $X$ any matrix. Then $$\text{trace}(XC)=\text{trace}(ABC)=\text{trace}(AB)=\text{trace}(X),$$ so $\sum_{i=1}^n\sum_{j=1}^n x_{ij}c_{ji} - \sum_{i=1}^n x_{ii}=0$ for every matrix $X$, which implies $C=I$ by considering the elementary matrices $X=E_{ij}$.
2) If we allow $C$ to depend on $A$:
If the diagonal of $AB$ is not full of zeros then we can always choose a diagonal $D\neq I$ such that trace$(ABD)=$trace$(AB)$. For example, if $AB_{n,n}\neq 0$ pick $D=$diag$(0,\ldots,0,$trace$(AB))$. Otherwise, pick $P$ invertible such that $PABP^{-1}$ has some nonzero diagonal element and pick $D$ for this matrix. Then, with $C:=P^{-1}DP$, $$\text{trace}(ABP^{-1}DP)=\text{trace}(PABP^{-1}D)=\text{trace}(PABP^{-1})=\text{trace}(AB).$$