Essence Of Linear Algebra (3Blue1Brown Inspired)
Coordinates describe an arrow. A different set of steps gives it a different description.
To locate a point on a map, we can count steps east and north. We could also count steps along two diagonal directions. The destination stays the same, but the numbers change. How do we translate between these descriptionsβand can choosing different directions make a mathematical operation easier to understand?
We will follow one arrow through both descriptions, build the matrix that translates between them, and then examine an operation that stretches the plane. Its special directions will give us a coordinate system in which that stretching becomes especially simple.
An original illustrated companion to Grant Sandersonβs 3Blue1Brown videos on change of basis and eigenvectors and eigenvalues. This tutorial focuses on those two topics; the linked series develops the wider subject.
One arrow, two descriptions
Start at the origin and move three units right, then one unit up. Draw an arrow from the origin to that destination; call it v. The two numbers (3, 1) tell us how many of each step to take.
The rightward unit step and upward unit step are our basis vectors, eβ and eβ. A basis is a set of vectors that lets us describe every vector in the space in exactly one way by scaling and adding them. Here, scaling a step means changing its length; a negative multiplier reverses its direction.
Now use a step one unit right and one unit up, bβ = (1, 1), and a step one unit right and one unit down, bβ = (1, β1). Two bβ steps reach (2, 2); adding one bβ step reaches (3, 1). Follow the colored paths:
Horizontal and vertical steps
Diagonal steps
Both paths reach the same gold arrow. Multiplying vectors by numbers and adding them is called a linear combination. The numbers in that combination are the vectorβs coordinates in the chosen basis:
We will write x for the column of standard coordinates, and c for the column of diagonal coordinates. The basis tells us what each entry multiplies:
Standard coordinates Β· multiply eβ, eβ
Diagonal coordinates Β· multiply bβ, bβ
The diagonal vectors are themselves (1, 0) and (0, 1) in their own basis: one copy of the first step, or one copy of the second. Their standard coordinates tell us where those steps lead on the original grid. This is the information we need to translate.
Put the new steps into the columns
Suppose we receive the diagonal coordinates c = (2, 1). To find the standard coordinates, take two copies of bβ and one copy of bβ, using their standard entries:
We need to perform this same operation for any pair of diagonal coordinates. Put bβ in the first column of an array and bβ in the second. Multiplying each column by the corresponding input coordinate, then adding, is matrixβvector multiplication. Call this matrix A:
A takes diagonal coordinates in and gives standard coordinates out. Its columns are the new basis vectors written in the standard basis. Try translating other coordinates with those same columns:
Cyan contributes cβbβ; blue contributes cβbβ. Their sum is the gold vector.
Input: diagonal coordinates.
Output: horizontal/vertical coordinates.
To translate in the other direction, we know x and need c. Write the standard coordinates as (xβ, xβ). The first row says xβ = cβ + cβ; the second says xβ = cβ β cβ. Add the equations to isolate cβ; subtract them to isolate cβ:
These two rules form the matrix that undoes A: its inverse, written Aβ»ΒΉ. Using it on our original arrow recovers the two diagonal coordinates:
A translates the diagonal description into the standard description; Aβ»ΒΉ translates back. Describing a fixed vector in a different basis is a change of basis. We can do this because the two chosen steps are independent: neither is a multiple of the other, so together they give unique coordinates throughout the plane.
Describe an operation by what it does to two steps
We can now translate descriptions of a fixed arrow. Our next goal is to describe an operation that changes the arrow itself. Suppose the rightward unit step is sent to (2, 1), and the upward unit step is sent to (1, 2).
Require the operation to preserve scaling and addition: transforming three copies of a vector gives three copies of its transformed vector, and transforming a sum gives the sum of the transformed vectors. Such an operation is a linear transformation. Once we know where the two basis vectors go, this rule tells us where every vector goes.
Our vector is 3eβ + eβ. Its image must therefore be three copies of the image of eβ, plus one copy of the image of eβ. Package those two images as the columns of a matrix M:
At 100%, M sends:
Cyan: eβ = (1, 0) β (2, 1).
Blue: eβ = (0, 1) β (1, 2).
Gold: v = (3, 1) β (7, 5).
The faint square grid is the fixed standard coordinate system. The colored grid follows the transformed steps.
Here M takes standard coordinates of the input and returns standard coordinates of its image. The gold arrow changes from (3, 1) to (7, 5). The coordinate language stays fixed.
Why can A also look like it moves the grid?
The same numerical multiplication can describe a translation of coordinates or a transformation of vectors. The interpretation depends on what the input and output numbers refer to.
Read (2, 1) as diagonal coordinates: it already describes our gold arrow. A gives (3, 1), its standard description. Now read (2, 1) as standard coordinates: it describes a different arrow, two units right and one up. Applying A as a transformation moves that arrow to (3, 1).
In the second interpretation, A sends eβ to bβ and eβ to bβ, so a moving-grid animation takes the standard grid into the diagonal grid. In the first interpretation, those same columns translate diagonal coordinates into standard coordinates. Labeling the coordinate language at each end keeps the two uses clear.
M mixes the standard coordinates: each output entry uses both input entries. Could another choice of basis expose a simpler description of this operation?
Find the directions that only get scaled
For M to act simply along a chosen direction, a vector pointing that way must come out along the same line through the origin. Then one number can describe the effect: how much that vector was scaled. Keep M fixed and turn the input arrow to look for these directions:
Gold: input (1, 0).
Pink ring: output (2, 1).
The output has left the dashed input line. Scaling the input alone cannot reach it.
Use the two direction buttons to find the lines where M acts by scaling alone.
The up-right and down-right directions have exactly this property. Check the diagonal steps we already know by multiplying them by M:
Along bβ Β· three times as long
Along bβ Β· unchanged
A nonzero vector that a transformation scales this way is an eigenvector. Its scale factor is the corresponding eigenvalue, usually written Ξ». For a candidate vector w, the condition is:
For this M, bβ has eigenvalue 3 and bβ has eigenvalue 1. Every nonzero multiple of either vector has the same eigenvalue. In other transformations an eigenvalue can be negative, reversing the arrow along its line, or zero, sending it to the origin.
Find those directions algebraically
The picture suggested two directions. To find all the possibilities directly from M, write the unknown vector as w = (p, q). The eigenvector condition asks for a common factor Ξ» in both entries:
Move the right sides to the left. The first equation gives q = (Ξ» β 2)p. Substitute it into the second:
If p were zero, the first equation would also make q zero. Since an eigenvector must be nonzero, the bracket must vanish. Thus Ξ» β 2 = Β±1, giving Ξ» = 3 or Ξ» = 1. Substituting back gives q = p or q = βp: the two diagonal lines.
There is a geometric way to package the same calculation. Subtract Ξ» times the original vector from Mβs output; we want the remainder to be zero. The matrix I with ones on its diagonal and zeros elsewhere leaves a vector unchanged, so it is called the identity matrix. Our condition becomes:
For this modified matrix to send a nonzero vector to zero, its two columns must be dependent: their contributions can cancel. Here is what that looks like at Ξ» = 3:
The area enclosed by the two output columns then vanishes. A matrixβs signed area scale in two dimensions is its determinant. For a two-by-two matrix, multiply the top-left and bottom-right entries, then subtract the product of the other two entries. Requiring zero area gives the same two values:
The determinant locates the possible scale factors. Solving (M β Ξ»I)w = 0 for each one finds the vectors with that factor.
We now have a reason to choose the diagonal basis: each of its vectors changes independently by a single multiplier. The next step is to express the whole transformation in those coordinates.
Translate in, transform, translate back
Suppose our input is given in diagonal coordinates and we want the transformed output in diagonal coordinates too. M currently accepts standard coordinates. We already have both translations needed to use it:
Diagonal input β standard input.
Standard input β standard output.
Standard output β diagonal output.
Write cβ² for the diagonal coordinates after the transformation. Applying the three operations in this order gives cβ² = Aβ»ΒΉ(M(Ac)). In a matrix product the rightmost matrix acts first. The combined matrix is M expressed in the diagonal basis.
Its first column describes the image of bβ in that basis: three copies of bβ and zero copies of bβ, giving (3, 0). Its second column describes the image of bβ: (0, 1). A matrix with entries only on its main diagonal is a diagonal matrix. Call this one D:
The original vector was 2bβ + bβ. Its image is 6bβ + bβ, which has standard coordinates (7, 5). We can now read the operation as βtriple the first diagonal coordinate; keep the second.β A basis made of eigenvectors is an eigenbasis; expressing the transformation in it is diagonalization.
What this buys us, and when it is possible
Apply M twice: the bβ contribution is multiplied by 3 twice, while the bβ contribution stays fixed. After n applications, the diagonal coordinates are (3βΏcβ, cβ). To express the answer in standard coordinates, translate back with A:
In two dimensions, this requires two independent eigenvectors. A 90Β° rotation has no real eigenvector: every nonzero real arrow leaves its original line. A shear can have just one line of eigenvectors, which also cannot provide a basis for the plane. Our example has the two independent directions required.
We have used the inverse to translate back. A particularly convenient case arises when the new basis vectors are perpendicular and each has length one. That is the form used in PCA.
Make each coordinate a signed distance
Our diagonal step (1, 1) has length β(1Β² + 1Β²) = β2. One diagonal coordinate unit therefore travels β2 ordinary distance units. To make a coordinate directly measure distance along its axis, shorten each diagonal step to length one by dividing by β2.
The shorter arrows below point along the same two directions. Each now travels one ordinary distance unit:
The directions stay perpendicular. Perpendicular unit vectors form an orthonormal basis. Call our vectorβs coordinates in this normalized basis s. Because each step is shorter, we need β2 times as many steps along each direction:
To recover s from x, multiply matching entries of x and uβ and add them. This operation, the dot product, reads the signed distance along the unit direction uβ. It keeps the uβ contribution and removes the perpendicular uβ contribution. Do the same with uβ for the second coordinate.
Turning each column uα΅’ into a row lets row-by-column multiplication perform that dot product. Swapping rows and columns is the transpose, written Qα΅:
Columns build the vector
Rows read its coordinates
Why the transpose is the inverse here
Multiplying Qα΅ by Q pairs each row with each column. A unit vector dotted with itself gives 1; perpendicular vectors give 0. The product is the identity matrix, so Qα΅ undoes Q:
Thus Qβ»ΒΉ = Qα΅. For our earlier, unnormalized A, each column has squared length 2, so Aα΅A = 2I. The inverse needs the extra factor 1/2 we derived earlier. In general, translation back uses the inverse; orthonormal columns make the transpose perform that operation.
Shortening an eigenvector leaves its eigenvalue unchanged: M(bβ/β2) = 3(bβ/β2). Consequently, the normalized basis gives the same simple description of M:
Reading the second equation from right to left: translate into the eigenbasis, scale its coordinates, then translate back. For a real symmetric matrixβone whose entries match across the diagonalβan orthonormal eigenbasis always exists. Expressing it as QDQα΅ is its spectral decomposition.
In principal component analysis, the matrix being studied is the covariance matrix, which summarizes how the measurements vary together. It is real symmetric. Its unit eigenvectors supply Q; their eigenvalues give the variance along those directions. Each centered observation receives coordinates through Qα΅, and Q rebuilds it from those coordinates.
Symbols and sources
- v
- The running geometric vector, three units right and one up.
- eβ, eβ; bβ, bβ
- Standard unit steps; diagonal steps (1, 1) and (1, β1), written in standard coordinates.
- x; c; s
- Coordinates in the standard, diagonal, and normalized diagonal bases, respectively.
- xβ, xβ; cβ, cβ; sβ, sβ
- The two entries of each coordinate column.
- A; Aβ»ΒΉ
- Diagonal-to-standard translation; its inverse.
- M; D; cβ²
- The transformation in standard coordinates; the same transformation in its eigenbasis; transformed diagonal coordinates.
- w = (p, q); Ξ»
- A candidate nonzero eigenvector in standard coordinates; its eigenvalue.
- I; det
- Identity matrix; determinant (signed area scale in two dimensions).
- uβ, uβ; Q; Qα΅
- Normalized diagonal vectors; matrix with those vectors as columns; its transpose.
- n
- Number of repeated applications of a transformation.
Conceptual inspiration: Grant Sanderson / 3Blue1Brown, Essence of Linear Algebra: Change of basis and Eigenvectors and eigenvalues. The explanations, running example and interactive diagrams on this page were created for this tutorial.
