cs.thefarshad
medium

Linear Algebra

Vectors and 2x2 matrices as transformations of space, with the determinant as area.

Linear algebra is the math of vectors and matrices — and it is the engine behind computer graphics, machine learning, physics simulations, and data analysis. The key insight is that a matrix is not just a grid of numbers; it is a transformation of space.

Drag the four matrix entries below. The blue and green arrows are the basis vectors, and the shaded region is the unit square after the transform. Its area is the determinant.

îĵ
M = [[1.00, 0.50], [0.00, 1.00]]det = ad − bc = 1.00

The shaded area equals |det|. det = 0 collapses the square to a line (the matrix is not invertible); a negative det means the plane was flipped over.

Vectors

A vector is a quantity with direction and magnitude, written as a column of numbers like [32]\begin{bmatrix} 3 \\ 2 \end{bmatrix}. You can add vectors component-wise and scale them by a number. In code, a vector is just an array — a point, a velocity, a color, or a row of features.

Matrices as transformations

A 2x2 matrix [abcd]\begin{bmatrix} a & b \\ c & d \end{bmatrix} transforms every point in the plane. The trick: it sends the basis vector i^=[10]\hat{i} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} to the first column [ac]\begin{bmatrix} a \\ c \end{bmatrix}, and j^=[01]\hat{j} = \begin{bmatrix} 0 \\ 1 \end{bmatrix} to the second column [bd]\begin{bmatrix} b \\ d \end{bmatrix}. Every other point follows along linearly.

Different entries produce familiar effects:

  • Scaling: [2002]\begin{bmatrix} 2 & 0 \\ 0 & 2 \end{bmatrix} doubles everything.
  • Rotation: [cosθsinθsinθcosθ]\begin{bmatrix} \cos \theta & -\sin \theta \\ \sin \theta & \cos \theta \end{bmatrix} spins the plane.
  • Shear: [1101]\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} slides the top sideways.

Dot Product and Matrix Multiplications

The dot product of two vectors uvu \cdot v measures how much they “point in the same direction.” It’s the sum of their products: u1v1+u2v2u_1v_1 + u_2v_2.

Matrix multiplication is really about composition. If matrix AA rotates and matrix BB scales, then the product BABA is the single transformation that rotates then scales. In code, this is how we chain graphics transforms or neural network layers.

The determinant

The determinant (adbc)(ad - bc) measures how much the transformation scales area.

  • det=1\text{det} = 1: area preserved (e.g., a pure rotation).
  • det=0\text{det} = 0: the unit square collapses to a line — the matrix is not invertible and information is lost.
  • det<0\text{det} < 0: the plane is flipped over (orientation reversed).

Takeaways

  • Vectors are directed quantities; a matrix transforms whole vectors at once.
  • A 2x2 matrix is defined by where it sends the basis vectors i^\hat{i} and j^\hat{j}.
  • Matrix multiplication corresponds to composing linear transformations.
  • The determinant is the area scale factor; det=0\text{det} = 0 means information is lost.