Linear transformations and diagonalisation — theory with photo filters, the kernel that swallows colours and the directions that do not turn (and the brightness that was not linear)

The first time I tried to write a photo filter as a matrix everything went wrong for a silly reason: raising the brightness is not a linear transformation. I was building a practice app that edited photos and I wanted every filter to be a matrix, as in class: rotate the photo, flip it, stretch it, turn it black and white. It all fitted until I tried to raise the brightness by adding 20 to each channel. However hard I tried, no matrix did it, and it took me an afternoon to understand why: a matrix always leaves zero where it is, and adding 20 moves it.

That mistake is the best way into this topic. A linear transformation is a rule that turns vectors into vectors while respecting sums and scaling, and every one of them has its matrix. With the matrix you compute the image of any vector, find out what gets lost on the way (the kernel) and what can be reached (the image). And the second half brings the nicest part: some directions do not turn when you apply the filter, they only stretch. They are the eigenvectors, and if there are enough of them, the matrix can be diagonalised: seen as a plain stretch. You will use topics 3 and 4 (subspaces, bases, dimension and equations) all the time, plus the rank and determinants from matrices and determinants. If you need to brush up on bases and dimension, it is all in vector spaces. After this theory comes the guided practice with problems solved step by step.

In a nutshell: a linear transformation is a function between vector spaces that respects addition and multiplication by a number, and it can always be written as a matrix. Diagonalising that matrix means finding a basis of eigenvectors in which the transformation only stretches each direction: D=P−1APD = P^{-1}AP.

Before you start. For this topic you only need three things from earlier topics: knowing what a basis and the dimension of a space are (how many vectors a basis has), solving a system by row reducing it and counting its rank, and computing a 2×2 2 \times 2 and a 3×3 3 \times 3 determinant. Nothing else. The topic has four big ideas, in this order: which photo filters are linear and how each one fits in a matrix; what gets lost on the way and what can come out (the kernel and the image); how the matrix changes when you look at the same transformation in another basis (the glasses); and the directions the filter does not turn, which let you see it as a plain stretch and compute its powers with hardly any work (diagonalising). If you get lost at any point, go back to the photo: every idea in the topic is a filter.

What a linear transformation is

Before the definition, think about what you would ask of a filter for it to behave well. Take the contrast, which multiplies each channel by 1.5, and two pixels, (100,40,0) (100, 40, 0) and (20,20,60) (20, 20, 60) . Treat them as vectors, without worrying about a channel going over 255. You have two routes: blend the two pixels (add them) and then filter, or filter each one and then blend them. Do the same with the brightness, which adds 20:

FilterBlend, then filterFilter, then blendWhy
Contrast(120,60,60)→(180,90,90) (120, 60, 60) \to (180, 90, 90) (150,60,0)+(30,30,90)=(180,90,90) (150, 60, 0) + (30, 30, 90) = (180, 90, 90) Multiplying the sum by 1.5 is the same as adding what has been multiplied
Brightness(120,60,60)→(140,80,80) (120, 60, 60) \to (140, 80, 80) (120,60,20)+(40,40,80)=(160,100,100) (120, 60, 20) + (40, 40, 80) = (160, 100, 100) On the second route the 20 is added twice, once per pixel

With the contrast the order does not matter; with the brightness, it does. The second thing you ask of a filter is the same with intensity: making the photo twice as intense before or after the filter must give the same result. With the contrast, 2⋅(100,40,0)=(200,80,0) 2 \cdot (100, 40, 0) = (200, 80, 0) and filtering gives (300,120,0) (300, 120, 0) ; filtering first gives (150,60,0) (150, 60, 0) , and doubling it, (300,120,0) (300, 120, 0) again.

Those two demands, «blending before or after makes no difference» and «scaling before or after makes no difference», are the whole idea. Now, with the official names:

A linear transformation (or linear map) is a rule ff that takes a vector v⃗\vec v from a vector space VV (the initial space, or domain) and gives it a vector f(v⃗)f(\vec v) in another space WW (the final space, or codomain):

f:V→W,v⃗↦f(v⃗) f : V \to W, \qquad \vec v \mapsto f(\vec v)

Not any rule will do. To be linear it must meet two conditions:

  1. It respects addition: f(v⃗1+v⃗2)=f(v⃗1)+f(v⃗2)f(\vec v_1 + \vec v_2) = f(\vec v_1) + f(\vec v_2) for all v⃗1,v⃗2∈V\vec v_1, \vec v_2 \in V.
  2. It respects multiplication by a number: f(λv⃗)=λf(v⃗)f(\lambda \vec v) = \lambda f(\vec v) for every v⃗∈V\vec v \in V and every λ∈R\lambda \in \mathbb{R}.

In photo terms: it does not matter whether you blend two photos and then apply the filter, or apply the filter to each one and then blend them; and it does not matter whether you make the photo twice as intense before or after the filter. The result is the same.

When the initial and final spaces are the same (V=WV = W), the transformation is called an endomorphism. Rotating a sticker on the screen is an endomorphism of R2\mathbb{R}^2: points of the plane go to points of the plane.

An example you can see: rotating the sticker by 90°

Put a sticker on the screen with the origin at its bottom-left corner. Rotating it 90° anticlockwise sends each point (x,y)(x, y) to (−y,x)(-y, x):

f(x,y)=(−y,x) f(x, y) = (-y, x)

Let us check both conditions with letters. If v⃗1=(x1,y1)\vec v_1 = (x_1, y_1) and v⃗2=(x2,y2)\vec v_2 = (x_2, y_2):

f(v⃗1+v⃗2)=f(x1+x2,  y1+y2)=(−(y1+y2),  x1+x2)=(−y1,x1)+(−y2,x2)=f(v⃗1)+f(v⃗2) f(\vec v_1 + \vec v_2) = f(x_1 + x_2,\; y_1 + y_2) = (-(y_1 + y_2),\; x_1 + x_2) = (-y_1, x_1) + (-y_2, x_2) = f(\vec v_1) + f(\vec v_2)
f(λv⃗)=f(λx,λy)=(−λy,λx)=λ(−y,x)=λf(v⃗) f(\lambda \vec v) = f(\lambda x, \lambda y) = (-\lambda y, \lambda x) = \lambda (-y, x) = \lambda f(\vec v)

Both hold: the rotation is linear. And it makes geometric sense: rotating the sum of two arrows is the same as adding the two arrows already rotated.

Why raising the brightness is not linear

Now the filter from my story. Each pixel of a photo is a vector of R3\mathbb{R}^3 with its three colour channels (red, green, blue): (R,G,B)(R, G, B). Raising the brightness by adding 20 is

b(R,G,B)=(R+20,  G+20,  B+20) b(R, G, B) = (R + 20,\; G + 20,\; B + 20)

Just look at black, (0,0,0)(0, 0, 0): b(0,0,0)=(20,20,20)b(0, 0, 0) = (20, 20, 20). And a linear transformation always sends the zero vector to the zero vector, because f(0⃗)=f(0⋅v⃗)=0⋅f(v⃗)=0⃗f(\vec 0) = f(0 \cdot \vec v) = 0 \cdot f(\vec v) = \vec 0. So bb is not linear. On the other hand, raising the contrast by multiplying by 1.5,

c(R,G,B)=(1.5R,  1.5G,  1.5B) c(R, G, B) = (1.5R,\; 1.5G,\; 1.5B)

is linear: c(v⃗1+v⃗2)=1.5(v⃗1+v⃗2)=c(v⃗1)+c(v⃗2)c(\vec v_1 + \vec v_2) = 1.5(\vec v_1 + \vec v_2) = c(\vec v_1) + c(\vec v_2), and the same goes for scalars.

Brightness versus contrastTwo panels with three colours in the red-green plane. Left: adding 20 to each channel shifts every point and black too, the origin, so it is not linear. Right: multiplying by 1.5 pushes the points away from the origin but black stays put: it is linear.Brightness: add 20RGblack movesf(0) ≠ 0 → not linearContrast: times 1.5RGblack staysf(0) = 0 and keeps sums → linear
A linear transformation never moves the origin: it is the first check.

