# Sum of products of elements in matrix form.

Suppose I have two matrices $\textbf{A}$, and $\textbf{B}$ as follows:

$\begin{array}{c=c} \textbf{A} = \left[ \begin{array}{ccc} a_{11} & a_{12} & a_{13}\\ a_{21} & a_{22} & a_{23}\\ a_{31} & a_{32} & a_{33}\\ \end{array}\right] \end{array}$ , and $\begin{array}{c=c} \textbf{B} = \left[ \begin{array}{ccc} b_{11} & b_{12} & b_{13}\\ b_{21} & b_{22} & b_{23}\\ b_{31} & b_{32} & b_{33}\\ \end{array}\right] \end{array}$

I am looking for a way to write, in matrix language, this operation:

$(a_{11}b_{11}+a_{12}b_{21}+a_{13}b_{31})+(a_{21}b_{12}+a_{22}b_{22}+a_{23}b_{32})+(a_{31}b_{13}+a_{32}b_{23}+a_{33}b_{33})=k$

The matrices can be rectangular in such a way that $\textbf{A}$ can of mxn dimension and $\textbf{B}$ can be of nxm dimension. If this is possible, I would be grateful for a clue.

Thanks.

if $C = A B$ is the matrix product, then the elements are $c_{i,j} = \sum_k a_{i,k} b_{k,j}$. Then the trace of $C$ will be
$Tr(C) = \sum_k c_{k,k} = \sum_k \Big( \sum_l a_{k,l}b_{l,k}\Big)$