Lecture 21 - Matrix Operations

Learning Objectives

Addition and Scalar Multiplication of Matrices

Given a matrix \( A \), we write \( a_{ij} \) or \( a_{i,j} \) for the entry in row \( i \) and column \( j \). The entries \( a_{ii} \) form the "main diagonal" of \( A \): \[ \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1m} \\ a_{21} & a_{22} & \cdots & a_{2m} \\ \vdots & \vdots & \ddots & \vdots \\ a_{n1} & a_{n2} & \cdots & a_{nm} \end{bmatrix} \]

Definition. The \( n\times n \) identity matrix, written \( I_n \), is the \( n\times n\) matrix where \( a_{ii} =1\) for all \( 1\le i\le n \) and \( a_{ij} = 0 \) for all \( i \ne j \).

The identity matrix \( I_n \) has 1's down its main diagonal, and zero in all other entries: \[ I_1 = \begin{bmatrix} 1 \end{bmatrix}, \quad I_2 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}, \quad I_3 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}, \ldots \]

For any vector \( \bbm x \in \mathbb R^n \), we have \( I_n \bbm x = \bbm x \).

Definition. The \( n\times m \) zero matrix, written \( O \), is the \( n\times m\) matrix that has zero in every entry.

We must be careful to distinguish the various "zero" notations we have encountered:

Definition. Given two \( n\times m\) matrices \( A \) and \( B \) with entries \( a_{ij} \) and \( b_{ij} \) respectively, the sum of \( A \) and \( B \), written \( A+B \), is the \( n\times m\) matrix whose \( i,j \) entry is \( a_{ij} + b_{ij} \).

Example 1. Let \( A = \begin{bmatrix} 2 & 0 & 3 \\ -1 & 4 & -6 \end{bmatrix} \) and \( B = \begin{bmatrix} 1 & -1 & -2 \\ 5 & -4 & 3 \end{bmatrix} \). Compute \( A + B \).

We add the corresponding entries of \( A \) and \( B \): \[ A+B = \begin{bmatrix} 2 & 0 & 3 \\ -1 & 4 & -6 \end{bmatrix} + \begin{bmatrix} 1 & -1 & -2 \\ 5 & -4 & 3 \end{bmatrix} = \begin{bmatrix} 2+1 & 0+(-1) & 3+(-2) \\ (-1)+5 & 4+(-4) & (-6)+3 \end{bmatrix} = \begin{bmatrix} 3 & -1 & 1 \\ 4 & 0 & -3 \end{bmatrix}. \ \Box \]

Definition. Given an \( n\times m \) matrix \( A \) with entries \( a_{ij} \) and a scalar \( c \), the scalar multiple of \( A \), written \( cA \), is the \( n\times m\) matrix whose \( i,j \) entry is \( c a_{ij} \).

Example 2. Let \( A = \begin{bmatrix} 2 & 0 & 3 \\ -1 & 4 & -6 \end{bmatrix} \). Compute \( 3A \).

We multiply each entry of \( A \) by 3: \[ 3A = 3 \begin{bmatrix} 2 & 0 & 3 \\ -1 & 4 & -6 \end{bmatrix} = \begin{bmatrix} 3(2) & 3(0) & 3(3) \\ 3(-1) & 3(4) & 3(-6) \end{bmatrix} = \begin{bmatrix} 6 & 0 & 9 \\ -3 & 12 & -18 \end{bmatrix}.\ \Box \]

Similar to the properties of vector operations we learned in Lecture 6, these matrix operations have some nice algebraic properties:

\( A+B=B+A \) Commutativity
\( (A+B)+C=A+(B+C) \) Associativity
\( A+O=A \) Additive Identity
\( r(A+B) = rA+rB \) Distributivity
\( (r+s)A = rA+sA \) Distributivity
\( r(sA) = (rs)A \) Compatibility

Matrix Multiplication

In addition to the matrix operations we have already discussed, we can also define a multiplication operation for matrices. Since matrices represent transformations (functions), we would like the product to be defined so that the product of the matrices represents the composition of the two functions.

Definition. Let \( A \) be an \( m\times n \) matrix and let \( B \) be an \( n\times p \) matrix. Write \( S(\bbm x) = A\bbm x\) and \( T(\bbm x) = B\bbm x \) for the linear transformations corresponding to \( A \) and \( B \), respectively. The product of \( A\) and \( B \), written \( AB \), is the standard matrix of the transformation \( (S\circ T)(\bbm x) = S(T(\bbm x)) = A(B\bbm x) \).

Take special note of the sizes of the matrices \( A \) and \( B \) in this definition. The number of columns of \( A \) must equal the number of rows of \( B \) for the product \( AB \) to be defined. For the product \( B\bbm x \) to be defined, we must have \( \bbm x \in \mathbb R^p \), where \( p \) is the number of columns of \( B \). Since \( B\) has \( n\) rows, \( B\bbm x\) is a vector with \( n \) entries. Since \( A \) is \( m\times n\), this means that \( A(B\bbm x) \) has \( m \) entries. So, the transformation \( S\circ T \) has domain \( \mathbb R^p \) and codomain \( \mathbb R^m \), which tells us that the product matrix \( AB \) has \( m \) rows and \( p \) columns.

