Back to the on-screen lesson ·

Matrix multiplication and composition

The row-column rule, conformability, multiplication as composition of maps, powers, the reversal rule for transposes, and why a product of non-zero matrices can be zero.

Paper packet. Every task here also exists on screen, where it is checked automatically; answers written on paper are not assessed by Nydus. When you are back at a device, enter your answers there.

1. What you will learn

By the end of this lesson you will be able to decide whether a product is defined and state the shape of the answer before computing it, evaluate a product by the row-column rule and check an entry by reading the product as a combination of columns, explain why multiplication is associative but not commutative by appealing to composition, compute a power of a small matrix without squaring its entries, apply the reversal rule $(AB)^{T} = B^{T}A^{T}$, and give an example of two non-zero matrices whose product is zero.

2. What you can already do with a matrix

You can add matrices of the same shape, scale them, transpose them and multiply one by a column vector. That last operation is the one this lesson generalises: $Ax$ weighted the columns of $A$ by the entries of $x$, and $AB$ does the same thing once for every column of $B$.

3. The words for the rule

$AB$ is defined when the number of columns of $A$ equals the number of rows of $B$; the two matrices are then conformable, and the product is $m \times p$ when $A$ is $m \times n$ and $B$ is $n \times p$. The $(i, j)$ entry of $AB$ is $\sum_k a_{ik}b_{kj}$ — row $i$ of $A$ against column $j$ of $B$. $A$ and $B$ commute when $AB = BA$, which is unusual rather than normal. $A^{k}$ is $A$ multiplied by itself $k$ times, and requires $A$ to be square.

4. One rule, and the reason it is that rule

$(AB)_{ij}$ is row $i$ of $A$ dotted with column $j$ of $B$. Written out: $(AB)_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \dots + a_{in}b_{nj}$, and that sum only makes sense when $A$ has as many columns as $B$ has rows. When the shapes do not agree, the product is undefined; when they do, the two inner numbers vanish and the outer two are the shape of the answer.

Why this rule and not the obvious entry-by-entry one? Because a matrix is a map. $A$ sends $x$ to $Ax$; $B$ sends $x$ to $Bx$; and the matrix that sends $x$ to $A(Bx)$ — do $B$, then $A$ — is exactly the array the row-column rule produces. Multiplication is defined to be composition, and every strange thing about it follows from that.

It is associative. $(AB)C = A(BC)$, because doing $C$, then $B$, then $A$ is one sequence of actions and the bracketing is only about the order in which you think about it. This is worth noticing: proving associativity from the sums is a page of index-chasing, and from composition it is a sentence.

It is not commutative. $AB$ and $BA$ may have different shapes; and when both are square and the same size, they are usually still different matrices. Turning and then shearing a picture is not shearing and then turning it.

Order reverses under the transpose: $(AB)^{T} = B^{T}A^{T}$. Check the shapes and you will see it could not be anything else.

A product can vanish without either factor vanishing. $AB = 0$ with $A \ne 0$ and $B \ne 0$ happens, and it happens because a matrix can crush a non-zero vector to zero.

Another way: picture

Think of each matrix as a machine with an input slot and an output slot, labelled with sizes. $B$ takes an $n$-vector and returns a $p$... no: $B$ is $n \times p$, so it takes a $p$-vector and returns an $n$-vector. To feed that into $A$, which takes an $n$-vector, the slots must match — and they do, exactly when $A$ has $n$ columns. Bolting the two machines together gives a machine taking a $p$-vector to an $m$-vector, which is why $AB$ is $m \times p$. Conformability is not a rule to memorise; it is what it means to be able to plug two machines together.

Another way: steps

  1. Write both shapes down and check the inner numbers agree; if not, stop — the product does not exist.
  2. Write the shape of the answer: outer numbers, in order.
  3. For each entry, take the row from the left and the column from the right, multiply term by term, and add.
  4. Check one entry a second way — as a combination of columns — before trusting the array.
  5. Never assume $AB = BA$; if you need it, prove it for the matrices in front of you.

5. Two other ways to read the same product

The row-column rule computes a product, and two other readings explain one.

Column by column. The $j$th column of $AB$ is $A$ times the $j$th column of $B$. So multiplying by $A$ on the left acts on each column of $B$ separately, and $AB$ is just $Ax$ done $p$ times. This is the reading that makes $A[I]= A$ obvious, and it is how a computer usually does the work.

Row by row. The $i$th row of $AB$ is the $i$th row of $A$ times the whole of $B$. So multiplying by $B$ on the right acts on the rows.

That asymmetry is the key to the whole of the next two lessons. Left multiplication does things to rows; right multiplication does things to columns. When elimination is rewritten as matrix multiplication, the elementary matrices go on the left, because row operations are what elimination does.

Blocks. If the shapes line up, a matrix can be cut into blocks and multiplied as though the blocks were entries. It is the same rule one level up, and it is how $[A \mid I]$ in the next lesson is read.

6. Powers, and what they are good for

$A^{k}$ needs $A$ square, and then $A^{j}A^{k} = A^{j+k}$ and $(A^{j})^{k} = A^{jk}$ — the two index laws survive, because powers of a single matrix always commute with each other.

What does not survive is $(AB)^{2} = A^{2}B^{2}$. Expanding honestly, $(AB)^{2} = ABAB$, and turning that into $AABB$ needs $BA = AB$, which you do not have. The same warning applies to $(A + B)^{2} = A^{2} + AB + BA + B^{2}$: four terms, and the middle two do not combine.

Powers matter because they run a process forward. If a vector $v_t$ records the state of something at step $t$ and $v_{t+1} = Av_t$, then $v_t = A^{t}v_0$, and the long-run behaviour of the process is the long-run behaviour of $A^{t}$. Computing $A^{t}$ by repeated multiplication is hopeless for large $t$; the eigenvalue unit exists largely to compute it in one step instead.

