# How to express matrix multiplication as the sum of individual elements?

I want to express $$\sum_{i=1}^N \sum_{j=1}^N a_{ij} x_i x_j$$ as matrix/vector multiplication. I've managed to get that the expression above is equal to $$x'Ax$$ where x is a vector, by expanding the sum but it took a while. Is there a faster way, which I can use to calculate it (and also be able to express matrix multiplication as a sum)?

• What could be faster than $$x^\top A x$$ ? Apr 8, 2020 at 12:10
• By the way, you may want to look at the Einstein summation convention, it gives useful notation for these types of calculations Apr 8, 2020 at 12:13
• I might have phrased my question poorly. What I meant is 'how can I look at the summation and instantly tell what the equivalent matrix multiplication is?'. Apr 8, 2020 at 12:47
• Okay, the Einstein summation convention is what I was looking for. Thank you very much! Apr 8, 2020 at 12:48

Yes, it depends upon what value of $$a_{ij}$$ and $$x$$ you are choosing. Relate your question with this example. Suppose $$x_i = 1$$ and $$x_j = 1$$ for every value of $$i$$ and $$j$$ and $$a_{ij} = \frac{a_i a_j }{i+j+1}$$ where $$1\le i,j\le N$$ and $$a_i, a_j \in \Bbb N$$ then $$\sum_{i=1}^N \sum_{j=1}^N a_{ij} x_i x_j = \sum_{i=1}^N \sum_{j=1}^N \frac{a_i a_j }{i+j+1} = \int _{0}^ 1 f(x) f(x)$$ where $$f(x) = a_1x + a_2 x^2 +\cdots a_n x^N$$. You can relate $$x' A x$$ to standard inner product of $$Ax$$ and $$x$$ in real space.