Lesson 2: MatricesSG G3
Data in tables — prices, marks, sales figures — can be packed into a single object and calculated with in one step. That object is a matrix, and it appears everywhere from spreadsheets to the weights inside the neural networks in the AI courses.
Order and elements
A matrix is a rectangular array of numbers arranged in rows and columns. Its order is rows × columns: a matrix with 2 rows and 3 columns has order 2 × 3. We refer to entries by their position: in the matrix below, the entry in row 2 and column 1 of A is 0.
Adding, subtracting and scalar multiplication
Only matrices of the same order can be added or subtracted, and it happens element by element. Scalar multiplication multiplies every element by the number.
A = [ 2 1 ] B = [ 1 4 ]
[ 0 3 ] [ 5 2 ]
A + B = [3 5; 5 5] — each entry is the sum of the entries in the same position. 2A doubles every entry: 2A = [4 2; 0 6]. Combining, 2A − B = [3 −2; −5 4]. If the orders differ, the operation does not exist at all: a 2 × 3 matrix can never be added to a 3 × 2 matrix, even though both have six entries.
Multiplying matrices
The product A (m × n) × B (n × p) gives an (m × p) matrix. Each entry is a row of A times a column of B: multiply corresponding pairs and add. The product exists only when the inner numbers match — the number of columns of A equals the number of rows of B.
Worked example 1: two products
[1 2; 3 4] × [5; 6]: the (2 × 2)(2 × 1) orders give a 2 × 1 answer. Top entry: 1 × 5 + 2 × 6 = 17. Bottom entry: 3 × 5 + 4 × 6 = 39. So the product is [17; 39]. [2 0; 1 3] × [4 1; 2 5]: the answer is 2 × 2. Entry by entry: top-left 2 × 4 + 0 × 2 = 8; top-right 2 × 1 + 0 × 5 = 2; bottom-left 1 × 4 + 3 × 2 = 10; bottom-right 1 × 1 + 3 × 5 = 16. The product is [8 2; 10 16].
Two warnings are built into the definition. First, matrix multiplication is not commutative: AB and BA are usually different matrices, and often only one of them exists. Second, the special matrix I = [1 0; 0 1] is the identity: AI = IA = A for any 2 × 2 matrix A, just as multiplying a number by 1 changes nothing.
Worked example 2: matrices earn their keep
A stationery shop records one day's sales of notebooks, pens and files at two branches, and the price of each item:
S = [ 120 200 80 ] P = [ 3.50 ]
[ 90 150 60 ] [ 1.20 ]
[ 2.00 ]
S is 2 × 3 (branches × items) and P is 3 × 1 (one price per item), so SP is 2 × 1 — one revenue figure per branch:
- Branch A: 120 × 3.50 + 200 × 1.20 + 80 × 2.00 = 420 + 240 + 160 = $820
- Branch B: 90 × 3.50 + 150 × 1.20 + 60 × 2.00 = 315 + 180 + 120 = $615
One matrix product replaced six multiplications and two additions — and a computer does it for a thousand branches as easily as for two. This is why matrices are the language of data: whenever information sits in a table and needs a weighted total, a matrix product is waiting.
Common mistakes
- Multiplying element by element. Matrix multiplication is row-by-column, never position-by-position: [1 2; 3 4] × [5; 6] is [17; 39], not [5; 24].
- Assuming AB = BA. Order matters in matrix multiplication; always multiply in the order written, and check whether the product in the other order even exists.
- Adding matrices of different orders. A 2 × 3 and a 3 × 2 cannot be added — there is no answer, not a partial one, because corresponding positions do not exist.
- Skipping the order check. Write the orders first: (2 × 3)(3 × 1) = (2 × 1). If the middle numbers differ, stop before you calculate anything.
Quick check: which of these products exist? (3 × 2)(2 × 2) exists and has order 3 × 2. (2 × 2)(3 × 2) does not exist — the inner numbers 2 and 3 do not match.
One more product: two shoppers at once
Prices of pens, notebooks and files are P = [2 3 5] (dollars). Two shoppers buy different quantities, recorded as the columns of Q: the first buys 4 pens, 2 notebooks and 1 file; the second buys 1 pen, no notebooks and 3 files, so Q = [4 1; 2 0; 1 3] (items × shoppers). The product PQ has order (1 × 3)(3 × 2) = 1 × 2: PQ = [2 × 4 + 3 × 2 + 5 × 1, 2 × 1 + 3 × 0 + 5 × 3] = [19 17]. In one multiplication we learn that the first shopper spends $19 and the second spends $17. Notice what determined the shape of the answer: the rows of the left matrix and the columns of the right matrix survive; the shared inner dimension disappears into the sums. This is exactly how a spreadsheet total, a weighted score and a neural-network layer all work — one pattern, many costumes.
Going deeper: why order really matters
Let A = [1 2; 3 4] and let B = [0 1; 1 0]. Compute both products in full: AB = [1 × 0 + 2 × 1, 1 × 1 + 2 × 0; 3 × 0 + 4 × 1, 3 × 1 + 4 × 0] = [2 1; 4 3]. BA = [0 × 1 + 1 × 3, 0 × 2 + 1 × 4; 1 × 1 + 0 × 3, 1 × 2 + 0 × 4] = [3 4; 1 2]. AB ≠ BA — a concrete proof that matrix multiplication is not commutative. Look closer and you can see what B does: multiplying A by B on the right swaps A's columns; multiplying on the left swaps A's rows. That is why the results differ, and it is the seed of how matrices encode transformations: the side you multiply on decides what gets transformed.
Exam Experience
Question 1 [3 marks]. A = [3 −1; 2 0] and B = [1 4; −2 5]. Find (a) A + B [1] (b) 2A − B. [2] Question 2 [4 marks]. P = [2 1 0; 1 3 2] and Q = [1; 2; 1]. (a) State the order of the product PQ. [1] (b) Calculate PQ. [3] Question 3 [3 marks]. A bakery sells muffins at $2.40 and tarts at $3.10. Its sales are given by S = [45 30; 60 25], where the rows are Monday and Tuesday and the columns are muffins and tarts. Calculate the product of S with the price column [2.40; 3.10], and interpret the two entries. Marking scheme. Q1: (a) A + B = [4 3; 0 5] (A1). (b) 2A − B = [5 −6; 6 −5] (M1 for doubling A or setting up the subtraction, A1). Q2: (a) 2 × 1 (B1). (b) PQ = [2 × 1 + 1 × 2 + 0 × 1; 1 × 1 + 3 × 2 + 2 × 1] = [4; 9] (M1 for the row-by-column method, M1 for the second entry, A1). Q3: the product is [45 × 2.40 + 30 × 3.10; 60 × 2.40 + 25 × 3.10] = [$201; $221.50] (M1, A1). Interpretation: Monday's revenue was $201 and Tuesday's was $221.50 (B1).
🎬 Watch & Learn
Free YouTube video lessons on “Matrices” — pick a result below:
✅ Check your understanding
Quick recall check, generated from this lesson’s key terms. It is practice only and is not graded.