To rule out linearity, try zero first. If f(0⃗)≠0⃗f(\vec 0) \neq \vec 0, it is not linear and you are done. If f(0⃗)=0⃗f(\vec 0) = \vec 0, it may still fail (for instance, f(x,y)=(x2,y)f(x, y) = (x^2, y)): then you have to check both conditions.

Along the same lines, any rule with a loose added number (x+3x + 3), powers (x2x^2), products of coordinates (xyxy), roots or absolute values is not linear. A linear transformation only has, in each coordinate, sums of the coordinates multiplied by numbers: f(x,y,z)=(2x−y,  3z,  x+y+z)f(x, y, z) = (2x – y,\; 3z,\; x + y + z).

Image and preimage

If f(v⃗)=w⃗f(\vec v) = \vec w, we say w⃗\vec w is the image of v⃗\vec v. The other way round, the preimage of a vector w⃗\vec w of the final space is the set of vectors that land on it:

f−1(w⃗)={ v⃗∈V:f(v⃗)=w⃗ } f^{-1}(\vec w) = \{\, \vec v \in V : f(\vec v) = \vec w \,\}

Note that it is a set: it can hold one vector, infinitely many or none. With the black-and-white filter you will see it straight away: lots of colours turn into the same grey.

The associated matrix: the columns are the images of the basis

Here is the idea that makes everything computable. If you know where the vectors of a basis go, you know where everything goes, because any vector is a combination of the basis and ff respects combinations.

In R2\mathbb{R}^2, with the standard basis e⃗1=(1,0)\vec e_1 = (1, 0) and e⃗2=(0,1)\vec e_2 = (0, 1), the 90° rotation does

f(1,0)=(0,1),f(0,1)=(−1,0) f(1, 0) = (0, 1), \qquad f(0, 1) = (-1, 0)

Before building the matrix, work out an image yourself with only those two facts. Where does (3,1) (3, 1) go? You do not need the rotation formula:

StepComputationWhy
1(3,1)=3⋅(1,0)+1⋅(0,1) (3, 1) = 3 \cdot (1, 0) + 1 \cdot (0, 1) Every arrow in the plane is so many times e⃗1 \vec e_1 plus so many times e⃗2 \vec e_2 : exactly its coordinates
2f(3,1)=3⋅f(1,0)+1⋅f(0,1) f(3, 1) = 3 \cdot f(1, 0) + 1 \cdot f(0, 1) f f respects sums and scaling, so it can be split into parts
3=3⋅(0,1)+1⋅(−1,0) = 3 \cdot (0, 1) + 1 \cdot (-1, 0) You substitute the two images you already know
4=(−1,3) = (-1, 3) You add entry by entry

Look at step 3: it is «3 times the first image plus 1 time the second». That is exactly what a matrix-times-vector product does when the images go in columns: the first number of the vector multiplies the first column and the second, the second. That is why the images go in columns, not in rows.

Check you’ve got it: with only f(1, 0) = (0, 1) and f(0, 1) = (−1, 0), where does (2, −5) go?

To (5,2) (5, 2) . Step by step: (2,−5)=2⋅(1,0)−5⋅(0,1) (2, -5) = 2 \cdot (1, 0) – 5 \cdot (0, 1) ; since f f respects combinations, f(2,−5)=2⋅(0,1)−5⋅(−1,0)=(0,2)+(5,0)=(5,2) f(2, -5) = 2 \cdot (0, 1) – 5 \cdot (-1, 0) = (0, 2) + (5, 0) = (5, 2) . Check it with the rotation formula, f(x,y)=(−y,x) f(x, y) = (-y, x) : (−(−5),2)=(5,2) (-(-5), 2) = (5, 2) . They match, and you did not need the formula at all.

Put those two images in columns and you have the associated matrix of ff in the standard basis:

A=(0−110) A = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}

With it, the image of any vector is a matrix product, with the vector as a column:

f(v⃗)=Av⃗,f(3,1)=(0−110)(31)=(−13) f(\vec v) = A \vec v, \qquad f(3, 1) = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix} \begin{pmatrix} 3 \\ 1 \end{pmatrix} = \begin{pmatrix} -1 \\ 3 \end{pmatrix}

The picture shows it on the grid: the orange arrow e⃗1\vec e_1 ends where the first column says and the violet e⃗2\vec e_2, where the second one says. The whole grid moves with them.

The matrix of the 90° rotationLeft: the plane grid with e1 in orange and e2 in violet. Center: the grid rotated 90 degrees; e1 ends at (0, 1) and e2 at (−1, 0). Right: the matrix A with those two images as columns: (0, 1) and (−1, 0).BeforeAfter the 90° rotation0-110Af(e₁)f(e₂)columns = imagesof the basis
Watch where the two basis arrows go: that, in columns, is the matrix.

In general, if f:V→Wf : V \to W with dim⁡V=n\dim V = n and dim⁡W=m\dim W = m, the associated matrix has size m×nm \times n: as many columns as the dimension of the initial space (one per basis vector) and as many rows as the dimension of the final one (the coordinates of each image). If ff is an endomorphism, AA is square.

The shortcut from the formula

When both bases are standard, there is a shortcut: the coefficients of each coordinate of ff go in rows. For instance, a colour gradient that turns the position (x,y)(x, y) of a pixel into a colour could be

g(x,y)=(2x,  x+y,  y)=(2x+0y,  1x+1y,  0x+1y)  ⇒  A=(201101) g(x, y) = (2x,\; x + y,\; y) = (2x + 0y,\; 1x + 1y,\; 0x + 1y) \;\Rightarrow\; A = \begin{pmatrix} 2 & 0 \\ 1 & 1 \\ 0 & 1 \end{pmatrix}

It is 3×23 \times 2: two columns because it starts in R2\mathbb{R}^2 and three rows because it lands in R3\mathbb{R}^3. And the columns are still the images of the basis: g(1,0)=(2,1,0)g(1, 0) = (2, 1, 0) and g(0,1)=(0,1,1)g(0, 1) = (0, 1, 1). Both ways give the same; use whichever you find easier, but know why each one works.

Putting the images of the basis in rows instead of columns. With square matrices you do not notice because the sizes fit, but you get the transpose and every image comes out wrong. A one-second check: AA times the vector (1,0,… )(1, 0, \dots) must give the first image.

Every linear transformation can be represented by a matrix, and every matrix represents a linear transformation. That is why in this topic we say «ff» or «AA», «the kernel of ff» or «the kernel of AA», interchangeably.

Computing a preimage means solving a system

If you want the vectors that land on w⃗\vec w, you have to solve Av⃗=w⃗A\vec v = \vec w: a system of equations from topic 2, with coefficient matrix AA and right-hand side w⃗\vec w. Rouché-Frobenius tells you how many solutions there are:

  • Consistent with a unique solution: a single vector goes to w⃗\vec w.
  • Consistent with infinitely many: infinitely many vectors go to w⃗\vec w.
  • Inconsistent: none. w⃗\vec w is not the image of anything.

If AA is square with ∣A∣≠0|A| \neq 0, it is direct: f−1(w⃗)=A−1w⃗f^{-1}(\vec w) = A^{-1}\vec w, a single vector.

Kernel and image: what is lost and what can be reached

Now the black-and-white filter. A simple way to turn a colour into grey is to put the average of the three channels in all three:

