Skip to main content

Applied Mathematics

Section 2.2 Matrix Operations

Subsection 2.2.1 Addition and Subtraction of Matrices

In this section, we learn how to perform some basic operations between matrices. First, we will look at adding and subtracting two matrices and later we will look at multiplying a matrix by a scalar (a number).

Definition 2.2.1.

In this case, let \(A\) and \(B\) be \(m \times n\) matrices. Then
  1. \(A+B\) is the matrix formed by
    \begin{equation*} [a_{ij}]+[b_{ij}] = [a_{ij}+b_{ij}] \end{equation*}
    That is to add matrices, we add element by element.
  2. \(A-B\) is the matrix formed by
    \begin{equation*} [a_{ij}]-[b_{ij}] = [a_{ij}-b_{ij}] \end{equation*}
    That is to add matrices, we subtract element by element.
If \(A\) and \(B\) are not the same size then \(A+B\) and \(A-B\) does not exist.
Note: an alternative definition of matrix subtraction, \(A-B=A+(-B)\text{,}\) which is consistent with subtraction of real numbers. We will define \(-B\) later in this chapter.

Example 2.2.2.

Let
\begin{align*} A \amp = \begin{bmatrix} 1 \amp -1 \amp 3 \\ 2 \amp 7 \amp 3 \end{bmatrix} \amp B \amp = \begin{bmatrix} 3 \amp 2 \amp -7 \\ 11 \amp 2 \amp 0 \end{bmatrix} \end{align*}
Then the sum \(A+B\) is found by adding the individual elements.
\begin{align*} A+B \amp = \begin{bmatrix} 1+3 \amp -2+2 \amp 3-7\\ 2+11 \amp 7+2 \amp 3+0 \end{bmatrix}= \begin{bmatrix} 4 \amp 1 \amp -4 \\ 13 \amp 9 \amp 3 \end{bmatrix} \end{align*}
similarly we can subtract in the same way
\begin{align*} A-B \amp = \begin{bmatrix} 1-3 \amp -1-2 \amp 3-(-7)\\ 2-11 \amp 7-2 \amp 3-0 \end{bmatrix}= \begin{bmatrix} -2 \amp -3 \amp 10 \\ -9 \amp 5 \amp 3 \end{bmatrix} \end{align*}

Example 2.2.3.

Find the following result or state that it does not exist.
\begin{equation*} \begin{bmatrix} 1 \amp 0 \\ 3 \amp -2 \end{bmatrix} + \begin{bmatrix} 3 \amp -2 \\ 5 \amp 0 \\ -3 \amp 4 \end{bmatrix} \end{equation*}
Solution.
Since the matrices are not the same size, this operation is not valid.
There are many properties of matrix operations and they will look familiar in relation to real numbers.

Proof.

We will prove the first property: Commutative Law: \(A+B=B+A\text{.}\) Start with the left hand side and get to the right hand side.
\begin{align*} A + B \amp =[a_{ij}] + [b_{ij}] \amp\amp\text{definition of the matrix}\\ \amp = [a_{ij}+b_{ij}] \amp\amp \text{sum of matrices} \\ \amp = [b_{ij}+a_{ij}] \amp\amp\text{use commutative law of numbers} \\ \amp = [b_{ij}] + [a_{ij}] \amp\amp \text{sum of matrices} \\ \amp = B + A \amp\amp\text{definition of matrix} \end{align*}
Note that we have used the notation that \(A=[a_{ij}]\) through this proof. This shorthand notation makes it easier to write matrices and provide proofs.

Subsection 2.2.2 Scalar Multiplication of Vectors and Matrices

Scalar multiplication of vectors and matrices is a simple operation where the result is the scalar times each element of the vector or matrix.

Definition 2.2.5.

Let
\begin{equation*} A=[a_{ij}]\text{,} \end{equation*}
then
\begin{equation*} kA=[ka_{ij}] \end{equation*}

Example 2.2.6.

The following are properties of scalar multiplication

Proof.

