Skip to main content

Linear Algebra with SageMath: Learn math with open-source software

Section 6.2 Operations With Matrices

Matrix arithmetic extends familiar operations like addition and multiplication to the world of matrices. We will learn how to add, subtract, and multiply matrices, explore properties of these operations, and see how they are used to solve systems of equations, represent compositions of transformations, and work with data in structured ways.
Matrices can be added, multiplied by a number (scalar multiplication), multiplied by a vector or a matrix (matrix multiplication). The first two operations -addition and scalar multiplication- are performed component-wise, similar to the corresponding operations on vectors.
Matrix multiplication is an operation between two matrices where the rows of the first matrix are multiplied (dot product) by the columns of the second matrix to produce the matrix product. For the multiplication to be defined, the number of columns in the first matrix must equal the number of rows in the second matrix. The resulting matrix has the same number of rows as the first matrix and the same number of columns as the second matrix.
In the case of multiplying a matrix by a vector, the vector is treated as a matrix with a single column. The output however is of type Vector and is not of type Matrix.
Note that matrix addition is commutative and associative, meaning that the order of addition does not affect the result. However, matrix multiplication is not commutative; in general, \(AB \neq BA\text{.}\) Matrix multiplication is associative, so \((AB)C = A(BC)\text{,}\) and it distributes over addition: \(A(B + C) = AB + AC\text{.}\) Also, the identity matrix serves as the multiplicative identity for matrices, whereas the zero matrix serves as the additive identity.