[Math] Calculating the number of operations in matrix multiplication

linear algebramatrices

Is there a formula to calculate the number of multiplications that take place when multiplying 2 matrices? For example

$$\begin{pmatrix}1&2\\3&4\end{pmatrix}
\times
\begin{pmatrix}5&6\\7&8\end{pmatrix}
=
\text{8 multiplications and 4 additions}
$$

Best Answer

Doing a $k\times l$ times $l\times m$ matrix multiplication in the straightforward way, every entry of the result is a scalar product of of two $l$-vectors, which requires $l$ multiplications and $l-1$ additions. Multiply that by the number $km$ of entries of the result (or don't multiply if you have sufficiently many processors to do everything in parallel).

Related Question