 # 10. Operations on matrices

We will use the following operations of matrices:

To add two matrices they need to have the same size. We add matrices by their coefficients, e.g.: Addition of matrices is associative and commutative, so for any matrices , and .

### Multiplying a matrix by a scalar

Simply by coefficients, e.g: Because of those operations it is easy to see that the set of matrices of given size is a linear space.

### Matrix multiplication

To multiply matrices, the first has to have the same number of columns as the second one of rows. The resulting matrix will have as many rows as the first one, and as many columns as the second one. We multiply the rows of the first matrix by the columns of the second in the sense that in the resulting matrix in a place in -th row and -th column we write the result of multiplication of -th row of the first matrix with the -th column of the second one, where by multiplication of row and column we mean multiplication of pairs of subsequent numbers summed up. E.g.:   Matrix multiplication is associative, which means that for any , . But is not commutative! Notice that if the matrices are not square it is impossible to multiply them conversely. If they are square the result may be different.

### Operations on rows of a matrix and multiplication of matrices

It is worth noticing that the standard operations on rows of matrices can be encoded as multiplication by some special matrices.

Let be a matrix, where the element in the -th row and -th column equals to , if , when and otherwise.

Let be a matrix, where the element in the -th row and -th column equals to if or or and otherwise.

Let be a matrix, where the element in the -th row and -th column equals to , if , , when and zero otherwise.

In other words, is the identity matrix with an additional in -th row and -th column, is the identity matrix after swapping -th and -th rows, and is the identity matrix where the element on the diagonal in -th row is changed to instead of .

It is easy to check that given a matrix ,

• matrix is a matrix obtained from by adding to the -th row -th row multiplied by ,
• matrix is a matrix obtained from by swapping -th row with the -th row,
• matrix is a matrix obtained from by multiplication of the -th row by ,
• matrix is a matrix obtained from by adding to the -th column -th column multiplied by ,
• matrix is a matrix obtained from by swapping -th column with the -th column,
• matrix is a matrix obtained from by multiplication of the -th column by ,