Lesson 8: Introduction to Matrices
🎧 Listen to this lesson
A matrix is a rectangular array of numbers, and it is the natural data structure of the modern world: spreadsheets, images, inventories, game boards and the weight tables of neural networks are all matrices. This lesson introduces the notation and the three core operations — addition, scalar multiplication and matrix multiplication — with the dimension rules that decide what is legal. Matrix multiplication is the subtle one: it is not element-by-element, and it is not commutative, and both facts have real meanings.
Notation, dimensions and equality
A matrix with m rows and n columns is m × n ("m by n"), and its entries are named by position: a_ij is the entry in row i, column j. Two matrices are equal only if they have the same dimensions and every corresponding entry matches. Addition and subtraction are entrywise and require identical dimensions; if the shapes differ, the operation is undefined — no partial credit from the mathematics.
Worked Example 1 — addition and scalar multiplication. Let A = [[2, −1], [0, 5]] and B = [[3, 4], [−2, 1]]. Then A + B = [[5, 3], [−2, 6]] (add corresponding entries), and 3A = [[6, −3], [0, 15]] (multiply every entry by 3). A scalar multiple scales the whole array uniformly — think of it as converting every price in a table from dollars to a currency worth a third as much, or tripling every measurement.
Matrix multiplication: rows meet columns
The product AB exists only when the number of columns of A equals the number of rows of B; the result has A's rows and B's columns. Each entry of AB is a dot product: (row i of A) · (column j of B) — multiply corresponding entries and add.
Worked Example 2 — a full multiplication. Let A = [[2, 1], [0, 3]] and B = [[1, −1], [4, 2]].
(AB)_11 = 2·1 + 1·4 = 6 (AB)_12 = 2·(−1) + 1·2 = 0
(AB)_21 = 0·1 + 3·4 = 12 (AB)_22 = 0·(−1) + 3·2 = 6
AB = [[6, 0], [12, 6]]
Now reverse the order: BA = [[2·1 + (−1)·0, 2·1 + (−1)·3], [4·1 + 2·0, 4·1 + 2·3]] = [[2, −1], [4, 10]]. Compare: AB ≠ BA. Order matters because the two products answer different questions — applying transformation B then A is genuinely different from A then B, just as "put on socks, then shoes" differs from the reverse. The identity matrix I = [[1, 0], [0, 1]] is the exception that proves the rule: AI = IA = A for every A, the matrix analogue of multiplying by 1.
Modelling: turning inventory into revenue
A sports shop has two branches. Their weekly sales (units) of shirts, trousers and jackets form a 2 × 3 matrix, and the prices form a 3 × 1 vector:
Sales S = [[40, 25, 10], Prices P = [[20],
[30, 35, 15]] [35],
[80]]
Revenue = S·P: Branch 1: 40·20 + 25·35 + 10·80 = 800 + 875 + 800 = $2,475
Branch 2: 30·20 + 35·35 + 15·80 = 600 + 1,225 + 1,200 = $3,025
The matrix product S·P is a 2 × 1 vector of branch revenues — dimensions (2 × 3)(3 × 1) → (2 × 1), the inner 3s matching and cancelling. This is exactly how real systems aggregate data: a table of quantities times a column of prices, a table of student scores times a column of weights (giving each student's weighted total in one operation), a table of ingredient needs times a column of costs. Notice P·S is impossible (1 ≠ 2): dimensions are the grammar of the operation.
Reading a product entry by entry
Every entry of a product has a story. In S·P, entry (2, 1) = 3,025 is entirely about Branch 2 and totals its three product lines. When a product looks wrong, interrogate one entry: expand its row-times-column sum and check each term against the data. This habit — auditing a single entry — is also how you catch the classic error of multiplying element-by-element: the elementwise product of A and B in Worked Example 2 would be [[2, −1], [0, 6]], which is a different (and here meaningless) array.
Common mistakes
- Multiplying element-by-element. That operation exists (the Hadamard product) but it is not matrix multiplication and is almost never what a problem wants. Entries of AB are row-by-column sums of products.
- Assuming AB = BA. Worked Example 2 disproves it with explicit numbers. Even when both products exist and have the same size, they usually differ.
- Adding matrices of different shapes. A 2 × 3 plus a 3 × 2 is undefined, full stop.
- Misreading a_ij. a_23 is row 2, column 3 — rows first, like coordinates in a spreadsheet (R2C3) or "down, then across" in a theatre seat map.
- Scalar multiplication applied to one row. 3A multiplies every entry; scaling one row is a different (row-operation) idea from Lesson 9's world.
Exam Experience
1. If A is 3 × 5 and B is 5 × 2, the product AB has dimensions
- (A) 3 × 2
- (B) 5 × 5
- (C) 2 × 3
- (D) AB is undefined
Answer: (A). Inner dimensions match (5 = 5); the product takes the outer dimensions, 3 × 2.
2. For A = [[1, 2], [3, 4]] and B = [[0, 1], [1, 0]], the (2, 1) entry of AB is
- (A) 3
- (B) 4
- (C) 1
- (D) 2
Answer: (B). Row 2 of A times column 1 of B: 3·0 + 4·1 = 4. (A) is just the entry a_21 read off without computing anything; (D) comes from grabbing the wrong row of A. The entry is a sum of two products — never a single table value.
3. Which statement about matrix multiplication is true?
- (A) AB = BA for all square matrices A, B
- (B) AB exists whenever A and B have the same number of entries
- (C) If A is 2 × 3 and B is 3 × 3, then AB is 2 × 3
- (D) The product of two 2 × 2 matrices can be 3 × 3
Answer: (C). (2 × 3)(3 × 3) → (2 × 3). (A) is disproved by Worked Example 2; (B) confuses entry count with matching inner dimensions; (D) violates the outer-dimension rule.
Constructed response. A café tracks two days of sales in the matrix M = [[50, 30], [70, 20]], where rows are Day 1 and Day 2 and columns are sandwiches and salads. Sandwiches cost $8 and salads $6. (a) Write a matrix product that computes the revenue for each day, and evaluate it. (b) The manager computes P·M instead, where P is your price matrix. Explain, using dimensions, why her product is invalid — or, if she reshapes P as a row matrix, what her product computes instead. (c) Weekend prices rise by 10%. Write the scalar operation on the price matrix and the new Day 1 revenue.
Scoring guide. (a) 2 points: 1 for the product M·[[8], [6]] with correct orientation (2 × 2 times 2 × 1); 1 for the values: Day 1: 50·8 + 30·6 = $580; Day 2: 70·8 + 20·6 = $680. (b) 2 points: 1 for noting [[8], [6]] is 2 × 1 and M is 2 × 2, so P·M has inner dimensions 1 ≠ 2 and is undefined; 1 for the reshaped version: the row matrix [8, 6]·M is 1 × 2 and computes the revenue of each product line across both days (sandwiches: 8·120 = $960; salads: 6·50 = $300) — a legitimate but different question. (c) 1 point: multiply the price matrix by 1.1 (prices $8.80, $6.60); new Day 1 revenue 50·8.80 + 30·6.60 = 440 + 198 = $638.
Going deeper: matrix equations and combined operations
Matrix equality turns matrices into systems in disguise. Solve for x and y: [[x, 2], [3, y]] + [[1, −2], [−3, 4]] = [[5, 0], [0, 6]]. Entry by entry: x + 1 = 5, so x = 4; 2 + (−2) = 0 ✓ (a consistency check the problem hands you); 3 + (−3) = 0 ✓; y + 4 = 6, so y = 2. Four entries, four small equations — this is the seed of Lesson 9's machinery.
Combined operations obey an order of operations just like arithmetic: scalars and parentheses first, then products, then sums — and dimensions must be audited at every stage. With A = [[1, 4, −2], [0, 3, 5]] and B = [[2, 1, 0], [−1, 3, 2]] (both 2 × 3), compute 2A − B: 2A = [[2, 8, −4], [0, 6, 10]], and subtracting B entrywise gives [[0, 7, −4], [1, 3, 8]]. The expression A·B, by contrast, is undefined: (2 × 3)(2 × 3) has mismatched inner dimensions. Half of matrix fluency is refusing illegal operations without hesitation.
One operation remains for the toolkit: the transpose A^T swaps rows and columns, turning an m × n matrix into an n × m one. For A above, A^T = [[1, 0], [4, 3], [−2, 5]]. Transposes matter when data arrives oriented the wrong way for a product — the sales matrix of the modelling section stored products across columns; a different database might store them down rows, and a transpose converts between the two so the revenue product S·P becomes legal. Data wrangling in real analytics is substantially this: reshape until the multiplication you need is defined, then multiply.
🎬 Watch & Learn
Free video lessons on “Introduction to Matrices” — pick a result below: