150. Matrix addition and multiplication

The adjacency matrix of a digraph can be used to compute directed walks from one node to another. This involves the concepts of matrix addition and multiplication, which are described briefly here.

150.1 Definition: scalar product

Let $V$ and $W$ be two $n$-tuples of real numbers. The scalar product $V\cdot W$ is the sum $\Sigma_{i=1}^{n}V_iW_i$.

150.1.1 Example $\langle 3,5,-1,0\rangle\cdot\langle 1,2,3,4\rangle=10$.

150.1.2 Usage The scalar product is also called the “dot” product. You may be familiar with its geometrical meaning when the tuples represent vectors.

150.1.3 Remark The scalar product is only defined for two tuples of the same length. For each positive integer $n$, it is a function $\mathrm{R}^n\times\mathrm{R}^n\to\mathrm{R}$.

150.2 Definition: product of matrices

Let $A$ be a $k\times m$ matrix with real entries, and $B$ an $m\times n$ matrix with real entries; specifically, $A$ has the same number of columns as $B$ has rows. Then the product $AB$ of the matrices is the $k\times n$ matrix whose $\langle i,j\rangle$th entry is the scalar product of the $i$th row of $A$ and the $j$th column of $B$. In other words,

$$(AB)_{ij}=\Sigma_{k=1}^{m}A_{ik}B_{kj} \tag{150.1}$$

150.2.1 Example

$$\begin{pmatrix}1&3&0\\2&2&2\end{pmatrix}\cdot\begin{pmatrix}2&1&0&5\\3&-2&1&-1\\5&1&1&0\end{pmatrix}=\begin{pmatrix}11&-5&3&2\\20&0&4&8\end{pmatrix} \tag{150.2}$$

150.2.2 Fact Matrix multiplication is associative, when it is defined; in other words, for a $k\times m$ matrix $A$, an $m\times n$ matrix $B$ and an $n\times p$ matrix $C$, $(AB)C=A(BC)$. Matrix multiplication is not, however, commutative. There are $n\times n$ matrices $A$ and $B$ for which $AB\neq BA$. (Note that if $AB$ and $BA$ are both defined, then $A$ and $B$ must be square matrices.)

150.2.3 Exercise Give examples of $2\times 2$ matrices showing that matrix multiplication is not commutative.

150.2.4 Exercise Show that matrix multiplication is associative when it is defined.

150.3 Definition: sum of matrices

Let $M$ and $N$ be $m\times n$ matrices. Then the sum $M+N$ is defined by requiring that $(M+N)_{ij}=M_{ij}+N_{ij}$.

150.3.1 Remark Two matrices can be added if and only if they have the same dimensions.

150.3.2 Example

$$\begin{pmatrix}2&5\\3&-3\end{pmatrix}+\begin{pmatrix}7&-1\\5&5\end{pmatrix}=\begin{pmatrix}9&4\\8&2\end{pmatrix} \tag{150.3}$$

150.4 Powers of matrices

In the following, we will use powers of square matrices with integer coefficients. If $M$ is a square $m\times m$ matrix, $M^n$ denotes $M$ multiplied by itself $n-1$ times. This is best defined by induction: $M^0=I$, $M^1=M$, and $M^n=M^{n-1}\cdot M$. It follows from this and Definition 150.2 that

$$(M^n)_{ij}=\Sigma_{k=1}^{m}(M^{n-1})_{ik}M_{kj} \tag{150.4}$$

Pages 227–228 of the book (PDF).