Study guide: Matrices
Overview
A matrix is a rectangular array of numbers. In discrete mathematics matrices record relations and graphs (0–1 and adjacency matrices), represent transformations, and encode systems of linear equations.
The key operations are addition, multiplication, transpose, determinant and inverse. Multiplication is the one that behaves differently from ordinary arithmetic, and it is where most mistakes occur.
Key ideas explained
Dimensions and addition
An m × n matrix has m rows and n columns. Addition and subtraction need identical dimensions and work entry by entry; scalar multiplication scales every entry.
Matrix multiplication
An m × n matrix times an n × p matrix is m × p, with (AB)ᵢⱼ = Σₖ aᵢₖ·bₖⱼ. The inner dimensions must match. Multiplication is associative but generally not commutative.
Special matrices and the transpose
The identity I satisfies AI = IA = A. A matrix is symmetric when A = Aᵀ. The transpose reverses products: (AB)ᵀ = BᵀAᵀ.
Determinant, inverse and walks in graphs
For a 2 × 2 matrix the determinant is ad − bc, and the inverse exists exactly when it is non-zero. Entry (i, j) of Aᵏ, for an adjacency matrix A, counts the walks of length k from vertex i to vertex j.
Worked examples
Multiplication order, determinant and inverse
Problem. A = [[1, 2], [3, 4]] and B = [[0, 1], [1, 0]]. Find AB, BA, det A and A⁻¹.
- AB = [[1·0 + 2·1, 1·1 + 2·0], [3·0 + 4·1, 3·1 + 4·0]] = [[2, 1], [4, 3]].
- BA = [[3, 4], [1, 2]], which differs from AB.
- det A = 1·4 − 2·3 = −2.
- A⁻¹ = (1/−2)·[[4, −2], [−3, 1]] = [[−2, 1], [1.5, −0.5]].
Answer. AB ≠ BA, det A = −2, and A⁻¹ = [[−2, 1], [1.5, −0.5]].
Counting walks with a power of the adjacency matrix
Problem. Path graph A–B–C has adjacency matrix M = [[0,1,0],[1,0,1],[0,1,0]]. Interpret M².
- M² = [[1,0,1],[0,2,0],[1,0,1]].
- Entry (A, C) = 1: the only length-2 walk from A to C is A–B–C.
- Entry (B, B) = 2: B–A–B and B–C–B.
Answer. M² counts length-2 walks between every pair of vertices.
Enter these same values in the calculator above and compare each step with the working shown here.
Common mistakes to avoid
- Assuming AB = BA.
- Multiplying matrices whose inner dimensions do not match.
- Multiplying entry by entry instead of row by column.
- Trying to invert a matrix with determinant 0.
- Writing (AB)⁻¹ = A⁻¹B⁻¹. The correct order is B⁻¹A⁻¹.
Where this shows up in computer science
- Boolean matrix powers compute transitive closure and reachability.
- Computer graphics uses matrices for rotation and scaling, and machine learning stores weights as matrices.
- Markov chains describe state changes with transition matrices.
Test yourself
Try each question before opening the answer.
Can a 2 × 3 matrix be multiplied by another 2 × 3 matrix?
No. The inner dimensions (3 and 2) do not match.
What does det A = 0 tell you?
A is singular: it has no inverse, and its rows are linearly dependent.
What is the transpose of [[1, 2], [3, 4]]?
[[1, 3], [2, 4]].