Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 62 ยท Linear Transformations

Linear Transformations

See a matrix as a function that moves vectors, learn the two rules of linearity, and read a matrix straight from where it sends the basis vectors.

So far you have treated a matrix as a table of numbers and A x as a calculation. There is a second, more powerful view: a matrix is a function that takes a vector in and gives a vector out. Feed x to A and you get A x, a new vector somewhere else. The function stretches, turns, flips or squashes space, and the matrix is a compact recipe for exactly how.

Functions of this kind are called linear transformations. They are the reason linear algebra matters for graphics, robotics, physics and machine learning: whenever something is rotated, scaled or projected, a matrix is doing the work. This lesson explains what makes a transformation linear and how to read the matrix off the transformation. You met this idea briefly in Three Ways to See Matrix-Vector Products; here it becomes the main story.

A matrix is a machine

Input A vector x in R^n.
Matrix A Moves, turns or squashes it.
Output A vector A x in R^m.

An m by n matrix maps R^n to R^m.

1 / 2

What "linear" means

A function T that maps vectors to vectors is linear if it satisfies two rules for all vectors u, w and every number c:

  1. T(u + w) = T(u) + T(w). Transforming a sum gives the sum of the transforms.
  2. T(c u) = c T(u). Transforming a scaled vector gives the scaled transform.

Together they say T respects linear combinations: T(a u + b w) = a T(u) + b T(w). A direct consequence is T(0) = 0, since 0 = 0 * u and the second rule gives T(0) = 0 * T(u) = 0. Any function that moves the origin is not linear.

Every matrix gives a linear transformation, because matrix multiplication distributes over addition and commutes with scaling. The surprise is the reverse: every linear transformation between coordinate spaces is a matrix multiplication. There is nothing else to find.

Python Testing linearity numerically

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

T passes both tests, which a handful of sample vectors suggests but does not prove. Each output entry is a plain combination of x and y, with no squares, no constants and no products, and that is what guarantees linearity. S fails: it shifts every vector one unit right. It even moves the origin, and S(u + w) differs from S(u) + S(w). Shifts are not linear, a problem you will solve in Homogeneous Coordinates and Translation.

The columns are the images of the basis vectors

Here is the key to building a matrix for any linear transformation. Every vector in R^2 is a combination x e1 + y e2 of the standard basis vectors. By linearity,

T(x e1 + y e2) = x T(e1) + y T(e2)

So knowing T(e1) and T(e2) tells you T completely. Put these two outputs side by side as the columns of a matrix and you have A:

A = [ T(e1) T(e2) ]

This is the same as the column view of A x from earlier lessons, now with a meaning: column j of the matrix is where the j-th basis vector lands. In the example above, T(e1) = (2, 1) and T(e2) = (1, -1), so

TEXT
A = [ 2   1 ]
    [ 1  -1 ]

and A @ u matches T(u). For a transformation from R^n to R^m, you need n columns of length m, so A is m x n.

To read a matrix like a map, look at its columns. The first column is where the point (1, 0) goes, the second column is where (0, 1) goes. If you can picture those two arrows, you can picture the whole transformation.

Seeing a transformation: what happens to the grid

A powerful way to picture a linear map is to draw a square grid before and after. Linearity guarantees three things:

  • grid lines stay straight lines,
  • parallel lines stay parallel,
  • evenly spaced lines stay evenly spaced.

The grid may be stretched, rotated or sheared into a lattice of parallelograms, and the origin stays put, but nothing curves. The unit square becomes the parallelogram spanned by the two columns of the matrix, and its area is multiplied by the determinant (more on that in Determinants).

Python Plotting a grid before and after

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The blue vertical lines and the red horizontal lines are mapped by one matrix product. Passing each whole line as two endpoints works because a straight line stays straight. The black and green arrows show where e1 and e2 land: they are exactly the two columns of A. The determinant is 1.5 * 0.8 = 1.2, because a shear does not change area and the stretch multiplies it by 1.5 along x and 0.8 along y.

One more look: the unit square

A tiny example makes the column picture concrete. The matrix below sends (1, 0) to (0, 1) and (0, 1) to (-1, 0): it rotates the plane a quarter turn counterclockwise.

Python A quarter turn, read from the columns

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The four corners of the unit square, stored as columns, are each moved by the matrix in one multiplication. (1, 0) becomes (0, 1) and (0, 1) becomes (-1, 0), which matches the two columns of A. Many transformations of this kind are collected in Rotation, Scaling, Shear and Reflection.

Transformations compose by matrix product

If A is the matrix of T and B is the matrix of S, then doing T first and S second is the function v -> B (A v). By associativity this is (B A) v. So composing transformations multiplies their matrices, with the first transformation on the right. That is the real reason matrix multiplication is defined the way it is, and why the order matters: matrix multiplication is not commutative, and neither is "rotate then shear". The grid example above used shear @ stretch to stretch first, then shear.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which function from R^2 to R^2 is linear?

    Only (3x - y, 2y) has outputs that are plain combinations of x and y. The shift moves the origin, and the product and the square break the two linearity rules.
  2. 2. A linear map sends e1 to (1, 3) and e2 to (-2, 0). What is its matrix?

    Column 1 is the image of e1 and column 2 is the image of e2, so the columns are (1, 3) and (-2, 0). Written by rows, that is [[1, -2], [3, 0]].
  3. 3. What must every linear transformation do to the zero vector?

    Since 0 = 0 * u, linearity gives T(0) = 0 * T(u) = 0. A map that moves the origin cannot be linear.
  4. 4. T has matrix A and S has matrix B. Which matrix represents 'apply T first, then S'?

    The input vector is multiplied by A first and the result by B, so the combined map is B (A v) = (B A) v. The first transformation is the rightmost matrix.

Summary

  • A matrix is a function; an m x n matrix maps R^n to R^m.
  • A transformation is linear when T(u + w) = T(u) + T(w) and T(c u) = c T(u); it always fixes the origin.
  • Column j of the matrix is the image of the j-th basis vector, so you can build the matrix from two or three outputs.
  • Linear maps keep grid lines straight, parallel and evenly spaced.
  • Composing transformations multiplies matrices, first transformation on the right.

Next, build the standard rotation, scaling, shear and reflection matrices in Rotation, Scaling, Shear and Reflection.