Let $A \in \mathbb{R}^{n_2 \times n_1}, B \in \mathbb{R}^{n_2 \times n_3}, C \in \mathbb{R}^{n_1 \times n_3}$ be matrices. Define:

$$S_j = \sum_{k=j}^{n_3} \sum_{i=1}^{n_1} C_{ik} (A_i - B_k)$$

for $j=1, \dots, n_3$, where $C_{ik}$ is the $ik$-th element of $C$, $A_i$ is the $i$-th column of $A$ and $B_k$ is the $k$-th column of $B$. I am wondering how to write the matrix

$$S = (S_1 \dots S_{n_3})$$

as a product of matrices, rather than the double summation above. I am asking because I need to compute $S$ in a program. For optimization purposes, it would be best to write it as a matrix product.

My attempts so far have involved the following transformation matrix:

$$\Lambda = \begin{pmatrix} 1 & 0 & 0 & \dots & 0 \\ 1 & 1 & 0 & \dots & 0 \\ 1 & 1 & 1 & \dots & 0 \\ & && \ddots \\ 1 & 1 & 1 & \dots & 1 \end{pmatrix}.$$

I am able to write

$$\left(\sum_{k=1}^{n_3} \sum_{i=1}^{n_1} C_{ik} A_i , \dots, \sum_{k=n_3}^{n_3} \sum_{i=1}^{n_1} C_{ik} A_i \right) = A C \Lambda^T$$

which solves half the problem. However, I do not see a way to write

$$\left(\sum_{k=1}^{n_3} \sum_{i=1}^{n_1} C_{ik} B_k , \dots, \sum_{k=n_3}^{n_3} \sum_{i=1}^{n_1} C_{ik} B_k \right).$$

Thank you in advance for any suggestions.


Note that $(\sum_{i=1}^{n_1} C_{i1}B_1,\dots,\sum_{i=1}^{n_1} C_{in_3}B_{n_3}) = BC^T$. So, your matrix can be written as $$ \left(\sum_{k=1}^{n_3}[BC^T]_k, \dots, \sum_{k=n_3}^{n_3}[BC^T]_k\right) $$ Conclude that the desired matrix is in fact $(BC^T)\Lambda_{n_1}$. All together, your matrix is $S = AC\Lambda_{n_3}^T - BC^T\Lambda_{n_1}$.

  • $\begingroup$ Thanks for your answer. If I'm not mistaken, there is a dimension mismatch: $B C^T \Lambda_{n_1}$ has size $n_2 \times n_1$ but $AC\Lambda_{n_3}^T$ has size $n_2 \times n_3$. $\endgroup$ – atzol May 23 '17 at 17:21
  • $\begingroup$ Thank you also for correcting the first term. $A$ indeed does not require a transpose. I edited my post accordingly. $\endgroup$ – atzol May 23 '17 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.