# 1.1.2 Addition and multiplication Matrices can only be added together if they have the same dimensions Addition is carried out element by element, for example: $$ \begin{bmatrix} a & b\\ c & d \end{bmatrix} + \begin{bmatrix} e & f\\ g & h \end{bmatrix} = \begin{bmatrix} a+e & b+f\\ c+g & d+h \end{bmatrix} $$ Matrices of any size can be easily multiplied by a scalar: $$ k \begin{bmatrix} a & b\\ c & d \end{bmatrix} = \begin{bmatrix} ka & kb\\ kc & kd \end{bmatrix} $$ Multiplying two matrices is slightly more complicated, however, demonstrated in the below example $$ \begin{bmatrix} a & b\\ c & d \end{bmatrix} \begin{bmatrix} e & f\\ g & h \end{bmatrix} = \begin{bmatrix} ae+bg & af+bh\\ ce+dg & cf+dh \end{bmatrix} $$ First, the first row of the left matrix is multiplied and summed with the first column of the right matrix to get the element in the first row and first column of the answer Next, the first row is multiplied and summed with the second column to get the element in the first row and second column Then, the same is repeated for the second row This means that the number of rows in the first matrix must equal the number of columns in the second to be multiplied; an n by m matrix can only be multiplied with an n by k matrix, resulting in an m by k product It is important to note that the order of the matrices is important, meaning that the following is different to the first example: $$ \begin{bmatrix} e & f\\ g & h \end{bmatrix} \begin{bmatrix} a & b\\ c & d \end{bmatrix} = \begin{bmatrix} ea+fc & eb+fd\\ ga+hc & gb+hd \end{bmatrix} $$ A general formula exists which can be used to demonstrate matrix multiplication, for: $$ C = AB $$ Where A is m by n and B is n by p, the equation is: $$ c_{ij} = \sum_{k=1}^n a_{ik}b_{kj} $$ The result is an i by j matrix of the sum of the products of elements of A and B, starting with k=1 and ending with k=n