This is a proof of the first property (Distributive Law over Matrix Addition)
\begin{align*} p(A+B) \amp = p ([a_{ij}] + [b_{ij}]) \amp\amp \text{definition of the matrix} \\ \amp = p [a_{ij}+b_{ij}]\amp\amp\text{definition of the sum} \\ \amp = [p(a_{ij}+b_{ij})] \amp\amp \text{definition of scalar multiplication} \\ \amp = [pa_{ij} + pb_{ij}] \amp\amp\text{distributive property of numbers}\\ \amp = [pa_{ij}] +[pb_{ij}] \amp\amp \text{sum of matrices} \\ \amp = p [a_{ij}] + p[b_{ij}] \amp\amp \text{definition of scalar multiplication} \\ \amp = pA + pB \amp\amp \text{definition of the matrix} \amp \end{align*}

Subsection 2.2.3 Reexamining Linear Systems

The next matrix operation is that of multiplication. We will take a look back at linear systems to motivate why multiplication works the way it does. Consider the following linear system.
\begin{align*} 3 x + 2y - z \amp = 10, \\ x - 2y + z \amp = 11, \\ 2x - 2y + 4z \amp = 5. \end{align*}
We can write this system as the vector equation
\begin{equation*} \begin{bmatrix} 3x+2y-z \\ x-2y+z \\ 2x-2y+4z \end{bmatrix} = \begin{bmatrix} 10 \\ 11 \\ 5 \end{bmatrix} \end{equation*}
and then separate the left hand side as the sum of three vectors:
\begin{equation*} \begin{bmatrix} 3x \\ x \\ 2x \end{bmatrix} + \begin{bmatrix} 2y \\ -2y \\ -2y \end{bmatrix} + \begin{bmatrix} -z \\ z \\ 4z \end{bmatrix} = \begin{bmatrix} 10 \\ 11 \\ 5 \end{bmatrix} \end{equation*}
And then using scalar multiplication, we get the following
\begin{equation*} x\begin{bmatrix} 3 \\ 1 \\ 2 \end{bmatrix} + y\begin{bmatrix} 2 \\ -2 \\ -2 \end{bmatrix} + z\begin{bmatrix} -1 \\ 1 \\ 4 \end{bmatrix} = \begin{bmatrix} 10 \\ 11 \\ 5 \end{bmatrix} \end{equation*}
If we let
\begin{equation*} A = \begin{bmatrix} 3 \amp 2 \amp -1 \\ 1 \amp -2 \amp 1 \\ 2 \amp -2 \amp 4 \end{bmatrix} \end{equation*}
be the coefficient matrix of the linear system then it seems natural if
\begin{equation*} \vec{u} =\begin{bmatrix} x \\ y \\ z \end{bmatrix} \end{equation*}
Then if we define the matrix multiplication
\begin{equation*} A \vec{u} = \begin{bmatrix} 3 \amp 2 \amp -1 \\ 1 \amp -2 \amp 1 \\ 2 \amp -2 \amp 4 \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} 3x+2y-z \\ x-2y+z \\ 2x-2y+4z \end{bmatrix} \end{equation*}
\begin{equation*} A\vec{u}=\vec{b} \end{equation*}
In the next section we will learn a way to solve a linear system in this way using an alternative method to Gauss’ method.

Subsection 2.2.4 Matrix-Vector Product

Using the motivation of the previous section, we now define a general matrix-vector product

Definition 2.2.8. Matrix-Vector Product.

Let \(A=[a_{ij}]\) be an \(m \times n\) matrix and \(\vec{x}\) be a column vector of length \(n\) with entries \([x_j]\text{.}\) Let \(\vec{a}_j\) be the column vectors of \(A\) or
\begin{align*} A \amp = \begin{bmatrix} \vec{a}_1 \amp \vec{a}_2 \amp \cdots \amp \vec{a}_n \end{bmatrix} \amp \vec{x} \amp = \begin{bmatrix} x_1 \\ x_2 \\ \cdots \\ x_n \end{bmatrix} \end{align*}
The product \(A \vec{x}\) is the column vector of length \(m\text{:}\)
\begin{equation*} A \vec{x} = x_1 \vec{a}_1 + x_2 \vec{a}_2 + \cdots + x_n \vec{a}_n = \sum_{j=1}^n x_j \vec{a}_j \end{equation*}

