Linear transformations: where two basis arrows go is the matrix
When you first learn matrix multiplication, it looks like a rule for multiplying numbers in a certain order. In fact a matrix is a note about how to change the plane, and the note only says where two arrows go. Drag the tips of those two arrows and see how the whole plane follows.
Short answer. A linear transformation is a function from arrows (vectors) to arrows that keeps sums and scaling: T(u + v) = T(u) + T(v) and T(k·u) = k·T(u). Then knowing where the basis arrows e₁ and e₂ go tells you where every arrow goes, and standing those two up as columns gives the matrix: T(x) = [T(e₁) T(e₂)]·x. In pictures, it is a change of the plane that keeps the origin in place and keeps grid lines straight and evenly spaced.
The matrix of T. The first column is T(e₁), the second column is T(e₂)
Drag the tips of the green and blue arrows, or type numbers into the four boxes (−4 to 4). The faint lines are where the original grid goes under T, and the green cell is where one original square (made by e₁ and e₂) goes. [a b; c d] means the matrix with top row a b and bottom row c d. When the plane is squashed onto a line, the solid purple line is the range and the dashed orange line is the kernel. If the two tips land on the same spot, dragging grabs the green one, so use the number boxes.
Try this. ① The starting matrix [2 −1; 1 1] has T(e₁) = (2, 1) and T(e₂) = (−1, 1). The grid leans and stretches but stays straight and evenly spaced. The range is the whole plane and the kernel is only 0, so 2 + 0 = 2. ② Press "Project onto y = x". All four boxes become 0.5 and the plane is squashed onto one purple line. The dashed orange line in direction (1, −1) is the kernel, and 1 + 1 = 2. ③ Go back to "Starting matrix" and drag the blue tip to (−2, −1) (or type b = −2, d = −1). Now T(e₂) = −T(e₁), so both arrows lie on one line. The range is the line in direction (1, 0.5) and the kernel is the line in direction (1, 1), because T(1, 1) = T(e₁) + T(e₂) = (2, 1) + (−2, −1) = (0, 0). ④ Rotate, stretch and shear never squash area to 0, so their kernel is only 0.
Definitions
The page below explains with maps from the plane to the plane, but the definitions are the same between any vector spaces. V and W are vector spaces and T : V → W is a function. V is the domain and W is the codomain.
- linear transformation
- T is a linear transformation if the two conditions below hold for all u, v ∈ V and c ∈ ℝ. It is also called a linear map.
- standard matrix
- For a linear transformation T : ℝⁿ → ℝᵐ, the m×n matrix A whose columns are where the standard basis vectors e₁, …, eₙ go, in order. For every x ∈ ℝⁿ, T(x) = Ax. This is "the matrix of T" on this page.
- kernel
- The set of all members of V that the linear transformation T sends to the zero vector. It is a subspace of V.
- range
- The set of all values of T. Some books call it the image. It is a subspace of W. If T(x) = Ax, it is the column space of A.
- injective
- T is injective (one-to-one) if it sends different members to different members. For a linear transformation T, this is the same as ker T = {0}.
- surjective
- T is surjective if every member of the codomain W is a value of T, that is, if the range is all of the codomain.
- isomorphism
- A linear transformation that is both injective and surjective (bijective), that is, a linear transformation for which both equations below hold. If there is an isomorphism from V to W, then V and W are isomorphic, written V ≅ W.
1. What a linear transformation is: a function that keeps sums and scaling
Say a function T takes an arrow x and gives back an arrow T(x) (arrows are on the vectors page). You can also think of it as a rule that moves every point of the plane somewhere. It is a linear transformation when it follows these two rules.
- It keeps sums:
T(u + v) = T(u) + T(v). Adding and then moving gives the same as moving and then adding. - It keeps scaling:
T(k·u) = k·T(u). Stretching and then moving gives the same as moving and then stretching.
In one line: T(a·u + b·v) = a·T(u) + b·T(v). In pictures: the origin stays put (T(0) = T(0·u) = 0·T(u) = 0). Grid lines stay straight, parallel, and evenly spaced. If the plane gets squashed flat, several lines can land on top of each other. The faint grid in the lab always behaves like this.
Examples that are not linear
A shift T(x) = x + (1, 0) is not a linear transformation, because it moves the origin to (1, 0). Sums break too: T(e₁ + e₂) = T(1, 1) = (2, 1), but T(e₁) + T(e₂) = (2, 0) + (1, 1) = (3, 1). The (1, 0) got added twice. A rotation or stretch plus a shift has its own name, an affine transformation. In graphics, people add one extra 1 to the end of each coordinate (homogeneous coordinates) so that a shift also becomes a matrix, one size bigger.
Bending is not linear either. T(x, y) = (x², y) gives T(2e₁) = (4, 0), but 2·T(e₁) = (2, 0), so it does not keep scaling.
2. How the formula is built: where the basis goes is the matrix
Using the lab's starting matrix, follow where x = (2, 3) goes. e₁ = (1, 0) and e₂ = (0, 1) are the plane's basic arrows (the standard basis). Suppose all we know about T is T(e₁) = (2, 1) and T(e₂) = (−1, 1).
Written only as formulas, the steps above are these.
In formulas, (2, 3) is written standing up as a column. It is the same arrow.
- Split x:
x = x₁e₁ + x₂e₂. (2, 3) is e₁ taken 2 times followed by e₂ taken 3 times. - Apply T:
T(x) = T(x₁e₁ + x₂e₂). Apply the same T to both sides. In the picture the staircase moves with the grid but stays a staircase. - Use the two rules:
= x₁T(e₁) + x₂T(e₂). Keeping sums splits the bracket in two, and keeping scaling pulls the 2 and the 3 out of T.2(2, 1) + 3(−1, 1) = (4, 2) + (−3, 3) = (1, 5). - Pack into a matrix:
= [T(e₁) T(e₂)]·x. "Take the columns x₁ times and x₂ times and add them" is exactly what multiplying a matrix by a vector does.[2 −1; 1 1]·(2, 3) = (2×2 + (−1)×3, 1×2 + 1×3) = (1, 5).
So the matrix of T has T(e₁) and T(e₂) as its columns, in order. If the input arrows have n entries, there are n basis arrows and so n columns. If the outputs have m entries, each column has m entries, so the matrix is m×n. The other way round, for any matrix A, x ↦ Ax follows both rules (A(u + v) = Au + Av, A(ku) = k·Au), so it is a linear transformation. Once a basis is fixed, linear transformations and matrices pair up one to one. How to multiply a matrix by a vector is on the matrix basics page.
3. Work it by hand: projecting onto the line y = x
A projection drops a line from the tip of an arrow straight down onto a line (at a right angle) and sends the arrow to the foot of that drop. It is the shadow you get when light shines straight onto the line. You do not need the matrix in advance. Just find the shadows of the two basis arrows.
- T(e₁). Points on the line look like (t, t). The arrow from (1, 0) to (t, t) is (t − 1, t), and it must be at a right angle to the line's direction (1, 1), so
(t − 1)×1 + t×1 = 0, which gives t = 0.5.T(e₁) = (0.5, 0.5). - T(e₂). The same way,
t + (t − 1) = 0, t = 0.5.T(e₂) = (0.5, 0.5). - The matrix. Stand them up as columns:
[0.5 0.5; 0.5 0.5]. This is the lab's "Project onto y = x" button. - Put in x = (3, 1).
(0.5×3 + 0.5×1, 0.5×3 + 0.5×1) = (2, 2). - Kernel and range. The output is 0 when
0.5x + 0.5y = 0, that is y = −x. The kernel is the line in direction (1, −1). Every output looks like (s, s), so the range is the line y = x. - Check.
(3, 1) = (2, 2) + (1, −1). The projection keeps the range part (2, 2) and erases the kernel part (1, −1). Projecting (2, 2) again leaves it at (2, 2).
The same work written as formulas:
4. Common transformations and their matrices
For each one you can write the matrix right away: stand T(e₁) and T(e₂) up as columns.
| Transformation | T(e₁) | T(e₂) | Matrix | Kernel | Area factor | Undo |
|---|---|---|---|---|---|---|
| Rotate by θ, counterclockwise | (cos θ, sin θ) | (−sin θ, cos θ) | [cos θ −sin θ; sin θ cos θ], for 90° [0 −1; 1 0] | only 0 | 1 | yes (rotate by −θ) |
| Stretch across ×2 | (2, 0) | (0, 1) | [2 0; 0 1] | only 0 | 2 | yes (across ×0.5) |
| Shear | (1, 0) | (1, 1) | [1 1; 0 1] | only 0 | 1 | yes ([1 −1; 0 1]) |
| Project onto y = x | (0.5, 0.5) | (0.5, 0.5) | [0.5 0.5; 0.5 0.5] | line in direction (1, −1) | 0 | no |
The area factor is the determinant, and the matrix that undoes a transformation is the inverse matrix.
5. Kernel, range, and the rank-nullity theorem
The kernel is every arrow that T sends to 0: ker T = { x : T(x) = 0 }. It always contains 0. In the lab it is the dashed orange line.
The range is every place T(x) can reach: im T = { T(x) }. Since T(x) = x₁T(e₁) + x₂T(e₂), it is everything you can make by adding up multiples of the matrix's columns, the column space. In the lab it is the solid purple line.
The rank-nullity theorem: dim(kernel) + dim(range) = dim(domain). The domain is the space the inputs come from. It says the input directions split into "directions that get squashed away" and "directions that survive". The dimension of the range is the rank of the matrix.
| Transformation | dim(kernel) | dim(range) | Sum = dim(domain) |
|---|---|---|---|
| Rotating the plane | 0 | 2 | 2 |
| Projecting the plane onto y = x | 1 | 1 | 2 |
| Sending the whole plane to 0 | 2 | 0 | 2 |
3D to the plane, (x, y, z) ↦ (x, y) | 1 (the z axis) | 2 | 3 |
When the kernel is only 0, two different inputs never land on the same output. If T(u) = T(v), then T(u − v) = 0, so u − v is in the kernel, and if the kernel is only 0 then u = v. For a transformation from the plane to the plane, the range is then the whole plane too, so it can be undone. That is exactly when the determinant is not 0 and the inverse matrix exists. One more link: a nonzero arrow in the kernel is an arrow that T multiplies by 0, which makes it an eigenvector with eigenvalue 0.
6. Maps: injective, surjective, isomorphism
A map (or mapping) is another name for a function: a rule that assigns to each element of one set exactly one element of another, written T : V → W. V is the domain and W is the codomain. In linear algebra, functions between vector spaces are usually called maps, and the ones that keep sums and scaling are linear maps. So "linear map" and "linear transformation" mean the same thing, though some books keep "transformation" for the case where the domain and codomain are the same space (V → V).
Maps are sorted by two questions: do outputs collide, and is everything reached?
| Name | Meaning | How to tell for a linear map |
|---|---|---|
| Injective (one-to-one) | Different inputs go to different places | The kernel is only 0 |
| Surjective (onto) | Every point of the codomain is reached | The range is the whole codomain |
| Bijective | Both injective and surjective. An inverse map exists | The kernel is only 0 and the range is the whole codomain |
The link between injective and the kernel is the argument at the end of section 5. Surjective says the range (what is reached) equals the codomain (the stated target). The map decides the range, but we choose the codomain, so the two can differ.
| Map | Injective | Surjective | Why |
|---|---|---|---|
| Rotating the plane | yes | yes | The kernel is only 0 and the range is the whole plane |
| Projecting the plane onto y = x (codomain: the plane) | no | no | The (1, −1) direction goes to 0, and nothing off the line is reached |
3D to the plane, (x, y, z) ↦ (x, y) | no | yes | The z axis goes to 0, but the plane is filled |
The plane to 3D, (x, y) ↦ (x, y, 0) | yes | no | Nothing collides, but points with z ≠ 0 are not reached |
With matrices, the sizes alone settle some cases. An m × n matrix is a map from n dimensions to m dimensions. By rank-nullity, dim(kernel) = n − rank, so injective means "rank = n" and surjective means "rank = m". The rank cannot exceed the smaller of m and n, so a wide matrix (n > m) is never injective and a tall matrix (n < m) is never surjective. For a square matrix (n = m) the two hold or fail together, and they hold exactly when the inverse matrix exists.
A bijective linear map is an isomorphism, and two spaces joined by one are isomorphic: the elements have different names, but adding and scaling work the same way. In finite dimensions, two spaces are isomorphic exactly when they have the same dimension. For example, the polynomials a + bx + cx² of degree at most 2 are isomorphic to 3D coordinate space through the map to (a, b, c).
The map I(x) = x that leaves everything in place is the identity map, and its matrix is the identity matrix. The shortcut in a residual connection is this map.
7. A new basis changes the matrix: similar matrices
So far "the matrix of T" meant the matrix when coordinates are written in the standard basis e₁, e₂. Write coordinates in another basis and the same transformation gets different numbers.
Stand the new basis ℬ = {b₁, …, bₙ} up as the columns of a matrix P. Multiplying new coordinates [x]ℬ by P gives standard coordinates, and multiplying by P⁻¹ goes back (the change-of-basis matrix. That page calls this matrix B. Here it is P, because B is needed for the similar matrix).
If the standard matrix of T is A, getting from new coordinates to new coordinates takes three steps: convert to standard coordinates (P), transform (A), and convert back (P⁻¹).
So the matrix of T in the new basis is P⁻¹AP. Two square matrices A and B are called similar matrices when some invertible matrix P satisfies the equation below. Similar matrices are the same linear transformation written in different bases.
Example: the projection in a basis that fits it
Take the projection onto the line y = x from section 3 again. For the new basis, pick the direction of the line, b₁ = (1, 1), and the direction at a right angle to it, b₂ = (1, −1).
In the new basis the matrix is diagonal. What the projection does, "keep the b₁ direction (times 1) and send the b₂ direction to 0 (times 0)", is now readable straight from the numbers. In the standard matrix A all four entries were 0.5, which hid it.
What similar matrices share
They describe the same transformation, so anything that does not depend on the basis is the same for both.
| Value | Meaning | A and P⁻¹AP in the example |
|---|---|---|
| Determinant | How much areas are scaled | 0 and 0 |
| Trace | Sum of the diagonal entries | 0.5 + 0.5 = 1 and 1 + 0 = 1 |
| Rank | Dimension of the range | 1 and 1 |
| Eigenvalues | How much vectors that keep their direction are scaled | 1 and 0 for both |
The determinants agree because the determinant of a product is the product of the determinants.
Choose the basis from the eigenvectors and P⁻¹AP becomes diagonal. The example above is that case, and doing this is called diagonalization. Some books define P the other way round and write B = PAP⁻¹. That only swaps P and P⁻¹, so the meaning is the same.
8. Properties to know
| Property | In plain words | In the lab |
|---|---|---|
| The origin stays at the origin | T(0) = 0. This is why a shift is not linear | However you drag, the arrows start at the origin |
| Straight lines stay straight | A line goes to a line or a single point, and even spacing stays even | The faint grid |
| Where the basis goes decides everything | Two linear transformations that send the basis to the same places are the same transformation. Those places, stood up as columns, are the matrix | Dragging just two tips moves the whole plane |
| Composition is matrix multiplication | If T has matrix A and S has matrix B, doing T and then S is S(T(x)) = (BA)x. The one done first sits on the right (matrix multiplication) | |
| Rank-nullity theorem | dim(kernel) + dim(range) = dim(domain) | The "1 + 1 = 2" in the readout |
Where it is used
- Computer graphics. Rotation, resizing and shearing are written as matrices, and a chain of them is multiplied together ahead of time into one matrix. Homogeneous coordinates let shifts join the chain.
- Neural network layers. A layer computes
Wx + band then applies an activation function.Wxis a linear transformation. Without activation functions, stacking many layers still gives oneWx + bin the end, so the power to bend comes from the activation functions (neural networks). - Reducing dimensions. Principal component analysis takes data with the mean removed and projects it onto the few directions where it spreads the most.
- Systems of equations Ax = b. Whether there is an answer depends on whether b is in the range. Whether the answer is the only one depends on whether the kernel is only 0.
Common questions
Are a linear transformation and a matrix the same thing?
Once you pick a basis, each linear transformation gets exactly one matrix. The matrix is the transformation written down as numbers. If you change the basis, the same transformation gets different numbers. The transformation did not change, only the ruler you wrote it with.
y = 2x + 1 is a straight line, so why is it not a linear transformation?
Because "linear" here means something stricter than "the graph is a straight line". A linear transformation must send 0 to 0, but y = 2x + 1 sends 0 to 1. Sums break too. Putting in 1 and 2 gives 3 and 5, but putting in 1 + 2 = 3 gives 7, not 3 + 5 = 8. A function like this is a linear transformation plus a shift, and it is called an affine function.
Why can a projection not be undone?
Because its kernel holds arrows other than 0. Projecting onto the line y = x sends both (3, 1) and (2, 2) to (2, 2). Their difference (1, −1) lies in the kernel, so it was erased. Looking only at the output (2, 2), you cannot tell which input it came from. A transformation from the plane to the plane can be undone only when its kernel is just 0, and that is exactly when the determinant is not 0 and the inverse matrix exists.
Words
| Word used here | Textbook name |
|---|---|
| A function that keeps sums and scaling | linear transformation, linear map |
| Scaling | scalar multiplication |
| Basic arrows e₁, e₂ | standard basis |
| The matrix with T(e₁), T(e₂) as columns | matrix of a linear transformation, standard matrix |
| Arrows squashed to 0 | kernel, null space |
| Everything that can be reached | range, image, column space |
| Input space, output space | domain, codomain |
| A rule that assigns one element to each element | map, mapping, function |
| Different inputs go to different places | injective, one-to-one |
| Every point of the codomain is reached | surjective, onto |
| Both injective and surjective | bijective |
| A bijective linear map | isomorphism |
| The map that leaves everything in place | identity map |
| dim(kernel) + dim(range) = dim(domain) | rank-nullity theorem. dim(kernel) is the nullity, dim(range) is the rank |
| Shadow dropped at a right angle onto a line | orthogonal projection |
| A linear transformation plus a shift | affine transformation |
| Adding a 1 to coordinates so shifts become matrices | homogeneous coordinates |
| Doing one transformation after another | composition |
| Two matrices for the same transformation in different bases | similar matrices. B = P⁻¹AP |
| The matrix P with the new basis as columns | change-of-basis matrix, transition matrix. Some books give this name to P⁻¹ |
Sources
- Wikipedia, Linear map. The two rules, the fact that where the basis goes decides the map, the columns of the matrix as images of the basis, kernel and range, and the injective / surjective / isomorphism classification.
- Wikipedia, Rank–nullity theorem.
- 3Blue1Brown, Linear transformations and matrices (Essence of linear algebra). The picture of grid lines staying straight and evenly spaced.