Search

Search papers and lessons

Linear Transformation

Level 2 · 9 min read

A linear transformation is a rule that moves points or vectors while keeping lines straight and the origin fixed, and every such rule is a matrix.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

A linear transformation is a rule that takes a vector and returns another vector, in a way that keeps straight lines straight and leaves the origin where it is. Stretching, rotating, flipping and shearing are all linear. Every linear transformation can be written as multiplication by a Matrix, so the matrix and the transformation are two views of the same thing.

Where you'll see it: the rotation of an image in a graphics engine, the layers of a neural network before the activation function, and the change of coordinates used in data preprocessing.

Intuition

A rule that moves space

Picture a sheet of graph paper. A transformation moves every point on that sheet to a new place. A linear transformation moves the grid in a very orderly way. Straight lines stay straight (or collapse to a point), parallel lines stay parallel, and the point at the centre, the origin, does not move. The grid may be stretched, turned or skewed, but it stays a grid.

Why does this matter? Because the whole effect of a linear transformation is decided by what it does to a few basic arrows. Once you know where the basic arrows go, you know where every point goes. That is the reason a small table of numbers, a matrix, is enough to describe the whole transformation.

−2−1.5−1−0.500.511.52−4−2024xf(x)
  • 2x: linear
  • 2x + 1: not linear
Both are straight lines, but only 2x passes through the origin. The shifted line 2x + 1 moves the origin away, so it is not linear.

Why the idea exists

Rotate a shape, scale it, then shear it, and the result is still one single linear move. Linear transformations are closed under combination, so they are the moves we can analyse completely. Much harder problems, such as nonlinear physics or nonlinear learning, are often approximated by linear ones near a point.

The math

Definition

Definition: Linear transformation

A function TT from vectors to vectors is linear if it satisfies two rules for all vectors u\mathbf{u} and v\mathbf{v} and every number cc:

T(u+v)=T(u)+T(v),T(c u)=c T(u).T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v}), \qquad T(c\,\mathbf{u}) = c\,T(\mathbf{u}).

The first rule says adding inputs adds outputs. The second says scaling the input scales the output by the same amount.

Here u\mathbf{u} and v\mathbf{v} are input vectors, cc is an ordinary number, and T(u)T(\mathbf{u}) is the output for u\mathbf{u}. Together the two rules imply that T(0)=0T(\mathbf{0}) = \mathbf{0}, which is why the origin stays fixed.

Every linear map is a matrix

Let e1,…,en\mathbf{e}_1, \dots, \mathbf{e}_n be the standard basis vectors: e1=(1,0,…,0)\mathbf{e}_1 = (1, 0, \dots, 0) and so on. Any vector x=(x1,…,xn)\mathbf{x} = (x_1, \dots, x_n) can be written as x1e1+⋯+xnenx_1 \mathbf{e}_1 + \dots + x_n \mathbf{e}_n. Applying the two rules gives

T(x)=x1T(e1)+⋯+xnT(en).T(\mathbf{x}) = x_1 T(\mathbf{e}_1) + \dots + x_n T(\mathbf{e}_n).

So the transformation is fixed once you know the images of the basis vectors. Put those images side by side as columns of a matrix:

A=(T(e1)T(e2)⋯T(en)).A = \begin{pmatrix} T(\mathbf{e}_1) & T(\mathbf{e}_2) & \cdots & T(\mathbf{e}_n) \end{pmatrix}.

Then T(x)=AxT(\mathbf{x}) = A\mathbf{x} for every x\mathbf{x}. This is the key result. The jj-th column of the matrix is where the jj-th basis arrow lands.

Composition is matrix multiplication

If TT has matrix AA and SS has matrix BB, then applying TT and then SS gives S(T(x))=B(Ax)=(BA)xS(T(\mathbf{x})) = B(A\mathbf{x}) = (BA)\mathbf{x}. The combined transformation has matrix BABA. This is why matrix multiplication is defined the way it is: it is the rule that makes composing two moves into one move.

Order matters. In general BA≠ABBA \neq AB, because doing one move and then another is not the same as doing them in reverse.

flowchart LR
  X[Input vector x] --> A[Apply A]
  A --> AX[Ax]
  AX --> B[Apply B]
  B --> BAX[BAx]

