30% off your first 3 months

Get the deal

Matrices: what multiplying them means

by DuckyHelperNov 12, 20264 min read
Math

TL;DR:

  • A 2 by 2 matrix acts on a point by rows times columns and moves it, for example rotating it.

  • Its columns are where the unit vectors (1, 0) and (0, 1) land.

  • Multiplying matrices means doing one transformation after another, and the order changes the result.

A phone rotates a photo, a game spins a character, a robot turns its arm. Behind each is a block of numbers called a matrix that moves points around. Multiplying them looks like a strange rule until you see that it simply means doing one move after another.

A matrix acting on a point

A 2 by 2 matrix has two rows and two columns: [[a, b], [c, d]]. To apply it to a point (x, y), multiply each row by the point and add: the new x is a·x + b·y, and the new y is c·x + d·y. That is rows times columns.

Worked example: a 2 by 2 matrix rotating a point by 90 degrees

The matrix R = [[0, −1], [1, 0]] rotates points 90° anticlockwise about the origin. Apply it to the point (3, 1).

  1. New x: 0·3 + (−1)·1 = −1.

  2. New y: 1·3 + 0·1 = 3.

  3. The new point is (−1, 3).

Check: the distance from the origin should not change in a rotation. Before: √(9 + 1) = √10. After: √(1 + 9) = √10. The same. And the dot product of the old and new points should be 0 for a 90° turn: 3·(−1) + 1·3 = 0. Correct.

Reading the columns

The first column of R is (0, 1): that is where the point (1, 0) lands. The second column is (−1, 0): that is where (0, 1) lands. Check with the rule: R applied to (1, 0) gives (0·1 + (−1)·0, 1·1 + 0·0) = (0, 1). So the columns tell you what the matrix does to the two basic directions. Once you know that, you know what it does to every point, since every point is a mix of those two.

Multiplying two matrices

To apply two moves in a row, multiply their matrices. The rule: each entry of the product is a row of the left matrix times a column of the right matrix. Take R (rotate 90°) and B = [[2, 0], [0, 1]] (stretch x by 2).

R·B = [[0·2 + (−1)·0, 0·0 + (−1)·1], [1·2 + 0·0, 1·0 + 0·1]] = [[0, −1], [2, 0]].

B·R = [[2·0 + 0·1, 2·(−1) + 0·0], [0·0 + 1·1, 0·(−1) + 1·0]] = [[0, −2], [1, 0]].

Order matters

The two products are different. In R·B, the matrix on the right acts first. So R·B stretches then rotates, and sends (1, 0) to (2, 0) then to (0, 2). Its first column is (0, 2), which matches. In B·R, rotate first then stretch: (1, 0) goes to (0, 1) and then stays (0, 1), since only x is stretched. Its first column is (0, 1), which matches.

So matrix multiplication is not commutative in general. Everyday analogy: putting on socks then shoes is different from shoes then socks. Some pairs do commute, such as two rotations about the same point, but you cannot assume it.

Two rotations make a half turn

Multiply R by itself: R·R = [[0·0 + (−1)·1, 0·(−1) + (−1)·0], [1·0 + 0·1, 1·(−1) + 0·0]] = [[−1, 0], [0, −1]]. That sends (x, y) to (−x, −y), a 180° turn. Two quarter turns make a half turn, as expected.

Try two more yourself

Apply M = [[1, 0], [0, −1]] to (3, 1). The new x is 1·3 + 0·1 = 3, and the new y is 0·3 + (−1)·1 = −1, giving (3, −1). This matrix reflects points across the x axis. Check: the first column is (1, 0), so the x direction stays put, and the second column is (0, −1), so the y direction flips. Now apply S = [[2, 0], [0, 2]] to (3, 1): you get (6, 2), double the distance in the same direction. The matrix [[1, 0], [0, 1]] leaves every point alone, and it plays the role of the number 1 for matrices.

How to check your answer

  • Lengths. A rotation must keep distances from the origin.

  • Columns. The columns of the product should be the images of (1, 0) and (0, 1).

  • Size rule. To multiply, the number of columns on the left must equal the number of rows on the right.

  • Try both orders. If they differ, that is normal.

Common mistakes

  • Multiplying entry by matching entry, instead of rows by columns.

  • Assuming A·B = B·A.

  • Applying the left matrix first. In A·B, B acts first.

  • Mixing up rows and columns when reading what the matrix does.

  • Dropping a minus sign, which turns a rotation into a reflection.

Where you will use it next

Matrices act on the vectors from vectors: adding forces and velocities. There is a neat parallel with numbers that rotate, shown in complex numbers as rotations, where multiplying by i does what R does here.

Frequently asked questions

Why is it called rows times columns?

Each entry of the answer is built by pairing a row of the first with a column of the second, multiplying matching entries, and adding.

Can I multiply any two matrices?

Only if the inner sizes match. A 2 by 2 times a 2 by 2 works. A 2 by 3 times a 2 by 2 does not.

Get started

DuckyHelper can
do more

It sees your screen and works in any app you use. Try it for 10 minutes, no card.

Get it for Mac, Windows or Linux

Share

Questions and jobs

Do anything

Ask it a question or hand it a job, in any app.

Doing jobs for you is in early access on Mac. Asking works on Mac, Windows and Linux.