Example 2.2.9.

\begin{align*} A \amp = \begin{bmatrix} 8 \amp 2 \amp -2 \amp 3 \\ 1 \amp 0 \amp 3 \amp 0 \\ 0 \amp 4 \amp -1 \amp -3 \end{bmatrix} \amp\text{and} \amp\amp \vec{x} \amp = \begin{bmatrix} 3 \\ 0 \\ -2 \\ -4 \end{bmatrix} \end{align*}
Find \(A\vec{x}\text{.}\)
Solution.
\begin{align*} A \vec{x} \amp = 3 \begin{bmatrix} 8 \\ 1 \\ 0 \end{bmatrix}+ 0 \begin{bmatrix} 2 \\ 0 \\ 4 \end{bmatrix} + (-2) \begin{bmatrix} -2 \\ 3 \\-1 \end{bmatrix} + (-4) \begin{bmatrix} 3 \\ 0 \\ -3 \end{bmatrix} \\ \amp = \begin{bmatrix} 3(8) + 0 (2) + (-2)(-2) + (-4)(3) \\ 3(1) + 0(0) + (-2)(3) + (-4)(0) \\ 3(0) + 0(4) + (-2)(-1) + (-4)(-3) \end{bmatrix} = \begin{bmatrix} 16 \\ -3 \\ 14 \end{bmatrix} \end{align*}

Definition 2.2.10. Matrix Form of a Linear System.

Consider the linear system:
\begin{align*} a_{1,1} x_1 + a_{1,2} x_2 + \cdots + a_{1,n} x_n \amp = b_1 , \\ a_{2,1} x_1 + a_{2,2} x_2 + \cdots + a_{2,n} x_n \amp = b_2, \\ \vdots \amp = \vdots \\ a_{m,1} x_1 + a_{m,2} x_2 + \cdots + a_{m,n} x_n \amp = b_m, \end{align*}
The matrix form of the linear system is given by
\begin{equation*} \begin{bmatrix} a_{11} \amp a_{12} \amp \cdots \amp a_{1n} \\ a_{21} \amp a_{22} \amp \cdots \amp a_{2n} \\ \cdots \amp \cdots \amp \ddots \amp \vdots \\ a_{m1} \amp a_{m2} \amp \cdots \amp a_{mn} \\ \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix} = \begin{bmatrix} b_1 \\ b_2 \\ \vdots \\ b_n \end{bmatrix} \end{equation*}
\begin{equation*} A \vec{x} = \vec{b} \end{equation*}

Subsection 2.2.5 Matrix-Matrix Product

This now leads naturally to the following definition of a matrix multiplication \(AB\) is naturally the matrix formed by multiplying \(A\) be each of the columns of \(b\text{.}\)

Definition 2.2.11.

Let \(A\) be a \(m \times n\) matrix and \(B\) be a \(n \times p\) matrix of the form:
\begin{equation*} B = \begin{bmatrix} \vec{b}_1 \amp \vec{b}_2 \amp \cdots \amp \vec{b}_p \end{bmatrix} \end{equation*}
where \(\vec{b}_1, \vec{b}_2, \cdots, \vec{b}_p\) are the columns of \(B\text{.}\) The matrix product \(AB\) is the \(n \times p\) matrix defined as
\begin{equation*} AB = A \begin{bmatrix} \vec{b}_1 \amp \vec{b}_2 \amp \cdots \amp \vec{b}_p \end{bmatrix} =\begin{bmatrix} A\vec{b}_1 \amp A\vec{b}_2 \amp \cdots \amp A\vec{b}_p \end{bmatrix} \end{equation*}
Note: if the number of columns of \(A\) does not equal the number of rows of \(B\text{,}\) then the product is undefined.

Subsubsection 2.2.5.1 Size Restrictions on Matrices