m(R,G,B)=(R+G+B3,  R+G+B3,  R+G+B3),M=13(111111111) m(R, G, B) = \left( \tfrac{R + G + B}{3},\; \tfrac{R + G + B}{3},\; \tfrac{R + G + B}{3} \right), \qquad M = \frac{1}{3}\begin{pmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{pmatrix}

Try an orange, (240,120,0)(240, 120, 0): the average is 120 and you get the grey (120,120,120)(120, 120, 120). With a blue, (0,60,300)(0, 60, 300)… also (120,120,120)(120, 120, 120). Two different colours end up as the same grey: the filter loses information. What is lost and what can be reached both have names.

The kernel

The kernel (or null space) of ff, Ker⁡(f)\operatorname{Ker}(f), is the set of vectors of the initial space that land on the zero vector:

Ker⁡(f)={ v⃗∈V:f(v⃗)=0⃗ } \operatorname{Ker}(f) = \{\, \vec v \in V : f(\vec v) = \vec 0 \,\}

It is always a subspace of the initial space. To compute it, you solve the homogeneous system Av⃗=0⃗A\vec v = \vec 0, that is, you row reduce (A∣0)(A \mid 0).

In the black-and-white filter, m(R,G,B)=(0,0,0)m(R, G, B) = (0, 0, 0) when R+G+B=0R + G + B = 0. That is a plane of R3\mathbb{R}^3 (one equation, three unknowns, two parameters):

Ker⁡(m)={(R,G,B):R+G+B=0},BKer⁡={(−1,1,0),  (−1,0,1)} \operatorname{Ker}(m) = \{ (R, G, B) : R + G + B = 0 \}, \qquad B_{\operatorname{Ker}} = \{ (-1, 1, 0),\; (-1, 0, 1) \}

And what has it got to do with the two colours from before? Their difference, (240,120,0)−(0,60,300)=(240,60,−300)(240, 120, 0) – (0, 60, 300) = (240, 60, -300), adds up to zero: it is in the kernel. Two vectors have the same image exactly when their difference is in the kernel, because f(v⃗1)=f(v⃗2)  ⟺  f(v⃗1−v⃗2)=0⃗f(\vec v_1) = f(\vec v_2) \iff f(\vec v_1 – \vec v_2) = \vec 0. The kernel measures how much gets squashed.

The kernel, step by step

This is how the kernel of the black-and-white filter comes out without skipping anything. The question is which colours turn into black, that is, when Mv⃗=0⃗ M\vec v = \vec 0 :

StepWhat you doWhy
1You write the three equations: R+G+B3=0 \tfrac{R + G + B}{3} = 0 , three timesEach output channel is the average, and all three have to be 0
2You multiply by 3: R+G+B=0 R + G + B = 0 Something divided by 3 is 0 exactly when that something is 0
3You row reduce: r2→r2−r1 r_2 \to r_2 – r_1 and r3→r3−r1 r_3 \to r_3 – r_1 leave two rows of zerosThe three equations are the same one: the rank is 1
4Pivot on R R , free G G and B B : R=−G−B R = -G – B Three unknowns and one useful equation leave 3−1=2 3 – 1 = 2 parameters
5(G,B)=(1,0) (G, B) = (1, 0) gives (−1,1,0) (-1, 1, 0) ; (G,B)=(0,1) (G, B) = (0, 1) gives (−1,0,1) (-1, 0, 1) One vector per parameter, setting each free one to 1 and the other to 0

The check takes a second: −1+1+0=0 -1 + 1 + 0 = 0 and −1+0+1=0 -1 + 0 + 1 = 0 , so both go to black. And you get a basis of two vectors, as the dimension formula you will see a little further down requires: 3−rg⁡(M)=3−1=2 3 – \operatorname{rg}(M) = 3 – 1 = 2 .

Check you’ve got it: which colours give the same grey as the orange (240, 120, 0)?

All the (R,G,B) (R, G, B) with R+G+B=360 R + G + B = 360 . Step by step: two colours give the same grey exactly when their difference is in the kernel, so they are the orange plus any vector that adds up to zero: (240,120,0)+α(−1,1,0)+β(−1,0,1) (240, 120, 0) + \alpha(-1, 1, 0) + \beta(-1, 0, 1) . Those vectors always add up to 360+0=360 360 + 0 = 360 , and their average is 120. It is the preimage of (120,120,120) (120, 120, 120) , a whole plane of colours. The blue (0,60,300) (0, 60, 300) is in it: 0+60+300=360 0 + 60 + 300 = 360 .

The image

The image (or range) of ff, Im⁡(f)\operatorname{Im}(f), is the set of all vectors of the final space that are the image of some vector:

Im⁡(f)={ f(v⃗):v⃗∈V } \operatorname{Im}(f) = \{\, f(\vec v) : \vec v \in V \,\}

It is a subspace of the final space, and the way to compute it comes from the matrix: since Av⃗A\vec v is a combination of the columns of AA, the columns of AA span the image. To keep a basis, you row reduce and take the columns that have a pivot (the original columns, not those of the echelon form). Also,

rg⁡(f)=dim⁡Im⁡(f)=rg⁡(A) \operatorname{rg}(f) = \dim \operatorname{Im}(f) = \operatorname{rg}(A)

In the black-and-white filter, the three columns of MM are equal, 13(1,1,1)\tfrac13(1, 1, 1), so rg⁡(M)=1\operatorname{rg}(M) = 1 and the image is the line of greys: BIm⁡={(1,1,1)}B_{\operatorname{Im}} = \{(1, 1, 1)\}. Everything that comes out of the filter is grey; a pure red cannot be reached.

Kernel and image of the black-and-white filterLeft: the colour space with the plane R + G + B = 0 in orange: it is the kernel, all of it goes to zero. Right: the line of greys (t, t, t): it is the image. A different orange and blue go to the same grey (120, 120, 120). Below, 3 = 2 + 1.Initial space ℝ³ (colours)Final space ℝ³Ker: R + G + B = 0 (dim 2)Im: greys(t, t, t), dim 10(240,120,0)(0,60,300)(120, 120, 120)3 = 2 + 1dim V = dim Ker + dim Im
The kernel is lost entirely in zero; the image is all that can come out of the filter.

The dimension formula

There is a relation you will use in every exercise:

dim⁡V=dim⁡Ker⁡(f)+dim⁡Im⁡(f) \dim V = \dim \operatorname{Ker}(f) + \dim \operatorname{Im}(f)

The dimension of the initial space is shared between what is lost and what arrives. In the filter: 3=2+13 = 2 + 1. In the 90° rotation: Ker⁡={(0,0)}\operatorname{Ker} = \{(0, 0)\} (the only vector that becomes zero when rotated is zero), so 2=0+dim⁡Im⁡2 = 0 + \dim\operatorname{Im} and the image is the whole of R2\mathbb{R}^2.

Always compute the rank first. With it you have dim⁡Im⁡=rg⁡(A)\dim\operatorname{Im} = \operatorname{rg}(A) and dim⁡Ker⁡=n−rg⁡(A)\dim\operatorname{Ker} = n – \operatorname{rg}(A), with nn the number of columns, before solving any system. That way you know how many vectors each basis must have, and it doubles as a check.

Subtracting the rank from the number of rows to get the dimension of the kernel. The kernel lives in the initial space, and its dimension is the number of columns minus the rank. In the gradient g:R2→R3g : \mathbb{R}^2 \to \mathbb{R}^3, with rg⁡=2\operatorname{rg} = 2, the kernel has dimension 2−2=02 – 2 = 0, not 3−2=13 – 2 = 1.

Injective, surjective and bijective

With the kernel and the image you can answer the three classic questions about a transformation:

TypeWhat it meansHow to check itExample
Injective (one-to-one)Different vectors go to different imagesKer⁡(f)={0⃗}\operatorname{Ker}(f) = \{\vec 0\}, that is, rg⁡(A)=n\operatorname{rg}(A) = n (columns)The gradient gg: no two pixels share a colour
Surjective (onto)Every vector of the final space is the image of some vectordim⁡Im⁡(f)=dim⁡W\dim\operatorname{Im}(f) = \dim W, that is, rg⁡(A)=m\operatorname{rg}(A) = m (rows)The 90° rotation
Bijective (isomorphism)Injective and surjective at once: every vector has a partner and only oneBoth conditions; if AA is square, ∣A∣≠0\lvert A \rvert \neq 0The 90° rotation

The black-and-white filter is neither injective (kernel of dimension 2) nor surjective (image of dimension 1 in R3\mathbb{R}^3). The gradient is injective but not surjective: with two numbers you cannot reach every colour in R3\mathbb{R}^3.

For an endomorphism everything simplifies: since m=nm = n, injective, surjective and bijective are the same thing, and the determinant decides. If ∣A∣≠0|A| \neq 0, it is bijective and has an inverse, f−1f^{-1}, whose matrix is A−1A^{-1}: undoing the filter. If ∣A∣=0|A| = 0, the filter has eaten something and there is no way back.

If dim⁡V>dim⁡W\dim V > \dim W (more columns than rows), ff cannot be injective: the rank is at most m<nm < n, so the kernel has dimension at least n−m>0n – m > 0. And if dim⁡V<dim⁡W\dim V < \dim W, it cannot be surjective. It is the first check, with no calculation at all.

The determinant as a change of area

There is a geometric reading of the determinant that will come in very handy with the simulator. If you apply a transformation of R2\mathbb{R}^2 to the unit square formed by e⃗1\vec e_1 and e⃗2\vec e_2, you turn it into the parallelogram formed by the columns of AA. And its area is ∣det⁡A∣|\det A|.

  • ∣det⁡A∣=2|\det A| = 2: areas double. That is what stretching the photo to twice its width does, (2001)\begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix}.
  • ∣det⁡A∣=1|\det A| = 1: areas do not change. That is what the rotation and the shear (1101)\begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix} do; the shear deforms the square into a rhomboid of the same area.
  • det⁡A<0\det A < 0: on top of that, the photo is flipped, as in a mirror. The horizontal mirror (−1001)\begin{pmatrix} -1 & 0 \\ 0 & 1 \end{pmatrix} has determinant −1-1.
  • det⁡A=0\det A = 0: the square is squashed into a segment or a point. Zero area, and that is why there is no inverse: you cannot «unsquash».

