matrix algebra
Matrix Multiplication
You should know: matrices
Overview
Matrix multiplication is a binary operation that produces a new matrix from two matrices. For the product AB to be defined, the number of columns of A must equal the number of rows of B: an m×n matrix times an n×p matrix yields an m×p matrix. Unlike ordinary number multiplication, matrix multiplication is not commutative in general — AB ≠ BA — because it represents the composition of two linear transformations, and the order in which transformations are applied matters.
Intuition
Each entry of the product AB is a dot product: the i-th row of A against the j-th column of B. A useful mental model is that matrix multiplication composes functions — if A and B are linear maps, AB means 'first apply B, then apply A' (reading right to left), just like function composition f∘g means 'first g, then f'. That's also why shapes must match up correctly and why order matters.
Interactive Graph
Formal Definition
For an m×n matrix A and an n×p matrix B, the product C = AB is the m×p matrix whose (i,j) entry is the dot product of row i of A with column j of B:
A is m×n, B is n×p — the inner dimensions (n) must match
The (i,j) entry of C = AB: row i of A dotted with column j of B
The resulting shape: rows of A by columns of B
Notation
| Notation | Meaning |
|---|---|
| The matrix product of A and B (A applied after... reading conventions vary; algebraically, row-times-column) | |
| The (i,j) entry of the product matrix C = AB | |
| Identity matrix — AI = IA = A for compatible shapes |
Properties
Associativity
Condition: Whenever the products are defined
Distributivity over addition
NOT commutative in general
Example: Even when both products are defined (e.g. both square of the same size), equality is the exception, not the rule
Transpose of a product
Condition: Order reverses under transpose
Identity element
Condition: For A of shape m×n
Applications
Worked Examples
c₁₁ = row 1 of A · column 1 of B = 1·5 + 2·7.
c₁₂ = row 1 of A · column 2 of B = 1·6 + 2·8.
c₂₁ = row 2 of A · column 1 of B = 3·5 + 4·7.
c₂₂ = row 2 of A · column 2 of B = 3·6 + 4·8.
Answer: AB = [[19, 22], [43, 50]]
Practice Problems
Compute AB for A = [[2, 0], [1, 3]] and B = [[4, 1], [0, 2]].
A is 3×5 and B is 5×2. What is the shape of AB, and is BA defined?
In 2-D computer graphics, a point (x, y) is rotated 90° counter-clockwise by multiplying by R = [[0, −1], [1, 0]]. Where does the point (3, 1) go?
In the stiffness method, member forces are found from f = k·d where k is the element stiffness matrix and d the nodal displacements. If k = [[50, −50], [−50, 50]] kN/mm and d = [2, 4]ᵀ mm, compute the nodal forces f.
Common Mistakes
Multiplying matrices entrywise (like addition), i.e. computing cᵢⱼ = aᵢⱼ·bᵢⱼ.
Matrix multiplication is row-times-column (dot products), not entrywise. The entrywise product (Hadamard product) is a different, less common operation and must be explicitly named as such.
Assuming AB = BA, as with ordinary numbers.
Matrix multiplication is generally non-commutative; swapping the order can even change whether the product is defined at all, since it depends on matching inner dimensions.
Quiz
Summary
- For A (m×n) and B (n×p), the product AB is m×p, with entry cᵢⱼ = Σₖ aᵢₖ bₖⱼ.
- The product is defined only when A's number of columns equals B's number of rows.
- Matrix multiplication is associative and distributive over addition, but NOT commutative in general.
- (AB)ᵀ = BᵀAᵀ — the order reverses under transpose.
- Matrix multiplication models composition of linear transformations, chained geometric transforms, and neural network layers.
References
- BookStrang, G. Introduction to Linear Algebra, 5th ed. Ch. 2.
Mathematics