Note that for each element in the resulting matrix, there is a vector-vector product, coming from each row of the first matrix and each column of the second matrix:
Remark 2.2.12.
The number of columns of the first matrix must equal the number of rows of the second matrix.
The size of the resulting matrix can also be found by the sizes of the input matrices.
Remark 2.2.13.
If the matrices \(A\) and \(B\) are multiplied then this diagram helps with a valid product as well as the size of the result.
Figure 2.2.14. Diagram of valid dimensions for matrix product.
That is if \(A\) is \(m\) by \(n\) and \(B\) is \(n\) by \(p\text{,}\) then \(C=AB\) has size \(m\) by \(p\text{.}\)
Example 2.2.15.
Let \(A\) be a matrix that is 2 by 3, \(B\) be a matrix that is 3 by 3 and \(C\) be a matrix that is 2 by 2. Determine which of the following products are valid and if the product is valid, list its size.
  1. \(\displaystyle AB\)
  2. \(\displaystyle AC\)
  3. \(\displaystyle BC\)
  4. \(\displaystyle BA\)
  5. \(\displaystyle CA\)
  6. \(\displaystyle CAB\)
Solution.
  1. Since \(A\) is 2 by 3 and \(B\) is 3 by 3, the inner numbers are equal and thus multiplication is valid and the result is 2 by 3.
  2. Since \(A\) is 2 by 3 and \(C\) is 2 by 2, the inner numbers are not equal, so multiplication is not valid.
  3. Since \(B\) is 3 by 3 and \(C\) is 2 by 2, the inner numbers are not equal, so multiplication is not valid.
  4. Since \(B\) is 3 by 3 and \(A\) is 2 by 3, the inner numbers are not equal, so multiplication is not valid.
  5. Since \(C\) is 2 by 2 and \(A\) is 2 by 3, the inner numbers are equal so multiplication is valid and the result are the outer numbers or 2 by 3.
  6. In this case, from (e), the size of \(CA\) is 2 by 3 and \(B\) is 3 by 3, so the inner numbers are equal so multiplication is valid and the result is 2 by 3.
Example 2.2.16.
\begin{align*} A \amp = \begin{bmatrix} 2 \amp 0 \\ 3 \amp -1 \\ -3 \amp 5 \end{bmatrix} \amp B\amp = \begin{bmatrix} 3 \amp -1 \\ 2 \amp 2 \end{bmatrix} \end{align*}
find \(AB\) if this is a valid operation.
Solution.
The size of \(A\) is 3 by 2 and the size of \(B\) is 2 by 2, so the inner numbers are equal and thus this operations is valid. The size of the result is 3 by 2.
\begin{align*} AB \amp = \begin{bmatrix} \begin{bmatrix} 2 \amp 0 \end{bmatrix} \begin{bmatrix} 3 \\ 2 \end{bmatrix} \amp \begin{bmatrix} 2 \amp 0 \end{bmatrix} \begin{bmatrix} -1 \\ 2 \end{bmatrix} \\[8pt] \begin{bmatrix} 3 \amp -1 \end{bmatrix} \begin{bmatrix} 3 \\ 2 \end{bmatrix} \amp \begin{bmatrix} 3 \amp -1 \end{bmatrix} \begin{bmatrix} -1 \\ 2 \end{bmatrix} \\[8pt] \begin{bmatrix} -3 \amp 5 \end{bmatrix} \begin{bmatrix} 3 \\ 2 \end{bmatrix} \amp \begin{bmatrix} -3 \amp 5 \end{bmatrix} \begin{bmatrix} -1 \\ 2 \end{bmatrix} \end{bmatrix} \\ \amp = \begin{bmatrix} (2)(3) + (0)(2) \amp (2)(-1)+(0)(2) \\ (3)(3) + (-1)(2) \amp (3)(-1) +(-1)(2) \\ (-3)(3) + (5)(2) \amp (-3)(-1) +(5)(2) \end{bmatrix} = \begin{bmatrix} 6 \amp -2 \\ 7 \amp -5 \\ 1 \amp 13 \end{bmatrix} \end{align*}
Example 2.2.17.
Find \(C=AB\) if
\begin{align*} A \amp = \begin{bmatrix} 2 \amp -1 \amp 3 \\ 1 \amp 1 \amp 2 \end{bmatrix} \amp B \amp = \begin{bmatrix} 2 \amp 1 \\ 3 \amp -2 \\ 7 \amp 5 \end{bmatrix} \end{align*}
Solution.
First, since the number of rows of \(A\) is 2 and the number of columns of \(B\) is 2, the size of \(C\) is 2.
  1. The 1st row and 1st column of \(C\) is the 1st row of \(A\) times the 1st column of \(B\text{.}\)
  2. The 1st row and 2nd column of \(C\) is the 1st row of \(A\) times the 2nd column of \(B\text{.}\)
  3. The 2nd row and 1st column of \(C\) is the 2nd row of \(A\) times the 1st column of \(B\text{.}\)
  4. The 2nd row and 2nd column of \(C\) is the 2nd row of \(A\) times the 2nd column of \(B\text{.}\)
