# Matrix expression for $\sum_{i<j} A_{i,j} x_i A_{j,i} x_j$

Given the following term: $$\sum_{i

(with $$A$$ a square matrix and $$x$$ a vector) is there a nice explicit matrix expression?

I've tried: $$\sum_{i

as well as the identity $$\sum_{i,j}(A B)_{i,j} = tr(A B)$$.

Although it looks simple, I couldn't find an expression that doesn't involve a $$\sum$$.

• Just a possible idea: Maybe some expression involving $x^\top A x$. Jun 28, 2021 at 10:07

If you allow something like $$D(x)$$ to denote the diagonal matrix with the entries of the column vector $$x$$ on the diagonal, so that $$D(\pmatrix{2\\6}) = \pmatrix{2 & 0 \\ 0 & 6},$$ then your second formula seems to be 90% of the way there --- I think that you get $$S = \frac12 x^t AA^T x - \left(\operatorname{tr}(D(X)A)\right)^2$$ ...if I've managed to read the indices correctly.
• Thank you! But isn't $(tr(D(x) A)^2 = (\sum_i x_i A_{ii})^2 \neq \sum_i x_i^2 A_{ii}^2$ Jul 2, 2021 at 9:00
• Yep --- you're right. You get all the terms on the right, but I managed to ignore all the cross terms of the form $x_iA_{ii} x_j A_{jj}$. Looks to me as if something to do with tensor-products and/or outer products might need to come into play here, and I've never been any good with those, alas. Jul 2, 2021 at 10:02