In R3\mathbb{R}^3 it is the same with volumes: the unit cube becomes a parallelepiped of volume ∣det⁡A∣|\det A|. The black-and-white filter squashes the colour cube into a segment of greys, and that is why ∣M∣=0|M| = 0.

In the Plane transformations simulator you can deform the grid with any 2 × 2 matrix and watch the area of the square change (with its sign) as you move the numbers.

Change of basis: the same transformation through different glasses

The matrix of a transformation depends on the bases you use to write the coordinates. The transformation is the same; what changes is how you describe it. It is like describing the rotation of a sticker with the axes of the screen or with the edges of the sticker itself.

Before the formula, do the change of basis in your head. Take the filter that stretches the photo diagonally, f(x,y)=(2x+y,  x+2y) f(x, y) = (2x + y,\; x + 2y) , which you will look at calmly in the example below, and some new glasses: the basis of the two diagonals, {(1,1),(1,−1)} \{(1, 1), (1, -1)\} . With these glasses, the coordinates (1,0) (1, 0) mean «once the first diagonal», that is, the screen vector (1,1) (1, 1) . What does the filter do with it, counted with the glasses on?

StepComputationWhy
1New coordinates (1,0)→ (1, 0) \to vector (1,1) (1, 1) The filter only works with screen coordinates: you translate first
2f(1,1)=(3,3) f(1, 1) = (3, 3) Now you do apply the filter formula
3(3,3)=3⋅(1,1)+0⋅(1,−1)→ (3, 3) = 3 \cdot (1, 1) + 0 \cdot (1, -1) \to new coordinates (3,0) (3, 0) The result has to be counted with the glasses again: how many times each diagonal
4New coordinates (0,1)→(1,−1)→f(1,−1)=(1,−1)→(0,1) (0, 1) \to (1, -1) \to f(1, -1) = (1, -1) \to (0, 1) The same with the second basis vector

The new coordinates of the two images, (3,0) (3, 0) and (0,1) (0, 1) , in columns, are the matrix of the filter with the glasses on: it has a 3 and a 1 on the diagonal and zeros elsewhere. And the three moves in each row (translate to the screen, apply the filter, translate back to the glasses) are the three matrices of the formula coming up now, read from right to left.

If you are unsure about the order in the formula, think about what has to happen to the vector first. It arrives in new coordinates, and the filter only understands screen ones: the first matrix that touches it, the one on the right, has to be the one that translates from the new coordinates to the old ones.

If AA is the matrix of f:V→Wf : V \to W in the bases BVB_V and BWB_W, and you want the matrix A′A' in other bases BV′B'_V and BW′B'_W, the formula is

A′=CW−1 A CV A' = C_W^{-1} \, A \, C_V

where CVC_V is the change-of-basis matrix from BV′B'_V to BVB_V (its columns are the vectors of the new basis written in the old one) and CWC_W, the same in the final space. Read it right to left: CVC_V turns new coordinates into old ones, AA applies the transformation, and CW−1C_W^{-1} takes the result back to new coordinates.

If ff is an endomorphism and you use the same new basis at input and output, you get the version you will use most:

A′=C−1AC A' = C^{-1} A C

An example that previews the second half of the topic

Take the filter that stretches the photo diagonally,

f(x,y)=(2x+y,  x+2y),A=(2112) f(x, y) = (2x + y,\; x + 2y), \qquad A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}

and look at it in the basis of the two diagonals, B′={(1,1),(1,−1)}B' = \{(1, 1), (1, -1)\}. The change-of-basis matrix has those vectors in columns, and its inverse comes from the 2 × 2 formula:

C=(111−1),C−1=1−2(−1−1−11)=(121212−12) C = \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, \qquad C^{-1} = \frac{1}{-2}\begin{pmatrix} -1 & -1 \\ -1 & 1 \end{pmatrix} = \begin{pmatrix} \tfrac12 & \tfrac12 \\ \tfrac12 & -\tfrac12 \end{pmatrix}

First ACAC, which holds the images of the vectors of B′B':

AC=(2112)(111−1)=(313−1) AC = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \begin{pmatrix} 3 & 1 \\ 3 & -1 \end{pmatrix}

and then C−1(AC)C^{-1}(AC):

A′=(121212−12)(313−1)=(3001) A' = \begin{pmatrix} \tfrac12 & \tfrac12 \\ \tfrac12 & -\tfrac12 \end{pmatrix}\begin{pmatrix} 3 & 1 \\ 3 & -1 \end{pmatrix} = \begin{pmatrix} 3 & 0 \\ 0 & 1 \end{pmatrix}

Diagonal! In the basis of the diagonals, the filter only stretches the diagonal (1,1)(1, 1) threefold and leaves (1,−1)(1, -1) as it was. What looked like a mix of both coordinates in the standard basis is, with the right glasses on, a stretch. Check it in ACAC: the first column, (3,3)(3, 3), is 3⋅(1,1)3 \cdot (1, 1), and the second, (1,−1)(1, -1), is 1⋅(1,−1)1 \cdot (1, -1).

The same filter in two basesLeft: the filter with matrix (2 1; 1 2) in the standard basis: the grid is deformed and (1, 0) goes to (2, 1), changing direction. Right: in the basis of the diagonals (1, 1) and (1, −1): the diagonal (1, 1) is stretched three times and (1, −1) stays the same, and the matrix is diagonal, (3 0; 0 1).Standard basis: everything mixesDiagonal basis×3×13001A'only stretches
With diagonal glasses on, the filter is just a stretch.

Two square matrices AA and A′A' with A′=C−1ACA' = C^{-1}AC for some invertible CC are called similar: they represent the same endomorphism in different bases. Similar matrices share everything that does not depend on the basis: the determinant, the rank, the trace and, as you are about to see, the eigenvalues.

