Skip to main content

Linear Algebra with SageMath Learn math with open-source software

Section 6.2 Operations With Matrices

Matrices can be added, multiplied by a scalar (scalar multiplication), or multiplied with other matrices (matrix multiplication). Addition and scalar multiplication are performed element-wise, analogous to the corresponding operations on vectors. Let \(A = \begin{bmatrix} a_{ij} \end{bmatrix}\) and \(B = \begin{bmatrix} b_{ij} \end{bmatrix}\) be \(m\times n\) matrices.
\begin{equation*} A + B = \begin{bmatrix} a_{ij} + b_{ij} \end{bmatrix} \end{equation*}
\begin{equation*} A - B = \begin{bmatrix} a_{ij} - b_{ij} \end{bmatrix} \end{equation*}
\begin{equation*} kA = \begin{bmatrix} ka_{ij} \end{bmatrix} \end{equation*}
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. Let \(C = \begin{bmatrix} c_{ij} \end{bmatrix}\) be an \(m\times p\) matrix and \(D = \begin{bmatrix} d_{ij} \end{bmatrix}\) be a \(p\times n\) matrix.
\begin{equation*} CD = \begin{bmatrix} d_{ij} \end{bmatrix} \end{equation*}
where \(d_{ij} = \sum_{k=1}^p c_{ik}d_{kj}\text{.}\)
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.