Common transformations

  • Scaling by s1s_1 along the horizontal axis and s2s_2 along the vertical axis: (s100s2)\begin{pmatrix} s_1 & 0 \\ 0 & s_2 \end{pmatrix}.
  • Rotation by angle θ\theta counterclockwise: (cos⁡θ−sin⁡θsin⁡θcos⁡θ)\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}.
  • Shear that slides each point horizontally by an amount that depends on its height: (1k01)\begin{pmatrix} 1 & k \\ 0 & 1 \end{pmatrix}.
  • Projection onto a line, which squashes the plane flat.

Eigen-directions

Some transformations leave certain directions alone, changing only the length of vectors that point that way. Those special directions are the eigenvectors, and the scale factors are the eigenvalues. They are the easiest way to understand what a matrix does over repeated applications.

Worked examples

Example
Finding the matrix from where the basis lands

Let T(x,y)=(x+2y, 3x−y)T(x, y) = (x + 2y,\ 3x - y). Is it linear? Check the rules on the formula: TT is built from sums of xx and yy multiplied by fixed numbers, so both rules hold. To find its matrix, compute the images of the basis vectors.

  1. T(1,0)=(1+0, 3−0)=(1,3)T(1, 0) = (1 + 0,\ 3 - 0) = (1, 3). This is the first column.
  2. T(0,1)=(0+2, 0−1)=(2,−1)T(0, 1) = (0 + 2,\ 0 - 1) = (2, -1). This is the second column.
  3. So A=(123−1)A = \begin{pmatrix} 1 & 2 \\ 3 & -1 \end{pmatrix}.
  4. Check with x=(1,1)\mathbf{x} = (1, 1). From the formula, T(1,1)=(3,2)T(1, 1) = (3, 2). From the matrix, A(1,1)=(1⋅1+2⋅1, 3⋅1+(−1)⋅1)=(3,2)A(1,1) = (1 \cdot 1 + 2 \cdot 1,\ 3 \cdot 1 + (-1) \cdot 1) = (3, 2). They agree.
Example
Rotating by 30 degrees, then checking the length

Take θ=30∘\theta = 30^\circ, so cos⁡θ=0.8660\cos\theta = 0.8660 and sin⁡θ=0.5\sin\theta = 0.5. The rotation matrix is

R=(0.8660−0.50.50.8660).R = \begin{pmatrix} 0.8660 & -0.5 \\ 0.5 & 0.8660 \end{pmatrix}.
  1. Apply RR to x=(2,1)\mathbf{x} = (2, 1). The first entry is 0.8660⋅2−0.5⋅1=1.23200.8660 \cdot 2 - 0.5 \cdot 1 = 1.2320.
  2. The second entry is 0.5⋅2+0.8660⋅1=1.86600.5 \cdot 2 + 0.8660 \cdot 1 = 1.8660.
  3. So Rx=(1.2320,1.8660)R\mathbf{x} = (1.2320, 1.8660).
  4. The original length is 22+12=5=2.2361\sqrt{2^2 + 1^2} = \sqrt{5} = 2.2361.
  5. The new length is 1.23202+1.86602=5.0000=2.2361\sqrt{1.2320^2 + 1.8660^2} = \sqrt{5.0000} = 2.2361.

The point turned to a new place, but its distance from the origin did not change. A rotation keeps lengths, which is what it means to be a rigid motion.

Example
Order matters: rotate then scale versus scale then rotate

Let R=(0−110)R = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} (rotate by 90∘90^\circ) and S=(2001)S = \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix} (double the horizontal direction).

  1. The product SR=(0−210)SR = \begin{pmatrix} 0 & -2 \\ 1 & 0 \end{pmatrix}. Apply it to (1,0)(1, 0): the result is (0,1)(0, 1).
  2. The product RS=(0−120)RS = \begin{pmatrix} 0 & -1 \\ 2 & 0 \end{pmatrix}. Apply it to (1,0)(1, 0): the result is (0,2)(0, 2).
  3. The two orders send the same point to different places, (0,1)(0, 1) versus (0,2)(0, 2).

So the order of moves is part of the transformation. Matrix multiplication keeps track of it for you.

Example
A realistic one: a three-day moving average

Suppose you have three daily readings (x1,x2,x3)(x_1, x_2, x_3) and you want their average. The map M(x1,x2,x3)=x1+x2+x33M(x_1, x_2, x_3) = \frac{x_1 + x_2 + x_3}{3} takes three numbers to one number. It is linear, with matrix (131313)\begin{pmatrix} \frac{1}{3} & \frac{1}{3} & \frac{1}{3} \end{pmatrix}, a 1×31 \times 3 matrix.

  1. Readings (3,6,9)(3, 6, 9) give M=3+6+93=6M = \frac{3 + 6 + 9}{3} = 6.
  2. A linear map can reduce the number of dimensions. Three inputs became one output here.
  3. Averaging is the basic step behind smoothing noisy sensor data, and it is linear, so doubling every reading doubles the average.