Writing A′=CAC−1A' = C A C^{-1}. With CC going from the new basis to the old one (new vectors in columns), the right formula is C−1ACC^{-1}AC: the CC that touches the vector first is the one on the right. If you are given the matrix from the old basis to the new one, then the order does flip. Always check which matrix you have.

Eigenvalues and eigenvectors: the directions that do not turn

In the previous example we found the good basis by eye. Now let us see how to always find it.

Look at what the diagonal filter does to three vectors:

  • f(1,0)=(2,1)f(1, 0) = (2, 1): it has changed direction.
  • f(1,1)=(3,3)=3⋅(1,1)f(1, 1) = (3, 3) = 3 \cdot (1, 1): same direction, three times as long.
  • f(1,−1)=(1,−1)=1⋅(1,−1)f(1, -1) = (1, -1) = 1 \cdot (1, -1): exactly the same.
The directions that do not turnThree vectors and their images under f(x, y) = (2x + y, x + 2y). (1, 0) goes to (2, 1) and changes direction. (1, 1) goes to (3, 3), on the same line and three times longer. (1, −1) goes to itself. The two diagonal lines, highlighted, are the ones that do not turn.(2, 1)(1, 0)(3, 3) = 3 · (1, 1)(1, −1) → (1, −1)f(x, y) = (2x + y, x + 2y)(1, 0): turns. Not an eigenvector.(1, 1): same line, ×3.Eigenvector, eigenvalue 3.(1, −1): stays the same.Eigenvector, eigenvalue 1.The indigo bands are the twolines that do not turn.
An eigenvector stays on its line after the filter; the eigenvalue says how much it stretches.

The last two are special: the filter does not turn them, it only multiplies them by a number. The definition: if ff is an endomorphism and a vector v⃗≠0⃗\vec v \neq \vec 0 satisfies

f(v⃗)=λv⃗(or Av⃗=λv⃗) f(\vec v) = \lambda \vec v \qquad (\text{or } A\vec v = \lambda \vec v)

then v⃗\vec v is an eigenvector of ff and λ∈R\lambda \in \mathbb{R} is its associated eigenvalue. In the diagonal filter, (1,1)(1, 1) is an eigenvector with eigenvalue 3 and (1,−1)(1, -1), an eigenvector with eigenvalue 1.

A few things you need to know by heart:

  • The eigenvector is never the zero vector (A0⃗=λ0⃗A\vec 0 = \lambda \vec 0 for any λ\lambda, so it would tell us nothing). The eigenvalue can be 0: then Av⃗=0⃗A\vec v = \vec 0 and the eigenvector lies in the kernel.
  • If v⃗\vec v is an eigenvector, so is any multiple αv⃗\alpha\vec v with α≠0\alpha \neq 0: (2,2)(2, 2) and (−5,−5)(-5, -5) are eigenvectors with eigenvalue 3. What matters is the direction.
  • All the eigenvectors of the same eigenvalue λ\lambda, together with 0⃗\vec 0, form a subspace: the eigenspace UλU_\lambda.
  • Each eigenvector has a single eigenvalue (it cannot be stretched by 3 and by 1 at the same time).
  • Eigenvectors of different eigenvalues are linearly independent.

How to compute them: the characteristic polynomial

The equation Av⃗=λv⃗A\vec v = \lambda\vec v can be written as Av⃗−λIv⃗=0⃗A\vec v – \lambda I\vec v = \vec 0, that is,

(A−λI)v⃗=0⃗ (A – \lambda I)\vec v = \vec 0

It is a homogeneous system. It always has the solution v⃗=0⃗\vec v = \vec 0, but that one is no use to us: we want others. And a square homogeneous system has non-zero solutions exactly when its determinant is zero (topic 2). So the eigenvalues are the solutions of

P(λ)=∣A−λI∣=0 P(\lambda) = |A – \lambda I| = 0

P(λ)P(\lambda) is the characteristic polynomial. For the diagonal filter:

∣A−λI∣=∣2−λ112−λ∣=(2−λ)2−1=λ2−4λ+3=(λ−1)(λ−3) |A – \lambda I| = \begin{vmatrix} 2 – \lambda & 1 \\ 1 & 2 – \lambda \end{vmatrix} = (2 – \lambda)^2 – 1 = \lambda^2 – 4\lambda + 3 = (\lambda – 1)(\lambda – 3)

That computation, without skipping anything:

StepComputationWhy
1A−λI=(2−λ112−λ) A – \lambda I = \begin{pmatrix} 2 – \lambda & 1 \\ 1 & 2 – \lambda \end{pmatrix} λI \lambda I only has λ \lambda on the diagonal: off it you subtract 0
2(2−λ)(2−λ)−1⋅1 (2 – \lambda)(2 – \lambda) – 1 \cdot 1 2×2 2 \times 2 determinant: main diagonal minus the other diagonal
34−4λ+λ2−1=λ2−4λ+3 4 – 4\lambda + \lambda^2 – 1 = \lambda^2 – 4\lambda + 3 You expand the square: (2−λ)2=4−4λ+λ2 (2 – \lambda)^2 = 4 – 4\lambda + \lambda^2
4(λ−1)(λ−3) (\lambda – 1)(\lambda – 3) You look for two numbers whose product is 3 and whose sum is 4: 1 and 3
5λ=1 \lambda = 1 or λ=3 \lambda = 3 A product is zero when one of its factors is

Subtracting λ \lambda from every entry of A A , including the ones off the diagonal. The identity matrix has zeros off the diagonal, so those entries stay as they were. If you get a strange polynomial, check this first.

Check you’ve got it: is 2 an eigenvalue of the diagonal filter?

No. Step by step: A−2I=(0110) A – 2I = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} , and its determinant is 0⋅0−1⋅1=−1≠0 0 \cdot 0 – 1 \cdot 1 = -1 \neq 0 . With a non-zero determinant, the system (A−2I)v⃗=0⃗ (A – 2I)\vec v = \vec 0 only has the solution v⃗=0⃗ \vec v = \vec 0 , which does not count as an eigenvector. You can also see it without determinants: Av⃗=2v⃗ A\vec v = 2\vec v would be (2x+y,  x+2y)=(2x,2y) (2x + y,\; x + 2y) = (2x, 2y) , which forces y=0 y = 0 and x=0 x = 0 . No direction is stretched by exactly two.

Eigenvalues: λ1=1\lambda_1 = 1 and λ2=3\lambda_2 = 3. For each one, the eigenvectors are the solutions of (A−λI)v⃗=0⃗(A – \lambda I)\vec v = \vec 0:

  • λ=3\lambda = 3: A−3I=(−111−1)A – 3I = \begin{pmatrix} -1 & 1 \\ 1 & -1 \end{pmatrix}. Both rows say the same, −x+y=0-x + y = 0, so y=xy = x: U3={(x,x)}U_3 = \{(x, x)\}, basis {(1,1)}\{(1, 1)\}.
  • λ=1\lambda = 1: A−I=(1111)A – I = \begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix}. Now x+y=0x + y = 0, y=−xy = -x: U1={(x,−x)}U_1 = \{(x, -x)\}, basis {(1,−1)}\{(1, -1)\}.

Exactly the two diagonals.

Two free checks for the characteristic polynomial. The sum of the eigenvalues is the trace of AA (here 1+3=2+21 + 3 = 2 + 2) and their product is the determinant (1⋅3=4−11 \cdot 3 = 4 – 1). If they do not match, something is wrong before you even start on the eigenvectors.

The two multiplicities

An eigenvalue can come out repeated in the characteristic polynomial. Each eigenvalue λi\lambda_i is described by two numbers:

  • Algebraic multiplicity mλim_{\lambda_i}: how many times it is a root of P(λ)P(\lambda).
  • Geometric multiplicity dλid_{\lambda_i}: the dimension of its eigenspace, that is, how many independent eigenvectors it has. You compute it without solving anything:
