How to Multiply a Matrix by a Matrix
The matrix product AB is defined only when the number of columns in A is equal to the number of rows in B. Similarly, the matrix product BA is defined only when the number of columns in B is equal to the number of rows in A.
Suppose that A is an i x j matrix, and B is a j x k matrix. Then, the matrix product AB results in a matrix C, which has i rows and k columns; and each element in C can be computed according to the following formula.
Cik = Σj AijBjk
where
Cik = the element in row i and column k from matrix C
Aij = the element in row i and column j from matrix A
Bjk = the element in row j and column k from matrix B
Σj = summation sign, which indicates that the aijbjk terms should be summed over j
Let's work through an example to show how the above formula works. Suppose we want to compute AB, given the matrices below.