We now explicitly show the dot products.
\begin{align*} C \amp = \begin{bmatrix} \begin{bmatrix} 2 \amp -1 \amp 3 \end{bmatrix} \begin{bmatrix} 2 \\ 3 \\ 7 \end{bmatrix} \amp \begin{bmatrix} 2 \amp -1 \amp 3 \end{bmatrix} \begin{bmatrix} 1 \\ -2 \\ 5 \end{bmatrix} \\ \begin{bmatrix} 1 \amp 1 \amp 2 \end{bmatrix} \begin{bmatrix} 2 \\ 3 \\ 7 \end{bmatrix} \amp \begin{bmatrix} 1 \amp 1 \amp 2 \end{bmatrix} \begin{bmatrix} 1 \\ -2 \\ 5 \end{bmatrix} \end{bmatrix}\\ \amp = \begin{bmatrix} 2(2) + (-1)(3) + 3(7) \amp (2)(1) + (-1)(-2) + (3)(5) \\ (1)(2) + (1)(3) +(2)(7) \amp (1)(1) + (1)(-2) + (2)(5) \end{bmatrix} \\ \amp = \begin{bmatrix} 22 \amp 19 \\ 19 \amp 9 \end{bmatrix} \end{align*}

Subsubsection 2.2.5.2 Alternative Form of the Matrix-Matrix Product

An alternative form of the matrix-matrix product \(AB\) is
\begin{equation*} (AB)_{ij} = \text{$i$th row of $A$} \cdot \text{$j$th column of $B$}. \end{equation*}
\begin{equation*} [(ab)_{ij}] = \bigl[\sum_k a_{ik}b_{kj}\bigr] \end{equation*}
This form is both helpful for proofs as we will see below as well as an alternative way to compute the matrix product.
Example 2.2.18.
Find, if possible, \(AB\) if
\begin{align*} A \amp \begin{bmatrix} -3 \amp 0 \amp 2 \\ 1 \amp 4 \amp -2 \\ 0 \amp 3 \amp 1 \end{bmatrix} \amp B \amp = \begin{bmatrix} 3 \amp 2 \\ -2 \amp0 \\ 1 \amp 3 \end{bmatrix} \end{align*}
Solution.
First, from the sizes of \(A\) and \(B\text{,}\) we know that the size of the product must be \(3 \times 2\text{.}\) For each element of the product matrix, we take the product of the \(i\)th row of \(A\) and \(j\)th column of \(B\text{.}\)
\begin{align*} \begin{bmatrix} \begin{bmatrix} -3 \amp 0 \amp 2\end{bmatrix} \begin{bmatrix} 3 \\ -2 \\ 1 \end{bmatrix} \amp \begin{bmatrix} -3 \amp 0 \amp 2\end{bmatrix} \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix} \\ \begin{bmatrix} 1 \amp 4 \amp -2\end{bmatrix} \begin{bmatrix} 3 \\ -2 \\ 1 \end{bmatrix} \amp \begin{bmatrix} 1 \amp 4 \amp -2\end{bmatrix} \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix} \\ \begin{bmatrix} 0 \amp 3 \amp 1\end{bmatrix} \begin{bmatrix} 3 \\ -2 \\ 1 \end{bmatrix} \amp \begin{bmatrix} 0 \amp 3 \amp 1\end{bmatrix} \begin{bmatrix} 2 \\ 0 \\ 3 \end{bmatrix} \end{bmatrix} \amp = \begin{bmatrix} (-9)+0+2 \amp -6 + 0 + 6 \\ 3-8-2 \amp 2 + 0 -6 \\ 0 -6 +1 \amp 0 + 0 + 3 \end{bmatrix} \\ \amp = \begin{bmatrix} -7 \amp 0 \\ -7 \amp -4 \\ -5 \amp 3 \end{bmatrix} \end{align*}

