Lite / Textbooks / The Mathematics of Machines / Chapter 5
5. Matrices and transformations
Introduction
A 2×2 matrix is a machine that takes in a vector and gives back a moved one. Its columns tell you where the two axis arrows land, which is enough to know where everything else goes. This chapter multiplies matrices and vectors, builds the rotation matrix from scratch, and shows why the order of two transformations matters and how to undo one.
Figure 5.1. Where the columns land (described in words)
A unit square with corners (0,0), (1,0), (1,1), (0,1) is transformed by the matrix with columns (1, 0) and (1, 1). The first axis arrow stays at (1, 0), the second moves to (1, 1), and the square becomes a parallelogram with the same area, because the determinant is 1.
Explanation
Built from 3 School lessons. Each part is the lesson's own explanation.
5.1 A matrix is a machine that moves vectors
Four numbers in a box can rotate, stretch, shear or flip an entire plane at once. How do they know where everything goes?
The recipe
For M = [a b; c d] and v = (x, y): M·v = (a·x + b·y, c·x + d·y). Each output component is one row of M dotted with v. A 2×2 matrix takes a 2D vector to another 2D vector.
Columns are where the axes land
M·(1, 0) = (a, c), the first column. M·(0, 1) = (b, d), the second column. Any vector (x, y) = x·(1, 0) + y·(0, 1), so M·v = x·(column 1) + y·(column 2). To design a matrix, decide where (1, 0) and (0, 1) should go and write those as columns. Grid lines stay straight, parallel and evenly spaced: that's what 'linear' means.
The determinant
det M = ad − bc is the factor by which areas change. det = 1: areas kept (rotations). det = 2: doubled. Negative: the plane is flipped over (a mirror image). det = 0: the plane is squashed onto a line or a point, information is lost, and the matrix cannot be undone.
Common mix-ups
The rows of a matrix tell you where the axes go.
✓ The columns do: column 1 is where (1, 0) lands, column 2 where (0, 1) lands.A negative determinant means the matrix shrinks things.
✓ The size of det is the area factor; the minus sign means a flip (mirror image).
Open the Lite lesson: A matrix is a machine that moves vectors
5.2 The rotation matrix, built from scratch
Every robot, game engine and spacecraft turns things with the same four entries: cos, −sin, sin, cos. Where does that minus sign come from?
Using R(θ)
To rotate a point about the origin by θ (anticlockwise positive): x′ = x cos θ − y sin θ, y′ = x sin θ + y cos θ. For a clockwise rotation, use a negative θ: cos stays the same, sin changes sign. To rotate about some other pivot, shift the pivot to the origin, rotate, then shift back.
What makes it a rotation
Its columns are unit length and perpendicular to each other, so lengths and angles are kept (it is 'orthogonal'), and det = 1, so it doesn't mirror. A matrix with orthonormal columns but det = −1 is a reflection, not a rotation.
Same matrix, two stories
R(θ)·p can mean 'turn the point p by θ' or 'p is given in a frame turned by θ; here it is in the outer frame'. Both are the same calculation. Robotics uses the second story constantly: a link frame rotated by θ1 turns the link's own coordinates into the base frame's.
Derivation: Deriving R(θ)
A matrix is fixed by where it sends (1, 0) and (0, 1): those images are its columns.
Rotating (1, 0) by θ lands on the unit circle at angle θ: (cos θ, sin θ). That's column 1.
(0, 1) starts at 90°, so after rotating it is at θ + 90°: (cos(θ + 90°), sin(θ + 90°)) = (−sin θ, cos θ). That's column 2, and the source of the minus sign.
So R(θ) = [cos θ −sin θ; sin θ cos θ], and R(θ)·(x, y) = (x cos θ − y sin θ, x sin θ + y cos θ).
Check lengths: (x cos θ − y sin θ)² + (x sin θ + y cos θ)² = x²(cos² + sin²) + y²(sin² + cos²) + (cross terms that cancel) = x² + y². Lengths are kept.
Check area: det R = cos θ · cos θ − (−sin θ) · sin θ = cos²θ + sin²θ = 1. No stretching, no flipping.
Common mix-ups
The minus sign in R(θ) goes on the bottom-left entry.
✓ It goes top-right: column 2 is where (0, 1) lands, (−sin θ, cos θ). Rebuild it from a sketch if unsure.A rotation matrix rotates about any point you like.
✓ It rotates about the origin. For another pivot, translate, rotate, translate back (or use a homogeneous transform).
Open the Lite lesson: The rotation matrix, built from scratch
5.3 Order matters: composing and undoing matrices
Shear then rotate, or rotate then shear? A robot's hand ends up in a different place. Why should order matter for multiplication?
Multiplying matrices
(A·B) entry in row i, column j = row i of A · column j of B. For 2×2: [a b; c d]·[e f; g h] = [ae + bg af + bh; ce + dg cf + dh]. The product A·B means 'first B, then A', because (A·B)·v = A·(B·v): the matrix nearest the vector acts first.
Order matters
In general A·B ≠ B·A. Physical intuition: put a book flat, rotate it 90° about a vertical axis, then flip it about a front-to-back axis; now do it the other way round. Different result. Planar rotations happen to commute, R(α)R(β) = R(α + β) = R(β)R(α), but mix in a shear, a scale or 3D rotations and order becomes everything.
Undoing: the inverse
The inverse M⁻¹ satisfies M⁻¹·M = I (the identity, [1 0; 0 1]). For 2×2: M⁻¹ = (1/det)·[d −b; −c a], which exists only when det ≠ 0. For rotations it is beautifully cheap: R(θ)⁻¹ = R(−θ) = R(θ)ᵀ (swap rows and columns). Undoing a turn is turning back.
Common mix-ups
A·B is 'A first, then B'.
✓ Acting on a vector, A·B·v applies B first. Read products right to left.The inverse of a product reverses each matrix but keeps the order.
✓ (AB)⁻¹ = B⁻¹A⁻¹: undo the last thing first.
Open the Lite lesson: Order matters: composing and undoing matrices
Worked examples
A matrix is a machine that moves vectors: example 1
Find [2 −1; 1 3]·(4, −2).
Solution
Row 1: 2×4 + (−1)×(−2) = 8 + 2 = 10. Row 2: 1×4 + 3×(−2) = 4 − 6 = −2. Answer (10, −2).
The rotation matrix, built from scratch: example 1
Rotate (3, 4) by 90° clockwise.
Solution
θ = −90°: cos = 0, sin = −1. x′ = 3×0 − 4×(−1) = 4, y′ = 3×(−1) + 4×0 = −3. (4, −3): length still 5.
Order matters: composing and undoing matrices: example 1
Find the inverse of M = [2 1; 5 3] and check it.
Solution
det = 6 − 5 = 1. M⁻¹ = [3 −1; −5 2]. Check row 1 · col 1: 3×2 + (−1)×5 = 1; row 1 · col 2: 3×1 + (−1)×3 = 0. ✓
Interactive figures, in words
Figure 5.2 from A matrix is a machine that moves vectors
Try each preset and describe it in words. Then choose Custom and build: (a) a matrix that triples heights only, (b) one that swaps x and y, (c) one that squashes the plane onto a line. For each, watch where the orange (1, 0) and green (0, 1) arrows land, and the determinant.
The matrix grid shows the plane before (fine grid) and after (blue grid) applying the matrix. An orange arrow shows where (1, 0) lands, a green arrow where (0, 1) lands, and a purple patch shows the transformed unit square. A test point (1.5, 1) and its image P′ are joined by a dashed arrow. The readout lists the matrix, both columns, P′ and the determinant.
Laboratory
These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.
- Equation Lab: Matrices (Equation Lab exploration)
Build a rotation by 90°, apply it twice and predict the result before you look.
Open on the full site - Playground: Robotic kinematics (Playground lab)
Treat each joint as a rotation and check that changing the order of two rotations moves the tip somewhere else.
Open on the full site
Practice
Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.
- [3 1; 0 2]·(2, 5): what is the first component?
Answer it in “A matrix is a machine that moves vectors” - Which matrix sends (1, 0) to (0, 2) and (0, 1) to (−1, 0)?
Answer it in “A matrix is a machine that moves vectors” - What is the determinant of [4 2; 3 1]?
Answer it in “A matrix is a machine that moves vectors” - Which matrix is R(90°)?
Answer it in “The rotation matrix, built from scratch” - The point (5, 12) is rotated by 73°. What is its distance from the origin afterwards?
Answer it in “The rotation matrix, built from scratch” - Rotate (3, 1) by 90° about the pivot (2, 1) (not the origin). What is the new y coordinate?
Answer it in “The rotation matrix, built from scratch” - [1 2; 3 4]·[5 6; 7 8]: what is the entry in row 2, column 1?
Answer it in “Order matters: composing and undoing matrices” - In A·B·v, which transformation is applied to v first?
Answer it in “Order matters: composing and undoing matrices”
Engineering applications
Robot frames
A camera on a robot arm sees the world in its own frame. A chain of rotation (and translation) matrices converts what it sees into the frame of the robot's base.
Graphics and screens
Every rotated, scaled or sheared shape on a screen is drawn by multiplying its corner coordinates by a matrix, usually millions of times a second.
Watch (optional)
Streaming video uses a lot of data. Everything you need is in the text.
- “Linear combinations, span, and basis vectors | Chapter 2, Essence of linear algebra” by 3Blue1Brown
- “Linear transformations and matrices | Chapter 3, Essence of linear algebra” by 3Blue1Brown
- “Matrix multiplication as composition | Chapter 4, Essence of linear algebra” by 3Blue1Brown
Summary
- A·v is a combination of A's columns weighted by v's components.
- The columns of A are where the axis vectors (1, 0) and (0, 1) land.
- R(θ) = [[cos θ, −sin θ], [sin θ, cos θ]] rotates by θ and keeps lengths.
- A·B means apply B first, then A; in general A·B ≠ B·A.
- The determinant is the area scale factor; zero means the matrix squashes the plane flat and cannot be undone.
Glossary
- Matrix multiplication
- Multiplying matrices combines rows of the first with columns of the second: each entry of the result is a dot product of a row and a column. Field Guide
- 2D rotation matrix
- A 2D rotation by angle θ anticlockwise maps (x, y) to (x cos θ − y sin θ, x sin θ + y cos θ), written as a 2×2 matrix. Field Guide
- Vector addition
- Vectors are added component by component: the x parts add, the y parts add, and the result is the single vector with the same effect as both. Field Guide
Project: A two-joint arm with matrices
Compute the tip position of a two-link planar arm for three pairs of joint angles using rotation matrices. Then swap the order of the two rotations in your calculation and show, with numbers, that the answer changes.
Deliverables
- The matrices used
- Tip positions for three poses
- The swapped-order result and an explanation
Write it up on paper or in your own notes. Lite never stores what you write.
References
- Gilbert Strang (2016). Introduction to Linear Algebra, 5th edition. Wellesley-Cambridge Press.
- MIT OpenCourseWare (2010). 18.06 Linear Algebra (Spring 2010). Massachusetts Institute of Technology. Link
Further reading from the lessons
- Linear map (Wikipedia)
The general idea behind matrices as transformations. - Rotation matrix (Wikipedia)
2D and 3D rotation matrices and their properties. - Matrix multiplication (Wikipedia)
Definition, properties and why it isn't commutative.