7. The four wrong rules

$AB$ is not entrywise. $(AB)_{ij}$ is not $a_{ij}b_{ij}$. That operation exists and has a different name and different uses; it is not what juxtaposition means here.

$AB \ne BA$, and "is" is not an exception. Do not cancel, do not reorder, and do not move a factor through another. If a step requires $AB = BA$, that step needs justifying for the particular matrices involved.

$(AB)^{T}$ is $B^{T}A^{T}$, not $A^{T}B^{T}$. The shapes alone rule out the wrong version whenever $A$ and $B$ are not square, which is a useful way to remember it.

$AB = 0$ does not mean $A = 0$ or $B = 0$, and $AC = BC$ does not mean $A = B$. Both of those cancellations are properties of the real numbers that matrices do not share. They come back only when the matrix being cancelled is invertible, which is the subject of the next lesson.

A square answer is not a promise of correctness. $A^{T}A$ is square for every $A$, of any shape at all; squareness is a fact about the shapes and says nothing about the entries.

8. Shapes first, entries second

  1. $A = \begin{pmatrix} 1 & 0 & 2 \\ 3 & 1 & 0 \end{pmatrix}$ is $2 \times 3$ and $B = \begin{pmatrix} 1 & 4 \\ 2 & 0 \\ 0 & 1 \end{pmatrix}$ is $3 \times 2$. Inner numbers agree, so $AB$ exists and is $2 \times 2$.

    Shape before arithmetic, always.

  2. $AB = \begin{pmatrix} 1 + 0 + 0 & 4 + 0 + 2 \\ 3 + 2 + 0 & 12 + 0 + 0 \end{pmatrix} = \begin{pmatrix} 1 & 6 \\ 5 & 12 \end{pmatrix}$.

    Row of the left, column of the right.

  3. $BA$ also exists, and is $3 \times 3$. Two matrices can have both products defined and of different sizes, which settles the commutativity question before any arithmetic is done.

    Different shapes, so certainly not equal.

9. A product that vanishes

  1. $A = \begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix}$ and $B = \begin{pmatrix} 1 & -1 \\ -1 & 1 \end{pmatrix}$. Neither is the zero matrix and neither has a zero entry.

    Nothing looks degenerate.

  2. $AB = \begin{pmatrix} 1 - 1 & -1 + 1 \\ 1 - 1 & -1 + 1 \end{pmatrix} = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix}$.

    Every dot product cancels.

  3. $BA$ is $\begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix}$ too, here — but that is luck, not a rule. What matters is that $B$ sends every vector into the line spanned by $(1, -1)$, and $A$ sends that line to zero.

    One matrix's output is the other's blind spot.

10. Your turn: if $A$ is $4 \times 3$, what shape is $A^{T}A$, and what shape is $AA^{T}$?

  1. $A^{T}$ is $3 \times 4$. For $A^{T}A$ the inner numbers are $4$ and $4$, so it is defined.

    Check conformability before the shape.

  2. Outer numbers $3$ and $3$: $A^{T}A$ is $3 \times 3$.

    Inner numbers cancel, outer numbers remain.

  3. Your turn: work this step out. Its working is at the end of the packet.

    $AA^{T}$ is $4 \times 4$. Both exist, both are square, and they are different sizes — so they are certainly not equal, and neither is the identity.

11. Guided practice

With $A = \begin{pmatrix} 4 & 2 \\ 2 & 5 \end{pmatrix}$ and $B = \begin{pmatrix} 5 & 3 \\ 1 & 3 \end{pmatrix}$, write $AB$.

This task has no paper form; do it on a device.

12. Guided practice

Write $A^{2}$ for $A = \begin{pmatrix} 3 & 6 \\ 0 & 6 \end{pmatrix}$.

This task has no paper form; do it on a device.

13. Practice

For $A = \begin{pmatrix} 6 & 4 & 1 \\ 1 & 4 & 1 \end{pmatrix}$ and $B = \begin{pmatrix} 4 & 5 \\ 3 & 6 \\ 3 & 5 \end{pmatrix}$, find the entry of $AB$ in row $1$, column $2$.

Answer:

14. Practice

$A$ is $2 \times 4$ and $B$ is $4 \times 3$. Give the shape of each product below.

RowsColumns
$AB$
$B^{T}A^{T}$
$A^{T}A$

15. Practice

$A$ and $B$ are $2 \times 2$ matrices whose product $AB$ is the zero matrix. What follows about $A$ and $B$?

16. Somewhere new

In the plane, $S$ is the shear $\begin{pmatrix} 1 & 3 \\ 0 & 1 \end{pmatrix}$ and $R$ is the quarter-turn anticlockwise $\begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}$. Write the matrix of the transformation that shears first and then turns.

This task has no paper form; do it on a device.

17. Lesson test

Lesson test: one question per skill, one attempt each, no hints. Your answers are checked when you submit.

18. Test question

With $A = \begin{pmatrix} 4 & 2 \\ 1 & 4 \end{pmatrix}$ and $B = \begin{pmatrix} 2 & 2 \\ 1 & 2 \end{pmatrix}$, write $AB$.

This task has no paper form; do it on a device.

19. What you can do now

You can multiply conformable matrices, predict shapes, compute powers and use the reversal rule. Say in your own words why the matrix of "do $S$, then $R$" is written $RS$ and not $SR$. Next: which square matrices can be undone, and how to undo them.

Working for the steps left to you

10. Your turn: if $A$ is $4 \times 3$, what shape is $A^{T}A$, and what shape is $AA^{T}$?, step 3

The two products of a rectangular matrix with its transpose are different objects.