Subsubsection 2.2.5.3 Properties of Matrix-Matrix Products

\begin{align*} A \amp = \begin{bmatrix} 2 \amp 0 \\ 3 \amp 1 \end{bmatrix}\amp B \amp = \begin{bmatrix} -3 \amp 1 \\ 0 \amp 4 \end{bmatrix} \end{align*}
Note that
\begin{align*} AB \amp = \begin{bmatrix} -6 \amp 2 \\ -9 \amp 7 \end{bmatrix}\amp BA \amp = \begin{bmatrix} -3 \amp 1 \\ 12 \amp 4 \end{bmatrix} \end{align*}
which shows that the commutative property does not hold.
Proof.
The proof of the first uses Definition ... of matrix multiply.
\begin{align*} A(r B + s C) \amp = [(A(rB+sC))_{ij}] \\ \amp = [\sum_k a_{ik} (rB+sC)_{kj}] \\ \amp = [\sum_k a_{ik} (r b_{kj} + s c_{kj}) ]\\ \amp = [r \sum_k a_{ik} b_{kj} + s \sum_k a_{i,k} c_{kj}] \\ \amp = r [(AB)_{ij}] + s [(AC)_{ij}] \\ \amp = r AB + s AC \end{align*}

Subsection 2.2.6 Transpose

The last basic matrix operation that we will cover here in the transpose of a matrix. As an example, if
\begin{equation*} A = \begin{bmatrix} 3 \amp -1 \amp 0 \\ 2 \amp 7 \amp 5 \end{bmatrix} \end{equation*}
then the transpose is the matrix, \(A^{\intercal}\) given by
\begin{equation*} A^{\intercal} = \begin{bmatrix} 3 \amp 2 \\ -1 \amp 7 \\ 0 \amp 5 \end{bmatrix} \end{equation*}
where the row and column of each element is flipped.

Definition 2.2.20.

The transpose of an \(m \times n\) matrix \(A\text{,}\) denoted \(A^{\intercal}\) is \(A\) flipped over the diagonal. In particular, the element in the \(i\)th row and \(j\)th column of \(A^{\intercal}\) is given by the \(j\)th row and \(i\) column of \(A\text{.}\)
Using the shorthand notation,
\begin{equation*} [a_{ij}]^{\intercal} = [a_{ji}] \end{equation*}
which is useful for proofs.
We will see that transposes play a big role in linear algebra.

Proof.

Proof of the 2nd property:
\begin{align*} (AB)^T \amp = [(AB)_{ij}]^T \qquad\text{definition of matrix}\\ \amp = [(AB)_{ji}] \qquad\text{definition of transpose}\\ \amp = \left[\sum_k a_{jk} b_{ki}\right] \qquad \text{product of matrices} \\ \amp = \left[\sum_k b_{ki} a_{jk}\right] \qquad \text{commuting numbers}\\ \amp = \left[(B^T A^T)_{ij} \right] \qquad\text{definition of matrix product} \\ \amp = B^T A^T \qquad\text{definition of matrix} \end{align*}

Subsection 2.2.7 Reexamination of the Dot Product

Recall that the dot product of two vectors \(\vec{u}\) and \(\vec{v}\) of the same length discussed in SubsectionΒ 1.6.8 is the sum of the products of the individual elements.
We can see that the dot product can also be defined as
\begin{equation*} \vec{u} \cdot \vec{v} = \vec{u}^{\intercal} \vec{v} = u_1 v_1 + u_2 v_2 + \cdots + u_n v_n \end{equation*}
or alternatively using summation notation
\begin{equation*} \vec{u}^{\intercal} \vec{v} = \sum_{i=1}^n u_i v_i \end{equation*}