Tradeoffs and failure modes

Linear transformations are the right tool when the relationship really is proportional and additive: scaling a grid, rotating coordinates, mixing measurements with fixed weights. They are easy to compute, to invert when possible, and to analyse with matrix tools.

They fail when the real relationship bends. A line that misses the origin is not linear, as the plot above showed. Squares, absolute values and thresholds are not linear either.

SituationWhat goes wrongBetter choice
Stacking several linear layers in a neural networkTwo linear layers collapse into one, because W2(W1x)=(W2W1)xW_2(W_1\mathbf{x}) = (W_2 W_1)\mathbf{x}. The depth adds nothingPut a nonlinear function between layers (see Feedforward Neural Network)
Fitting a curve with a straight-line modelSystematic error that no weights can removeAdd nonlinear features, or use a nonlinear model
Squashing a 3D point cloud onto a planeInformation about the third dimension is lost, and it cannot be recoveredKeep the full dimension, or keep the directions that carry the information you need
Assuming an inverse existsSingular matrices collapse space and have no inverseTest whether the Determinant is nonzero before inverting

History

Linear ideas grew out of the study of systems of equations, which go back many centuries. In the 1840s Hermann Grassmann developed the abstract idea of combining vectors and forming linear combinations. Arthur Cayley introduced the matrix as an object in its own right in the 1850s, and it became the standard way to write a linear map. Giuseppe Peano stated the modern axioms for vector spaces and linear maps in 1888.

The idea caught on because it was the right level of abstraction for physics, geometry and, eventually, computing. A single definition covers rotations of a rigid body, the change of basis in quantum mechanics and the layers of a learning system.

Check yourself

QuestionWhich two rules must a function satisfy to be a linear transformation?Show answer

It must satisfy additivity, T(u+v)=T(u)+T(v)T(\mathbf{u} + \mathbf{v}) = T(\mathbf{u}) + T(\mathbf{v}), and homogeneity, T(c u)=c T(u)T(c\,\mathbf{u}) = c\,T(\mathbf{u}). Together they mean adding inputs adds outputs and scaling inputs scales outputs. From these, T(0)=0T(\mathbf{0}) = \mathbf{0} follows automatically.

QuestionFind the matrix of T(x,y)=(4x−y, 2y)T(x, y) = (4x - y,\ 2y).Show answer

Compute the basis images. T(1,0)=(4,0)T(1, 0) = (4, 0), which is the first column. T(0,1)=(−1,2)T(0, 1) = (-1, 2), which is the second column. So A=(4−102)A = \begin{pmatrix} 4 & -1 \\ 0 & 2 \end{pmatrix}. Check with (1,1)(1, 1): T(1,1)=(3,2)T(1,1) = (3, 2), and A(1,1)=(4−1, 0+2)=(3,2)A(1,1) = (4 - 1,\ 0 + 2) = (3, 2).

QuestionIs f(x)=x2f(x) = x^2 a linear transformation of real numbers? Give the reason.Show answer

No. Additivity fails: f(1+1)=4f(1 + 1) = 4, but f(1)+f(1)=2f(1) + f(1) = 2.

QuestionLet RR rotate by 90∘90^\circ and SS double the horizontal direction. Does RS=SRRS = SR? Explain what that means for the moves.Show answer

No. RS(1,0)=(0,2)RS(1,0) = (0,2) while SR(1,0)=(0,1)SR(1,0) = (0,1). Doing the moves in a different order gives a different final position, so composition is not commutative.

QuestionA transformation has matrix AA. Its output for input x\mathbf{x} is AxA\mathbf{x}. If you apply AA twice, what matrix do you get, and why does a stack of linear layers without an activation function add no expressive power?Show answer

Applying AA twice gives A(Ax)=(AA)xA(A\mathbf{x}) = (AA)\mathbf{x}, so the matrix is A2A^2. More generally a stack of linear layers with matrices W1,W2W_1, W_2 acts as the single matrix W2W1W_2 W_1. The layers combine into one linear map, so without a nonlinear step between them the network can only represent linear functions, no matter how deep it is.

Sources