3.2 Basic operations

Transposition

It is often useful to switch the rows and columns of a matrix around. The resulting matrix is called the transpose of the original matrix, and denoted with a superscript ^{\scriptstyle\top} or an apostrophe ':

M=[324112]M=[341212]\mathbf{M}= \left[ \begin{array}{rr} 3 & 2 \\ 4 & -1 \\ -1 & 2 \end{array} \right] \qquad \mathbf{M}^{\scriptstyle\top}=\left[ \begin{array}{rrr} 3 & 4 & -1 \\ 2 & -1 & 2 \end{array} \right]

Note that Mij=MjiM_{ij}=M ^{\scriptstyle\top}_{ji}, and that if M\mathbf{M} is an r×cr \times c matrix, M\mathbf{M}^{\scriptstyle\top} is a c×rc \times r matrix.

Addition

There are two kinds of addition operations for matrices. The first is scalar addition:

M+2=[3+22+24+21+21+22+2]=[546114]\mathbf{M}+ 2 = \left[ \begin{array}{rr} 3+2 & 2+2 \\ 4+2 & -1+2 \\ -1+2 & 2+2 \end{array} \right] = \left[ \begin{array}{rr } 5 & 4 \\ 6 & 1 \\ 1 & 4 \end{array} \right]

The other kind is matrix addition:

M+M=[324112]+[324112]=[648224]\mathbf{M}+ \mathbf{M}= \left[ \begin{array}{rr} 3 & 2 \\ 4 & -1 \\ -1 & 2 \end{array} \right] + \left[ \begin{array}{rr} 3 & 2 \\ 4 & -1 \\ -1 & 2 \end{array} \right]= \left[ \begin{array}{rr} 6 & 4 \\ 8 & -2 \\ -2 & 4 \end{array} \right]

Formally, (A+B)ij=Aij+Bij(\mathbf{A}+\mathbf{B})_{ij} = A_{ij} + B_{ij}.

Note that only matrices of the same dimension can be added to each other – there is no such thing as adding a 4×54 \times 5 matrix to a 2×92 \times 9 matrix.

Multiplication

There are also two common kinds of multiplication for matrices. The first is scalar multiplication:

4M=4[324112]=[12816448]4\mathbf{M}= 4\left[ \begin{array}{rr} 3 & 2 \\ 4 & -1 \\ -1 & 2 \end{array} \right] = \left[ \begin{array}{rr } 12 & 8 \\ 16 & -4 \\ -4 & 8 \end{array} \right]

Formally, (cM)ij=cMij(c\mathbf{M})_{ij} = cM_{ij}.

The other kind is matrix multiplication. The product of two matrices, AB\mathbf{A}\mathbf{B}, is defined by multiplying all of A\mathbf{A}’s rows by B\mathbf{B}’s columns in the following manner:

(AB)ik=jAijBjk(\mathbf{A}\mathbf{B})_{ik} = \sum_j A_{ij}B_{jk}

[121410][320112]=[22129]\left[ \begin{array}{rrr} 1 & 2 & 1 \\ 4 & -1 & 0 \end{array} \right] \left[ \begin{array}{rr} 3 & 2 \\ 0 & -1 \\ -1 & 2 \end{array} \right]= \left[ \begin{array}{rr} 2 & 2 \\ 12 & 9 \end{array} \right]

Note that matrix multiplication is only defined if the number of columns of A\mathbf{A} matches the number of rows of B\mathbf{B}, and that if A\mathbf{A} is an m×nm \times n matrix and B\mathbf{B} is an n×pn \times p matrix, then AB\mathbf{A}\mathbf{B} is an m×pm \times p matrix.

The following elementary algebra rules carry over to matrix algebra:

A+B=B+A(A+B)+C=A+(B+C)(AB)C=A(BC)A(B+C)=AB+ACk(A+B)=kA+kB\begin{align*} \mathbf{A}+\mathbf{B}&= \mathbf{B}+\mathbf{A}& (\mathbf{A}+\mathbf{B})+\mathbf{C}&=\mathbf{A}+(\mathbf{B}+\mathbf{C}) \\ (\mathbf{A}\mathbf{B})\mathbf{C}&= \mathbf{A}(\mathbf{B}\mathbf{C}) & \mathbf{A}(\mathbf{B}+\mathbf{C})&=\mathbf{A}\mathbf{B}+\mathbf{A}\mathbf{C}\\ k(\mathbf{A}+\mathbf{B}) &= k\mathbf{A}+k\mathbf{B} \end{align*}

One important exception, however, is that ABBA\mathbf{A}\mathbf{B}\neq \mathbf{B}\mathbf{A}; the order of matrix multiplication matters, and we must remember to, for instance, “left multiply” both sides of an equation by a matrix M\mathbf{M} to preserve equality.

Inner and outer products

Suppose u\mathbf{u} and v\mathbf{v} are two n×1n \times 1 vectors. We can’t multiply them in the sense defined above, uv\mathbf{u}\mathbf{v}, because the number of columns of u\mathbf{u}, 1, doesn’t match the number of rows of v\mathbf{v}, n. However, there are two ways in which vectors of the same dimension can be multiplied.

The first is called the inner product (also, the “cross product”):

uv=jujvj[32][21]=62=4.\begin{align*} \mathbf{u}^{\scriptstyle\top}\mathbf{v}&= \sum_j u_j v_j \\ \left[\begin{array}{rr} 3 & 2 \end{array} \right] \left[\begin{array}{r} 2 \\ -1 \end{array}\right] &= 6 - 2 = 4. \end{align*}

Note that when we multiply matrices, the element (AB)ij(\mathbf{A}\mathbf{B})_{ij} is equal to the inner product of the ith row of A\mathbf{A} and the jth column of BB.

The second way of multiplying two vectors is called the outer product:

(uv)ij=uivj[32][21]=[6342]\begin{align*} (\mathbf{u}\mathbf{v}^{\scriptstyle\top})_{ij} &= u_i v_j \\ \left[\begin{array}{r} 3 \\ 2 \end{array} \right] \left[\begin{array}{rr} 2 & -1 \end{array}\right] &= \left[\begin{array}{rr} 6 & -3 \\ 4 & -2 \end{array}\right] \end{align*}

Note that the inner product returns a scalar number, while the outer product returns an n×nn \times n matrix.