Is there a formula for the product of 3 matrices? That is, if $A \in \mathbb{R}^{m \times n}, B \in \mathbb{R}^{n \times n},$ and $C \in \mathbb{R}^{n \times p}$, and I want the $(i, j)$ entry of the product $D = ABC$, how can I write $D_{i,j}$? I know $(AB)_{i,j} = \sum_{k=1}^na_{ik}b_{kj}$, but I'm not sure if this can be generalized to more than 2 matrices. Thanks for any help.
2 Answers
You can done it for a arbritary number of matrices, the case of tree matrices goes $$(AB)_{i,j} = \sum_{k} A_{i,k} B_{k,j} $$ With some renaming we reach $$ (XY)_{a,b} = \sum_{c} X_{a,c} Y_{c,b} $$ So we replace $X$ with $AB$ $$ ((AB)Y)_{a,b} = \sum_{c} (AB)_{a,c} Y_{c,b} $$ $$ ((AB)Y)_{a,b} = \sum_{c} (\sum_{k} A_{a,k} B_{k,c}) Y_{c,b} $$ After some basic manipulations we get $$ (ABY)_{a,b} = \sum_{c} \sum_{k} A_{a,k} B_{k,c} Y_{c,b} $$ Finally replace $Y$ with $C$ $$ (ABC)_{a,b} = \sum_{c} \sum_{k} A_{a,k} B_{k,c} C_{c,b} $$ So we had derivted our triple matrix formula. (And like this we can generalize for n matrices)
-
1
It would be similar to the 2 matrices case but it involves 2 nested sums. I am not sure if this is very efficient in practice: $$d_{ij} = \sum_u\sum_va_{iu}b_{uv}c_{vj}$$