We see that \( AB \) is only defined when the number of columns of \( A \) matches the number of rows of \( B \). Furthermore, if \( A \) is \( m\times n \) matrix and \( B \) is \( n\times p \), then \( AB \) is \( m\times p\). How do we compute the columns of \( AB \)?

Since \( AB \) is the standard matrix for \( S\circ T\), to find the columns of \( AB \), we compute \( (S \circ T)(\bbm e_j) \) for each \( 1\le j \le p \): \[ (S\circ T)(\bbm e_j) = S(T(\bbm e_j)) = S(\bbm b_j) = A\bbm b_j. \]

The columns of \( AB \) are the vectors \( A\bbm b_j \), where \( \bbm b_j \) is the \( j^{\rm th} \) column of \( B \).

Example 3. Let \( A = \begin{bmatrix} 2 & 3 \\ 1 & -5 \end{bmatrix} \) and \( B = \begin{bmatrix} 4 & 3 & 6 \\ 1 & -2 & 3 \end{bmatrix} \). Compute \( AB \) and \( BA \).

For \( AB \), we compute \( A\bbm b_j \) for each column of \( B \): \[ A\bbm b_1 = \begin{bmatrix} 2 & 3 \\ 1 & -5 \end{bmatrix} \vectwo 4 1 = \vectwo {11}{-1} \] \[ A\bbm b_2 = \begin{bmatrix} 2 & 3 \\ 1 & -5 \end{bmatrix} \vectwo 3 {-2} = \vectwo 0 {13} \] \[ A\bbm b_3 = \begin{bmatrix} 2 & 3 \\ 1 & -5 \end{bmatrix} \vectwo 6 3 = \vectwo {21} {-9} \]

So, \( AB = \begin{bmatrix} 11 & 0 & 21 \\ -1 & 13 & -9 \end{bmatrix}\).

For \( BA \), we note that the products \( B\bbm a_1 \) and \( B\bbm a_2 \) are undefined since the number of columns of \( B \) does not match the number of rows of \( A \). The product \( BA \) is undefined. \( \Box \)

Example 4. Let \( B = \begin{bmatrix} 4 & 3 & 6 \\ 1 & -2 & 3 \end{bmatrix} \) and \( C = \begin{bmatrix} 2 & 0 \\ -1 & 1 \\ 0 & -1 \end{bmatrix} \). Compute \( BC \) and \( CB \), or explain why the product is undefined.

For \( BC \), we compute \( B\bbm c_j \) for each column of \( C \): \[ B\bbm c_1 = \begin{bmatrix} 4 & 3 & 6 \\ 1 & -2 & 3 \end{bmatrix} \vecthree 2 {-1} 0 = \vectwo 5 4 \] \[ B\bbm c_2 = \begin{bmatrix} 4 & 3 & 6 \\ 1 & -2 & 3 \end{bmatrix} \vecthree 0 1 {-1} = \vectwo {-3} {-5} \]

So, \( BC = \begin{bmatrix} 5 & -3 \\ 4 & -5 \end{bmatrix} \).

For \( CB \), we compute \( C \bbm b_j \) for each column of \( B \): \[ C \bbm b_1 = \begin{bmatrix} 2 & 0 \\ -1 & 1 \\ 0 & -1 \end{bmatrix} \vectwo 4 1 = \vecthree 8{-3}{-1} \] \[ C \bbm b_2 = \begin{bmatrix} 2 & 0 \\ -1 & 1 \\ 0 & -1 \end{bmatrix} \vectwo 3 {-2} = \vecthree 6 {-5} 2 \] \[ C \bbm b_3 = \begin{bmatrix} 2 & 0 \\ -1 & 1 \\ 0 & -1 \end{bmatrix} \vectwo 6 3 = \vecthree {12} {-3} {-3} \]

So, \( CB = \begin{bmatrix} 8 & 6 & 12 \\ -3 & -5 & -3 \\ -1 & 2 & -3 \end{bmatrix} \). \( \Box \)

Note that in Example 4, both \( BC \) and \( CB \) were defined, but \( BC \ne CB \). The two products aren't even the same size! We will explore this asymmetry in matrix multiplication further in the next lecture.

The Row-Column Rule

There is a more efficient way to compute the product of two matrices: the row-column rule. If \( A \) is \( m\times n \) and \( B \) is \( n\times p\), then the \( i,j\) entry of \( AB \) is sum of the product of the entries of the \( i^{\rm th} \) row of \( A \) and the corresponding entries of the \( j^{\rm th} \) column of \( B\): \[ a_{i1} b{1j} + a_{i2} b_{2j} + \cdots + a_{in} b_{nj}. \]

For example, consider again the product \( AB \) from Example 3. The 1, 3 entry of \( AB \) is the sum of the products of the 1st row of \( A \) and the 3rd column of \( B \): \[ AB = \begin{bmatrix} \color{red} 2 & \color{red} 3 \\ 1 & -5 \end{bmatrix} \begin{bmatrix} 4 & 3 & \color{red} 6 \\ 1 & -2 & \color{red} 3 \end{bmatrix} = \begin{bmatrix} \cdot & \cdot & (2)(6) + (3)(3) \\ \cdot & \cdot & \cdot \end{bmatrix} \]

We can use the row-column rule to compute the other entries of \( AB \), and we will get the same result as in Example 3. This is typically faster than computing \( AB \) one column at a time as we did in that example.

We can also use technology tools to multiply matrices for us:

« Lecture 20 Back to Top Lecture 22 »