Vectors, Matrices & Linear Maps
Vectors encode states and directions, while matrices encode linear input–output rules. This chapter derives matrix multiplication from composition, explains rows, columns, units, order, and linear systems, and separates the mathematical operation from algorithms that compute it.
Vectors and matrices are not special kinds of tables. A vector is a state, direction, or collection of quantities described in a declared coordinate system. A matrix is a rule that turns one vector into another while preserving addition and scaling. Its entries acquire meaning only after the input order, output order, basis, and units are named.
Matrix multiplication looks arbitrary when taught as a recipe, but it is forced by one requirement: the matrix for two rules composed in sequence must produce the same result as running those rules one after another.
Vectors need semantics and units #
A coordinate vector
is an ordered list only after its coordinates have been declared. The same array could mean a point at three metres east and two metres north, three units of product A and two of product B, or two sensor readings. Those are different vectors in different models even though the stored numbers match.
Vector addition combines like coordinates:
Multiplication by a positive scalar changes magnitude without changing direction or coordinate proportions. A negative scalar reverses direction, and zero collapses the vector to the zero vector. These operations are meaningful only when the coordinate systems and units are compatible. Adding a position vector to a temperature vector is not repaired by the fact that both arrays have length three.
Dot products are weighted totals and alignment #
For vectors , their dot product is
It has two complementary meanings.
- As a weighted total, is the weight applied to input .
- For nonzero vectors, as alignment, measures how much one vector points along the other.
For example, if quantities are units and unit prices are euros per unit, then
The multiplication pairs corresponding coordinates; the addition accumulates their contributions into one output. Matrix multiplication repeats this same weighted-total mechanism for many outputs at once.
A matrix is a linear map #
An matrix accepts an -coordinate input and produces an -coordinate output:
Each row of is the weighted recipe for one output coordinate. Each column is the output produced by one input basis vector. This second view follows because
The map is linear because it preserves combinations:
For example,
rotates the plane by counterclockwise. Its first column says where the input basis vector goes; its second says where goes. Thus
Translation is not linear because it does not keep the zero vector fixed. A rule is affine; homogeneous coordinates let graphics and robotics package that extra offset into a larger matrix.
Why multiplication is row by column #
Let turn inputs into intermediate quantities, and let turn those quantities into outputs. If and , then
Therefore the one matrix that performs the combined map is , with
The shared index is not bookkeeping: it names the intermediate channels created by and consumed by . Along each path , effects multiply; parallel paths add. That wiring is why the rule is row by column. An elementwise product cannot represent composition.
Equivalently, column of is applied to column of :
The dimensions encode the same contract:
The two occurrences of are the common intermediate coordinate system.
A product–resource–cost pipeline #
Suppose
means three units of product A and two of product B. Let
describe kilograms of material per product unit in its first row and labour-hours per product unit in its second. Then
If material costs €4/kg and labour costs €20/h, use
The composed row, measured in euros per product unit, is
so
The row-by-column rule has composed two real pipelines: products into resources, then resources into cost. Shapes and units expose a reversed or meaningless multiplication before arithmetic begins.
Composition order matters #
Let
Stretching horizontally and then rotating gives
Rotating first and then stretching gives
In , the rightmost map acts first. Matrix multiplication is generally not commutative because resizing and rotating an image, calibrating and mixing sensor channels, or passing through two physical stages depends on order. It is associative:
because either parenthesization represents the same three-stage composition.
The operation and its algorithms are different objects #
For and , the direct three-loop algorithm performs scalar multiplications plus a comparable number of additions, so its arithmetic work scales as . Reordering loops or multiplying blocks can greatly improve memory locality without changing the definition of . Special algorithms may reduce arithmetic for sufficiently large matrices, but they still owe the same mathematical product, subject to floating-point rounding.
This distinction recurs throughout mathematics: a formula specifies the object; an algorithm specifies the steps, work, storage, and numerical path used to obtain it. The DFT and FFT are a particularly clear example.
Linear systems are inverse questions #
Forward multiplication asks: given the input , what output follows? A linear system asks the inverse question: which input could have produced an observed output ?
Suppose standard and premium tickets satisfy
In matrix form,
Subtracting the first equation from the second gives , then . The matrix records two measurement rules; solving reconciles both at once.
A square matrix has an inverse only when different inputs cannot collapse to the same output. More generally, a system may have no solution, one solution, or infinitely many. Elimination exposes which case applies and is normally preferable to explicitly forming in numerical work.
Where the same operation appears #
| Model | Vector means | Matrix means | Composition means |
|---|---|---|---|
| graphics and camera geometry | point or direction coordinates | rotate, scale, or act on homogeneous coordinates before perspective division | combine stages into one transform |
| sensor calibration | raw channels | gains and cross-channel mixing | raw readings to calibrated outputs |
| production planning | product quantities | resource use per product | products to resources to total cost |
| linear ODEs and control | system state | instantaneous coupling between state variables | state evolution and coordinate changes |
| Fourier analysis | samples or coefficients | correlations with basis waves | transform and reconstruct coordinates |
| neural-network layer | feature activations | learned weighted combinations | linear maps separated by nonlinearities |
Matrices recur because all these models use weighted sums and composable linear channels. This does not mean every rectangular dataset is intrinsically a linear map. The interpretation, units, and chosen input/output spaces create the mathematics.
Diagnostic checklist #
- Name every vector's coordinate order, basis, and units.
- For , verify that the number of columns of matches the input length.
- Read rows as output recipes and columns as basis-vector images.
- For , say which map acts first and name the intermediate space.
- Use a tiny vector to test composition order; do not assume .
- Distinguish matrix multiplication from elementwise multiplication.
- Treat as a question about existence and uniqueness, not as an order to compute an inverse blindly.
- Separate the mathematical operation from the algorithm, data layout, and floating-point implementation used to compute it.
- Check whether an offset makes the model affine rather than linear.
The row-by-column rule becomes memorable only after its job is clear: it is the unique bookkeeping that makes a composed chain of linear input–output rules behave like the chain itself.