dλi=dim⁡Uλi=n−rg⁡(A−λiI) d_{\lambda_i} = \dim U_{\lambda_i} = n – \operatorname{rg}(A – \lambda_i I)

And it always holds that

1≤dλi≤mλi 1 \le d_{\lambda_i} \le m_{\lambda_i}

So a simple eigenvalue (m=1m = 1) always has d=1d = 1, and you do not need to look at it. You only have to compute the geometric multiplicity of the repeated eigenvalues.

Computing dλd_\lambda as n−rg⁡(A)n – \operatorname{rg}(A), with AA without subtracting λ\lambda. That is the dimension of the kernel, which only matches UλU_\lambda when λ=0\lambda = 0. The matrix to look at is A−λIA – \lambda I, one for each eigenvalue.

Diagonalising: the filter as a plain stretch

Before the definition, go back to the glasses of the diagonals and ask yourself why a diagonal matrix came out. The first column of A′ A' holds the coordinates, with the glasses on, of the image of the first basis vector. Since (1,1) (1, 1) is an eigenvector, its image is 3⋅(1,1) 3 \cdot (1, 1) : three times the first vector and zero times the second, (3,0) (3, 0) . The second one, (1,−1) (1, -1) , stays as it is: (0,1) (0, 1) . Each column has a single non-zero number, right in its place on the diagonal, and that number is the eigenvalue.

Now swap one of the two for a vector that does turn, for example (1,0) (1, 0) , and use the basis {(1,0),(1,−1)} \{(1, 0), (1, -1)\} . Its image, (2,1) (2, 1) , is no longer a multiple of (1,0) (1, 0) : with these glasses it is 3⋅(1,0)−1⋅(1,−1) 3 \cdot (1, 0) – 1 \cdot (1, -1) , and its column becomes (3,−1) (3, -1) , with two numbers. The diagonal breaks.

So the recipe, in words, is: find enough directions that do not turn to make a basis, put them in columns, and the matrix of the filter in that basis is diagonal, with the eigenvalues on the diagonal. The matrix of eigenvectors in columns is the C C of the change of basis; in this section it is called P P . The same thing, stated with the official definition:

A square matrix AA is diagonalisable if it is similar to a diagonal matrix: there is an invertible matrix PP (the change-of-basis matrix, or modal matrix) with

D=P−1AP D = P^{-1} A P

We already did it in the diagonals example: with PP = the eigenvectors in columns, DD has the eigenvalues on the diagonal. That is no coincidence. In general:

  • The columns of PP are eigenvectors of AA that form a basis.
  • The diagonal of DD holds their eigenvalues, in the same order as the eigenvectors in PP.

So diagonalising means finding a basis of eigenvectors. And that cannot always be done.

When it can be done: the two conditions

A matrix AA of size nn is diagonalisable over R\mathbb{R} if and only if both conditions hold:

  1. All eigenvalues are real: the roots of P(λ)P(\lambda) are real numbers (counted with multiplicity, they add up to nn).
  2. For each eigenvalue, the algebraic multiplicity equals the geometric one: mλi=dλim_{\lambda_i} = d_{\lambda_i}.

A handy consequence: if AA has nn distinct real eigenvalues, it is certainly diagonalisable, because all of them are simple and for them d=m=1d = m = 1.

How to decide whether A is diagonalisableFlowchart: compute the eigenvalues with the characteristic polynomial; if any is not real, it is not diagonalisable. If they are real, compute the geometric multiplicity of each repeated eigenvalue; if any differs from the algebraic one, it is not diagonalisable. If they match, compute the eigenvectors and build P and D in the same order.1. Eigenvalues|A − λI| = 0All real?Nonot diagonalisableYes2. For each repeated λd = n − rg(A − λI)m = d for all?Nonot diagonalisableYes3. Eigenvectors(A − λI)v = 04. P and D in the same orderD = P⁻¹APA simple eigenvaluealways has d = 1:only the repeatedones are checked.
Two questions, two exits: almost every exam exercise follows this path.

The full recipe, with a colour filter

Let us take a filter of R3\mathbb{R}^3 that mixes channels: each new channel is twice itself plus the other two.

A=(211121112) A = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}

If you did the topic 1 exercises, you already computed its characteristic polynomial: ∣A−λI∣=(1−λ)2(4−λ)|A – \lambda I| = (1 – \lambda)^2 (4 – \lambda).

If you do not have it to hand, this is how it comes out without expanding the determinant by brute force. The trick is that every row of A−λI A – \lambda I adds up to the same thing:

StepComputationWhy
1A−λI=(2−λ1112−λ1112−λ) A – \lambda I = \begin{pmatrix} 2 – \lambda & 1 & 1 \\ 1 & 2 – \lambda & 1 \\ 1 & 1 & 2 – \lambda \end{pmatrix} You subtract λ \lambda only on the diagonal
2c1→c1+c2+c3 c_1 \to c_1 + c_2 + c_3 : the first column becomes (4−λ,4−λ,4−λ) (4 – \lambda, 4 – \lambda, 4 – \lambda) Each row adds up to (2−λ)+1+1=4−λ (2 – \lambda) + 1 + 1 = 4 – \lambda , and adding the other columns to one column does not change the determinant
3You take 4−λ 4 – \lambda out: the first column becomes (1,1,1) (1, 1, 1) If a whole column is multiplied by a number, that number comes out multiplying the determinant
4r2→r2−r1 r_2 \to r_2 – r_1 , r3→r3−r1 r_3 \to r_3 – r_1 : you get (11101−λ0001−λ) \begin{pmatrix} 1 & 1 & 1 \\ 0 & 1 – \lambda & 0 \\ 0 & 0 & 1 – \lambda \end{pmatrix} Subtracting rows does not change the determinant either, and it makes zeros below the 1
5(4−λ)⋅1⋅(1−λ)(1−λ) (4 – \lambda) \cdot 1 \cdot (1 – \lambda)(1 – \lambda) The determinant of a triangular matrix is the product of its diagonal

You get (1−λ)2(4−λ) (1 – \lambda)^2 (4 – \lambda) , the same polynomial, and already factorised: no need to look for the roots of a degree-3 polynomial.

Step 1. Eigenvalues. λ1=1\lambda_1 = 1 with m1=2m_1 = 2 and λ2=4\lambda_2 = 4 with m4=1m_4 = 1. All real: first condition met. Check: 1+1+4=6=tr⁡(A)1 + 1 + 4 = 6 = \operatorname{tr}(A) and 1⋅1⋅4=4=∣A∣1 \cdot 1 \cdot 4 = 4 = |A|.

Step 2. Geometric multiplicities. Only the repeated one needs checking, λ=1\lambda = 1:

