Linear Algebra › Section B · Matrix algebra › Topic B.1

Matrix operations

A matrix is more than a table of numbers: it can be added, scaled, multiplied and flipped. Matrix multiplication in particular is defined so that it chains transformations together, and that one decision explains every rule in this topic.

From tables to an algebra

So far, matrices have mainly been a compact way to store a linear system, and the topic "The matrix equation Ax = b" described the product \(A\mathbf{x}\) as a combination of the columns of \(A\). Now matrices become objects in their own right, to be added, scaled and multiplied by each other. Most rules look like ordinary arithmetic, but a few important ones do not, and those differences cause most beginner errors.

Notation and special matrices

An \(m \times n\) matrix has \(m\) rows and \(n\) columns. The entry in row \(i\) and column \(j\) is written \(a_{ij}\), and the columns are often named \(\mathbf{a}_1, \dots, \mathbf{a}_n\). Two matrices are equal when they have the same size and every pair of matching entries agrees. A square matrix has \(m = n\); its diagonal entries are \(a_{11}, a_{22}, \dots\). A diagonal matrix has zeros everywhere off that diagonal. The identity \(I_n\) is the diagonal matrix with every diagonal entry 1, and a zero matrix, written 0, has every entry 0.

Sums and scalar multiples

Matrices of the same size are added entry by entry, and a scalar \(r\) multiplies every entry: the \((i, j)\) entry of \(A + B\) is \(a_{ij} + b_{ij}\), and that of \(rA\) is \(ra_{ij}\). A sum of matrices of different sizes is simply undefined. Because each entry obeys ordinary arithmetic, the familiar laws carry over: \(A + B = B + A\), \((A + B) + C = A + (B + C)\), \(A + 0 = A\), \(r(A + B) = rA + rB\), \((r + s)A = rA + sA\) and \(r(sA) = (rs)A\). The difference \(A - B\) means \(A + (-1)B\).

Multiplication means composition

Suppose \(B\) is \(n \times p\) and \(A\) is \(m \times n\). Multiplying \(\mathbf{x}\) by \(B\) and then multiplying the result by \(A\) gives \(A(B\mathbf{x})\). We define the product \(AB\) so that this two-step map becomes a single multiplication, \((AB)\mathbf{x} = A(B\mathbf{x})\). That forces the rule

AB = \begin{bmatrix} A\mathbf{b}_1 & A\mathbf{b}_2 & \cdots & A\mathbf{b}_p \end{bmatrix}

where \(\mathbf{b}_1, \dots, \mathbf{b}_p\) are the columns of \(B\). So each column of \(AB\) is a combination of the columns of \(A\), with weights taken from a column of \(B\). The number of columns of \(A\) must equal the number of rows of \(B\), and \(AB\) is \(m \times p\).

The row-column rule

By hand, one entry at a time is quicker. The \((i, j)\) entry of \(AB\) is row \(i\) of \(A\) paired with column \(j\) of \(B\): multiply matching entries and add.

(AB)_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots + a_{in}b_{nj}

The same idea works a whole row at a time: row \(i\) of \(AB\) equals row \(i\) of \(A\) times the matrix \(B\). Either view can check the other.

Worked example: a 2 × 3 times a 3 × 2

Let

A = \begin{bmatrix} 1 & -2 & 3 \\ 0 & 4 & -1 \end{bmatrix}, \quad B = \begin{bmatrix} 2 & 1 \\ 1 & 3 \\ -1 & 2 \end{bmatrix}

1. Sizes: \(2 \times 3\) times \(3 \times 2\), so \(AB\) exists and is \(2 \times 2\). 2. Entry (1, 1): \(1(2) + (-2)(1) + 3(-1) = -3\). 3. Entry (1, 2): \(1(1) + (-2)(3) + 3(2) = 1\). 4. Row 2: \(0 + 4 + 1 = 5\) and \(0 + 12 - 2 = 10\). So

AB = \begin{bmatrix} -3 & 1 \\ 5 & 10 \end{bmatrix}

5. Check column 1 by the column view:

2\mathbf{a}_1 + 1\mathbf{a}_2 - 1\mathbf{a}_3 = (2 - 2 - 3, 0 + 4 + 1) = (-3, 5)

