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.
- 2x: linear
- 2x + 1: 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
A function from vectors to vectors is linear if it satisfies two rules for all vectors and and every number :
The first rule says adding inputs adds outputs. The second says scaling the input scales the output by the same amount.
Here and are input vectors, is an ordinary number, and is the output for . Together the two rules imply that , which is why the origin stays fixed.
Every linear map is a matrix
Let be the standard basis vectors: and so on. Any vector can be written as . Applying the two rules gives
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:
Then for every . This is the key result. The -th column of the matrix is where the -th basis arrow lands.
Composition is matrix multiplication
If has matrix and has matrix , then applying and then gives . The combined transformation has matrix . 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 , 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 along the horizontal axis and along the vertical axis: .
- Rotation by angle counterclockwise: .
- Shear that slides each point horizontally by an amount that depends on its height: .
- 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
Let . Is it linear? Check the rules on the formula: is built from sums of and multiplied by fixed numbers, so both rules hold. To find its matrix, compute the images of the basis vectors.
- . This is the first column.
- . This is the second column.
- So .
- Check with . From the formula, . From the matrix, . They agree.
Take , so and . The rotation matrix is
- Apply to . The first entry is .
- The second entry is .
- So .
- The original length is .
- The new length is .
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.
Let (rotate by ) and (double the horizontal direction).
- The product . Apply it to : the result is .
- The product . Apply it to : the result is .
- The two orders send the same point to different places, versus .
So the order of moves is part of the transformation. Matrix multiplication keeps track of it for you.
Suppose you have three daily readings and you want their average. The map takes three numbers to one number. It is linear, with matrix , a matrix.
- Readings give .
- A linear map can reduce the number of dimensions. Three inputs became one output here.
- 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.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Stacking several linear layers in a neural network | Two linear layers collapse into one, because . The depth adds nothing | Put a nonlinear function between layers (see Feedforward Neural Network) |
| Fitting a curve with a straight-line model | Systematic error that no weights can remove | Add nonlinear features, or use a nonlinear model |
| Squashing a 3D point cloud onto a plane | Information about the third dimension is lost, and it cannot be recovered | Keep the full dimension, or keep the directions that carry the information you need |
| Assuming an inverse exists | Singular matrices collapse space and have no inverse | Test 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, , and homogeneity, . Together they mean adding inputs adds outputs and scaling inputs scales outputs. From these, follows automatically.
QuestionFind the matrix of .Show answer
Compute the basis images. , which is the first column. , which is the second column. So . Check with : , and .
QuestionIs a linear transformation of real numbers? Give the reason.Show answer
No. Additivity fails: , but .
QuestionLet rotate by and double the horizontal direction. Does ? Explain what that means for the moves.Show answer
No. while . Doing the moves in a different order gives a different final position, so composition is not commutative.
QuestionA transformation has matrix . Its output for input is . If you apply 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 twice gives , so the matrix is . More generally a stack of linear layers with matrices acts as the single matrix . 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.