A−I=(111111111),rg⁡(A−I)=1,d1=3−1=2=m1 A – I = \begin{pmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{pmatrix}, \qquad \operatorname{rg}(A – I) = 1, \qquad d_1 = 3 – 1 = 2 = m_1

Second condition met: AA is diagonalisable.

Step 3. Eigenvectors. For λ=1\lambda = 1, the system (A−I)v⃗=0⃗(A – I)\vec v = \vec 0 is a single equation, x+y+z=0x + y + z = 0, with two parameters: x=−y−zx = -y – z. Setting (y,z)=(1,0)(y, z) = (1, 0) and (0,1)(0, 1):

U1={(−y−z,y,z)},BU1={(−1,1,0),  (−1,0,1)} U_1 = \{(-y – z, y, z)\}, \qquad B_{U_1} = \{(-1, 1, 0),\; (-1, 0, 1)\}

For λ=4\lambda = 4:

A−4I=(−2111−2111−2)→  r1↔r2  (1−21−21111−2)→ r3→r3−r1  r2→r2+2r1 (1−210−3303−3) A – 4I = \begin{pmatrix} -2 & 1 & 1 \\ 1 & -2 & 1 \\ 1 & 1 & -2 \end{pmatrix} \xrightarrow{\; r_1 \leftrightarrow r_2 \;} \begin{pmatrix} 1 & -2 & 1 \\ -2 & 1 & 1 \\ 1 & 1 & -2 \end{pmatrix} \xrightarrow[\, r_3 \to r_3 – r_1 \,]{\, r_2 \to r_2 + 2r_1 \,} \begin{pmatrix} 1 & -2 & 1 \\ 0 & -3 & 3 \\ 0 & 3 & -3 \end{pmatrix}

The third row is the second with the sign changed, so we are left with x−2y+z=0x – 2y + z = 0 and −3y+3z=0-3y + 3z = 0: y=zy = z and x=2z−z=zx = 2z – z = z. Basis of U4U_4: {(1,1,1)}\{(1, 1, 1)\}.

Step 4. Build PP and DD, in the same order:

P=(−1−11101011),D=(100010004) P = \begin{pmatrix} -1 & -1 & 1 \\ 1 & 0 & 1 \\ 0 & 1 & 1 \end{pmatrix}, \qquad D = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 4 \end{pmatrix}

Step 5. Check without computing P−1P^{-1}: it is enough to see that AP=PDAP = PD. For instance, the third column of APAP is A(1,1,1)=(4,4,4)A(1, 1, 1) = (4, 4, 4), and the third column of PDPD is 4⋅(1,1,1)4 \cdot (1, 1, 1). Likewise for the other two.

Back to the photo: the colours with R+G+B=0R + G + B = 0 (not real colours, but vectors all the same) do not change, and the greys (t,t,t)(t, t, t) are multiplied by 4. Any other colour is a mix of the two.

Mixing up the order of PP and DD. If you put (1,1,1)(1, 1, 1) in the first column of PP, the 4 has to go first on the diagonal of DD. The diagonalisation is still valid in another order, but both must go together.

When it cannot be diagonalised

There are two ways to fail, one per condition, and both can be seen in the plane.

The shear. H=(1101)H = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}, f(x,y)=(x+y,y)f(x, y) = (x + y, y), slants the sticker like an italic letter. Its polynomial is (1−λ)2(1 – \lambda)^2: eigenvalue 1, double, m1=2m_1 = 2. But

H−I=(0100),rg⁡(H−I)=1,d1=2−1=1≠2 H – I = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}, \qquad \operatorname{rg}(H – I) = 1, \qquad d_1 = 2 – 1 = 1 \neq 2

There is only one direction that does not turn, the horizontal (1,0)(1, 0). One eigenvector short of a basis: it is not diagonalisable.

The 90° rotation. Its polynomial is ∣−λ−11−λ∣=λ2+1\begin{vmatrix} -\lambda & -1 \\ 1 & -\lambda \end{vmatrix} = \lambda^2 + 1, which has no real roots (they are ±i\pm i, which you will meet in the complex numbers topic). It makes sense: when you rotate by 90°, no direction stays put. It is not diagonalisable over R\mathbb{R}.

Two matrices that cannot be diagonalisedLeft: the shear tilts the grid; the horizontal axis stays put, but every other direction leans over, so there is only one line of eigenvectors. Right: the 90-degree rotation; every direction turns and there are no real eigenvalues.Shear (1 1; 0 1)λ = 1 double, but only one eigenvector90° rotation (0 −1; 1 0)λ² + 1 = 0: no real eigenvalue
The shear fails the second condition and the rotation fails the first.

Symmetric matrices always can be

There is a family that never fails: every real symmetric matrix (At=AA^t = A) is diagonalisable, its eigenvalues are real and eigenvectors of different eigenvalues are orthogonal. Both examples in this section (the diagonal filter and the channel mixer) are symmetric, and look: (1,1)⋅(1,−1)=0(1, 1) \cdot (1, -1) = 0 and (1,1,1)⋅(−1,1,0)=0(1, 1, 1) \cdot (-1, 1, 0) = 0. You will need this in the next topic, bilinear and quadratic forms, because there all matrices are symmetric.

What it is for: powers of a matrix

Applying the diagonal filter five times in a row means computing A5A^5. By hand, four matrix products. With the diagonalisation, almost nothing. From D=P−1APD = P^{-1}AP you get A=PDP−1A = PDP^{-1}, and when you multiply AA by itself the PPs in the middle cancel out:

A2=PDP−1⋅PDP−1=PD(P−1P)DP−1=PD2P−1,Ak=PDkP−1 A^2 = PDP^{-1} \cdot PDP^{-1} = PD(P^{-1}P)DP^{-1} = PD^2P^{-1}, \qquad A^k = PD^kP^{-1}

And the power of a diagonal matrix just raises each number on the diagonal. With the diagonal filter, P=(111−1)P = \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}, D=(3001)D = \begin{pmatrix} 3 & 0 \\ 0 & 1 \end{pmatrix} and P−1=12(111−1)P^{-1} = \tfrac12\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}:

Ak=(111−1)(3k001)12(111−1)=12(3k+13k−13k−13k+1) A^k = \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\begin{pmatrix} 3^k & 0 \\ 0 & 1 \end{pmatrix}\frac12\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \frac12\begin{pmatrix} 3^k + 1 & 3^k – 1 \\ 3^k – 1 & 3^k + 1 \end{pmatrix}

With k=5k = 5: 35=2433^5 = 243, so A5=(122121121122)A^5 = \begin{pmatrix} 122 & 121 \\ 121 & 122 \end{pmatrix}. And with k=1k = 1 you get AA back, which is the quickest check of the formula.

Powers through diagonalisationThree boxes in a row: P inverse switches to the eigenvector basis, D to the k stretches each direction by 3 to the k and by 1, and P goes back to the screen basis. Below, the result for k = 5: the matrix (122 121; 121 122).P⁻¹switch to theeigenvector basisDᵏstretch each direction3ᵏ and 1ᵏPback to thescreen basisAᵏ = P · Dᵏ · P⁻¹ (read right to left)A⁵ = (122 121; 121 122)with 3⁵ = 243: each entry is (243 ± 1) / 2
The middle Ps cancel out: applying the filter k times is stretching k times.

The glasses reading: P−1P^{-1} switches to the eigenvector basis, DkD^k stretches each direction kk times and PP goes back to the screen basis. That is why, when a filter is applied many times, the direction of the largest eigenvalue takes over: the photo ends up stretched almost only along the diagonal.

In the exam, «compute AnA^n» always comes after «study whether it is diagonalisable». If it is, the result is PDnP−1PD^nP^{-1} with nn as a letter; leave the expression with powers (3n3^n) and check with n=1n = 1 that you get AA.

Powers, step by step

This is how A5 A^5 of the diagonal filter comes out with PD5P−1 PD^5P^{-1} , multiplying from left to right:

StepComputationWhy
1D5=(350015)=(243001) D^5 = \begin{pmatrix} 3^5 & 0 \\ 0 & 1^5 \end{pmatrix} = \begin{pmatrix} 243 & 0 \\ 0 & 1 \end{pmatrix} When you multiply two diagonal matrices, only the diagonal entries get multiplied together
2PD5=(2431243−1) PD^5 = \begin{pmatrix} 243 & 1 \\ 243 & -1 \end{pmatrix} Multiplying by a diagonal matrix on the right scales the columns: the first by 243 and the second by 1
3PD5⋅12(111−1)=12(244242242244) PD^5 \cdot \tfrac12\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} = \tfrac12\begin{pmatrix} 244 & 242 \\ 242 & 244 \end{pmatrix} Row by column: 243+1=244 243 + 1 = 244 and 243−1=242 243 – 1 = 242
4A5=(122121121122) A^5 = \begin{pmatrix} 122 & 121 \\ 121 & 122 \end{pmatrix} You divide by 2

The direct way would have taken four products of full matrices; here, only two, and one of them with a diagonal matrix. And the table shows why the large eigenvalue takes over: the 243 of the direction (1,1) (1, 1) swamps the 1 of the direction (1,−1) (1, -1) , and that is why the four entries of A5 A^5 are almost equal. With k=20 k = 20 the difference between the entries would still be 1, against ten-digit numbers.