Note that \(BA\) is \(3 \times 3\), so it cannot equal \(AB\).

Properties, and what fails

For matrices of compatible sizes, multiplication is associative, \(A(BC) = (AB)C\), and distributes from both sides: \(A(B + C) = AB + AC\) and \((B + C)A = BA + CA\). Scalars move freely, \(r(AB) = (rA)B = A(rB)\), and \(I_mA = A = AI_n\) for an \(m \times n\) matrix. Three ordinary rules fail. In general \(AB \ne BA\), even when both are defined and the same size. Cancellation fails: \(AB = AC\) does not force \(B = C\). And a product can be zero with neither factor zero:

\begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}\begin{bmatrix} 2 & -4 \\ -1 & 2 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}

Worked example: revenue and cost for three shops

A business sells two products in three shops. Matrix \(Q\) lists weekly units sold (rows are shops, columns are products), and \(P\) lists each product's price and unit cost in dollars (rows are products, columns are price then cost).

Q = \begin{bmatrix} 20 & 15 \\ 12 & 30 \\ 25 & 10 \end{bmatrix}, \quad P = \begin{bmatrix} 4 & 3 \\ 6 & 2 \end{bmatrix}

1. \(Q\) is \(3 \times 2\) and \(P\) is \(2 \times 2\), so \(QP\) is \(3 \times 2\): one row per shop. 2. Shop 1: revenue \(20(4) + 15(6) = 170\), cost \(20(3) + 15(2) = 90\). 3. Shop 2: \(48 + 180 = 228\) and \(36 + 60 = 96\). 4. Shop 3: \(100 + 60 = 160\) and \(75 + 20 = 95\). So the shops take $170, $228 and $160 and spend $90, $96 and $95. The product \(PQ\) is undefined, because \(P\) has 2 columns but \(Q\) has 3 rows.

Powers and the transpose

For a square matrix, \(A^k\) means \(k\) copies of \(A\) multiplied together, and \(A^0 = I\). Powers model repeated steps: if \(a_{ij} = 1\) when a one-way road runs from town \(i\) to town \(j\) and 0 otherwise, the entries of \(A^2\) count two-road routes. The transpose \(A^T\) turns rows into columns, so \((A^T)_{ij} = a_{ji}\) and an \(m \times n\) matrix becomes \(n \times m\). Its rules are \((A^T)^T = A\), \((A + B)^T = A^T + B^T\), \((rA)^T = rA^T\) and \((AB)^T = B^TA^T\), with the order reversed. In the first worked example, \((AB)^T\) has rows (-3, 5) and (1, 10), and so does \(B^TA^T\). A matrix with \(A^T = A\) is called symmetric.

Common mistakes to avoid

First, multiplying without checking sizes: the inner numbers must match, and the outer numbers give the size of the product. Second, assuming \(AB = BA\); reorder a product only when you know the two matrices commute. Third, writing \((AB)^T = A^TB^T\), which is often not even defined; the order must reverse. Fourth, squaring a matrix by squaring each entry: \(A^2\) means \(AA\). Fifth, cancelling a matrix from both sides of \(AB = AC\), which is not allowed in general.

Key takeaways

Same-size matrices add entry by entry, and scalars multiply every entry. AB is defined when A has as many columns as B has rows; its columns are A times the columns of B, and its (i, j) entry is row i of A paired with column j of B. Multiplication is associative and distributive but not commutative, has no cancellation law, and allows AB = 0 with A and B non-zero. Powers repeat a square matrix, and the transpose swaps rows and columns, with (AB)ᵀ = BᵀAᵀ.

Flashcards

Flashcard

m × n matrix

A matrix with m rows and n columns

Rows come first in the size.

Test your understanding

Question 1 of 5

A is a 4 × 3 matrix and B is a 3 × 2 matrix. Which statement is correct?

Question 2 of 5

A has rows (2, −1, 3) and (0, 4, 1). B has rows (1, 0), (2, −2) and (−1, 5). What is the (2, 2) entry of AB?

Question 3 of 5

For matrices A and B where AB is defined, which expression always equals (AB)ᵀ?

Question 4 of 5

A, B and C are n × n matrices. Which statement is true for every choice of them?

Question 5 of 5

A has rows (1, 2) and (3, 0). What is A²?

← Previous topicNext topic →