Matrix multiplication is somewhat more complicated than matrix addition because it does not work componentwise, and because the size and the order of the matrices in a matrix multiplication matter.
We define the product of two matrices and only if every row of is as long as each column . So if is an matrix, then needs to be an matrix for certain . If this is the case, then the matrix product is an matrix. The element on the -th row and the -th column in the matrix product is defined as follows:
We can also write the right-hand side of the definition of as the dot product of the -th row vector of and -th column vector of (interpreted as column vectors) or the matrix product of the -th row vector of and -th column vector of (interpreted as matrices):
The product of the matrices and can be visualised as follows: then is the matrix of which the element is the dot product of the magenta coloured row and column of the matrices and :
The definition of the product of matrices finds its inspiration in the writing of linear equations and systems of linear equations. A linear equation can be written as the dot product of vectors and , or as This then appears in matrix notation as It suggests the concept of 'row vector times column vector'.
Similarly we can write a system of linear equations in matrix notation by stitching together linear equations in matrix notation. The system of linear equations with unknowns can be written in matrix notation as
Solving the system of linear equations amounts to finding a column matrix which, when multiplied from the left by the coefficient matrix yields the column matrix . This solving of a system for the given coefficient matrix can be carried out for several column vectors at the same time and can be concisely recorded by replacing and by multiple columns, so in fact by matrices and . This forces a unique choice for : the matrix multiplication in the way it is defined.
If and , thenThis shows that matrix multiplication is not commutative if the sizes are greater than .
Use as many examples as you need to become familiar with the product of matrices.
By way of example, we calculate the matrix coefficient at entry , that is to say, in the first row and second column. To this end we calculate the dot product of the pair of magenta colored row and column vector, the first row in the first factor and the second column in the second factor of the matrix product:
In the same way, the other matrix coefficients can be calculated.
Most calculation rules we already know from the multiplication of numbers, also apply to matrix multiplication, at least if the dimensions of the matrices are such that matrix multiplication is possible. We mention:
The first two lines and the last line follow directly from the definitions. The proof of the third line with the definition of the product matrices is much tedious paperwork.
Thanks to the second rule we can write without parentheses; it does not matter if we calculate this expression as or as . Similarly, the third line enables us to write ; the order in which products are calculated matrix does not matter.
Suppose that is a square matrix. Then, the matrix product exists and this is a symmetric matrix.
Suppose we have random variables and have a sample of data for each random variable such that the sample mean for each random variable is zero. Put these data in an matrix . Then, the sample covariance matrix is a symmetric matrix, and can be written as