Matrices transform space

intro 8 minlinear-algebra-basics

Builds on:Linear equations stay balancedFunctions are machines

The idea

A matrix is a compact rule for transforming vectors: its columns show exactly where the basis vectors land. Scaling, rotation, reflection, and shear all become a single matrix multiplication — the same trick used throughout graphics, machine learning, and other data transformations.

Matrix multiplication composes transformations. If BB acts first and AA acts second, then A(Bx)=(AB)xA(Bx)=(AB)x: the rightmost matrix is applied first. This also explains why two linear layers without a nonlinearity collapse to one matrix product.

Real-world: stretching a game sprite

A 2D game doubles a character's width but keeps its height, so every point (x,y)(x, y) is transformed to (2x,y)(2x, y) by the matrix [2001]\begin{bmatrix} 2 & 0 \\ 0 & 1 \end{bmatrix}. The sprite point (3,4)(3, 4) moves to (6,4)(6, 4) — the xx-coordinate doubles while yy stays unchanged.

[ 2 0 ; 0 1 ]

The matrix scales the vector’s x-coordinate by 2; y stays fixed.

Worked example

Apply the transform in one calculation:

[2001][22]=[2(2)+0(2)0(2)+1(2)]=[42].\begin{bmatrix}2&0\\0&1\end{bmatrix} \begin{bmatrix}2\\2\end{bmatrix} = \begin{bmatrix} 2(2)+0(2)\\ 0(2)+1(2) \end{bmatrix} = \begin{bmatrix}4\\2\end{bmatrix}.

Cheat sheet

[abcd][xy]=[ax+bycx+dy]\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} ax+by \\ cx+dy \end{bmatrix}