Check you’ve got it: what is A² with the formula? Check it by multiplying.

A2=(5445) A^2 = \begin{pmatrix} 5 & 4 \\ 4 & 5 \end{pmatrix} . Step by step: with k=2 k = 2 , 32=9 3^2 = 9 , so 12(9+1)=5 \tfrac12(9 + 1) = 5 on the diagonal and 12(9−1)=4 \tfrac12(9 – 1) = 4 off it. Multiplying directly, the first row of A A times the first column gives 2⋅2+1⋅1=5 2 \cdot 2 + 1 \cdot 1 = 5 and times the second, 2⋅1+1⋅2=4 2 \cdot 1 + 1 \cdot 2 = 4 ; the second row comes out the same but in the other order. They match.

The same in MATLAB

MATLAB does not diagonalise in a single command as on paper, but it has everything you need to check each step. This script goes over the channel-mixing filter with the commands from the lab assignments:

format rat
A = [2 1 1; 1 2 1; 1 1 2];   % channel-mixing filter
eig(A)                        % eigenvalues (sorted)
poly(A)                       % coefficients of det(lambda*I - A)
rank(A - eye(3))              % d = 3 - rank = 2 for lambda = 1
U1 = null(A - eye(3), 'r')    % basis of U1, paper style
U4 = null(A - 4*eye(3), 'r')  % basis of U4
P = [U1 U4]                   % change-of-basis matrix: eigenvectors in columns
D = inv(sym(P))*A*P           % exact with sym: comes out diagonal

Output:

ans =

       1       
       1       
       4       

ans =

       1             -6              9             -4       

ans =

       1       

U1 =

      -1             -1       
       1              0       
       0              1       

U4 =

       1       
       1       
       1       

P =

      -1             -1              1       
       1              0              1       
       0              1              1       

 
D =
 
[1, 0, 0]
[0, 1, 0]
[0, 0, 4]
 

What to look at in each output:

  • eig(A) gives the eigenvalues in a column, sorted from smallest to largest: 1, 1 and 4.
  • poly(A) gives the coefficients of λ3−6λ2+9λ−4\lambda^3 – 6\lambda^2 + 9\lambda – 4, which is ∣λI−A∣|\lambda I – A|, ours with the sign changed (the roots are the same).
  • null(M, 'r') solves Mv⃗=0⃗M\vec v = \vec 0 just as on paper: it sets each free variable to 1, one at a time. That is why it gives (−1,1,0)(-1, 1, 0) and (−1,0,1)(-1, 0, 1), the same ones we found by hand. Without 'r', null gives vectors of length 1 with decimals, which are also eigenvectors but look nothing like yours.
  • inv(sym(P))*A*P is P−1APP^{-1}AP computed with exact fractions (sym turns the matrix into a symbolic one). If it comes out diagonal, with the eigenvalues in the order of the columns of PP, the diagonalisation is right. Without sym, MATLAB works with decimals and some zero comes out as a tiny number, which format rat prints as an asterisk.

The powers of the diagonal filter, both ways:

A = [2 1; 1 2];
P = [1 1; 1 -1];   D = [3 0; 0 1];
A^5                % multiplying directly
P*D^5*inv(P)       % with the diagonalisation

Output:

ans =

     122            121       
     121            122       

ans =

     122            121       
     121            122       

Both outputs match. Watch the difference between D^5 (matrix power) and D.^5 (each entry to the fifth): with a diagonal matrix they give the same, but with AA they do not.

MATLAB also has [P, D] = eig(A), which returns both matrices at once. But it normalises each eigenvector to length 1 (with decimals such as 0.7071) and orders them its own way, so its PP does not look like yours even though it is just as valid. To check your paper, null(A - lambda*eye(n), 'r') is handier, and it is what the lab assignments use.

Try it in the MATLAB playground

In the website’s MATLAB playground you can run this script without installing anything. It checks the photo filters: the kernel and image of black and white, and why the shear refuses to be diagonalised.

format rat
M = ones(3)/3;              % black-and-white filter
M*[240; 120; 0]             % an orange...
M*[0; 60; 300]              % ...and a blue give the same grey
rank(M)                     % dim Im = 1
null(M, 'r')                % basis of the kernel: dim 2
H = [1 1; 0 1];             % shear (slant)
eig(H)                      % eigenvalue 1, double
2 - rank(H - eye(2))        % but only one eigenvector

Things to look at:

  1. The first two outputs are equal: check on paper that (240,120,0)−(0,60,300)(240, 120, 0) – (0, 60, 300) lies in the kernel that null(M, 'r') gives.
  2. In the Workspace panel, M shows up with fractions (1/3) thanks to format rat. Remove it and you will see 0.3333.
  3. Change H to the rotation [0 -1; 1 0] and run eig: MATLAB will give you two numbers with i, which are not real.
  4. Try det(M), det(H) and det([2 0; 0 1]) and relate them to what happens to the area of the square.

Summary

ConceptWhat it isHow to do it by handIn MATLAB
Associated matrixImages of the basis in columnsf(e⃗j)f(\vec e_j) in column jj; with standard bases, coefficients in rowsA
Image of a vectorf(v⃗)f(\vec v)Av⃗A\vec vA*v
PreimageVectors that land on w⃗\vec wSolve Av⃗=w⃗A\vec v = \vec wrref([A w])
KernelVectors that land on 0⃗\vec 0Solve Av⃗=0⃗A\vec v = \vec 0; dim⁡=n−rg⁡(A)\dim = n – \operatorname{rg}(A)null(A, 'r')
ImageEverything that can be reachedColumns of AA with a pivot; dim⁡=rg⁡(A)\dim = \operatorname{rg}(A)rank(A)
Change of basisSame ff, other coordinatesA′=CW−1ACVA' = C_W^{-1}AC_V; endomorphism, C−1ACC^{-1}ACinv(C)*A*C
EigenvaluesRoots of ∣A−λI∣=0\lvert A – \lambda I \rvert = 0Characteristic polynomialeig(A)
EigenvectorsSolutions of (A−λI)v⃗=0⃗(A – \lambda I)\vec v = \vec 0One system per eigenvaluenull(A - l*eye(n), 'r')
DiagonalisingD=P−1APD = P^{-1}APReal and mλ=dλm_\lambda = d_\lambda for allinv(P)*A*P
PowersAk=PDkP−1A^k = PD^kP^{-1}Raise the diagonal of DDP*D^k*inv(P)

Three ideas to take away:

  1. A linear transformation is fixed by the images of the basis, and those images, in columns, are its matrix. Everything else (image, kernel, injectivity, change of basis) is computed with that matrix and what you already know about ranks and systems.
  2. dim⁡V=dim⁡Ker⁡+dim⁡Im⁡\dim V = \dim\operatorname{Ker} + \dim\operatorname{Im}: what goes in is shared between what is lost and what arrives. Compute the rank first and you will know how many vectors to look for.
  3. Diagonalising means finding the directions that do not turn. You need the eigenvalues to be real and each one to have as many independent eigenvectors as times it is repeated; if so, D=P−1APD = P^{-1}AP and the powers come for free.

Now it is your turn: in the guided practice on linear transformations and diagonalisation we solve five problems step by step, each one checked in MATLAB, and in the Plane transformations simulator you can deform the grid with any matrix and see its eigenvectors. And to check you have got it, the linear transformations and diagonalisation exercises go from easy to hard, come with commented solutions and include a quiz like the Campus ones. After that, topic 6: bilinear and quadratic forms, where today’s symmetric matrices tell you whether a surface is a bowl, a saddle or a channel.

Next step: practiceLinear transformations and diagonalisation — guided practice with colour filters, layers that get lost and a matrix with a parameter as in the exam (and the basis that fixed nothing)

Did this article help you? Here is how you can support SergioLearns →