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: .
Table of Contents
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 and a 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, and . 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:
| Filter | Blend, then filter | Filter, then blend | Why |
|---|---|---|---|
| Contrast | Multiplying the sum by 1.5 is the same as adding what has been multiplied | ||
| Brightness | 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, and filtering gives ; filtering first gives , and doubling it, 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 that takes a vector from a vector space (the initial space, or domain) and gives it a vector in another space (the final space, or codomain):
Not any rule will do. To be linear it must meet two conditions:
- It respects addition: for all .
- It respects multiplication by a number: for every and every .
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 (), the transformation is called an endomorphism. Rotating a sticker on the screen is an endomorphism of : 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 to :
Let us check both conditions with letters. If and :
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 with its three colour channels (red, green, blue): . Raising the brightness by adding 20 is
Just look at black, : . And a linear transformation always sends the zero vector to the zero vector, because . So is not linear. On the other hand, raising the contrast by multiplying by 1.5,
is linear: , and the same goes for scalars.
To rule out linearity, try zero first. If , it is not linear and you are done. If , it may still fail (for instance, ): then you have to check both conditions.
Along the same lines, any rule with a loose added number (), powers (), products of coordinates (), roots or absolute values is not linear. A linear transformation only has, in each coordinate, sums of the coordinates multiplied by numbers: .
Image and preimage
If , we say is the image of . The other way round, the preimage of a vector of the final space is the set of vectors that land on it:
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 respects combinations.
In , with the standard basis and , the 90° rotation does
Before building the matrix, work out an image yourself with only those two facts. Where does go? You do not need the rotation formula:
| Step | Computation | Why |
|---|---|---|
| 1 | Every arrow in the plane is so many times plus so many times : exactly its coordinates | |
| 2 | respects sums and scaling, so it can be split into parts | |
| 3 | You substitute the two images you already know | |
| 4 | 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 . Step by step: ; since respects combinations, . Check it with the rotation formula, : . They match, and you did not need the formula at all.
Put those two images in columns and you have the associated matrix of in the standard basis:
With it, the image of any vector is a matrix product, with the vector as a column:
The picture shows it on the grid: the orange arrow ends where the first column says and the violet , where the second one says. The whole grid moves with them.
In general, if with and , the associated matrix has size : 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 is an endomorphism, is square.
The shortcut from the formula
When both bases are standard, there is a shortcut: the coefficients of each coordinate of go in rows. For instance, a colour gradient that turns the position of a pixel into a colour could be
It is : two columns because it starts in and three rows because it lands in . And the columns are still the images of the basis: and . 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: times the vector 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 «» or «», «the kernel of » or «the kernel of », interchangeably.
Computing a preimage means solving a system
If you want the vectors that land on , you have to solve : a system of equations from topic 2, with coefficient matrix and right-hand side . Rouché-Frobenius tells you how many solutions there are:
- Consistent with a unique solution: a single vector goes to .
- Consistent with infinitely many: infinitely many vectors go to .
- Inconsistent: none. is not the image of anything.
If is square with , it is direct: , 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:
Try an orange, : the average is 120 and you get the grey . With a blue, … also . 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 , , is the set of vectors of the initial space that land on the zero vector:
It is always a subspace of the initial space. To compute it, you solve the homogeneous system , that is, you row reduce .
In the black-and-white filter, when . That is a plane of (one equation, three unknowns, two parameters):
And what has it got to do with the two colours from before? Their difference, , adds up to zero: it is in the kernel. Two vectors have the same image exactly when their difference is in the kernel, because . 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 :
| Step | What you do | Why |
|---|---|---|
| 1 | You write the three equations: , three times | Each output channel is the average, and all three have to be 0 |
| 2 | You multiply by 3: | Something divided by 3 is 0 exactly when that something is 0 |
| 3 | You row reduce: and leave two rows of zeros | The three equations are the same one: the rank is 1 |
| 4 | Pivot on , free and : | Three unknowns and one useful equation leave parameters |
| 5 | gives ; gives | One vector per parameter, setting each free one to 1 and the other to 0 |
The check takes a second: and , 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: .
Check you’ve got it: which colours give the same grey as the orange (240, 120, 0)?
All the with . 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: . Those vectors always add up to , and their average is 120. It is the preimage of , a whole plane of colours. The blue is in it: .
The image
The image (or range) of , , is the set of all vectors of the final space that are the image of some vector:
It is a subspace of the final space, and the way to compute it comes from the matrix: since is a combination of the columns of , the columns of 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,
In the black-and-white filter, the three columns of are equal, , so and the image is the line of greys: . Everything that comes out of the filter is grey; a pure red cannot be reached.
The dimension formula
There is a relation you will use in every exercise:
The dimension of the initial space is shared between what is lost and what arrives. In the filter: . In the 90° rotation: (the only vector that becomes zero when rotated is zero), so and the image is the whole of .
Always compute the rank first. With it you have and , with 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 , with , the kernel has dimension , not .
Injective, surjective and bijective
With the kernel and the image you can answer the three classic questions about a transformation:
| Type | What it means | How to check it | Example |
|---|---|---|---|
| Injective (one-to-one) | Different vectors go to different images | , that is, (columns) | The gradient : no two pixels share a colour |
| Surjective (onto) | Every vector of the final space is the image of some vector | , that is, (rows) | The 90° rotation |
| Bijective (isomorphism) | Injective and surjective at once: every vector has a partner and only one | Both conditions; if is square, | The 90° rotation |
The black-and-white filter is neither injective (kernel of dimension 2) nor surjective (image of dimension 1 in ). The gradient is injective but not surjective: with two numbers you cannot reach every colour in .
For an endomorphism everything simplifies: since , injective, surjective and bijective are the same thing, and the determinant decides. If , it is bijective and has an inverse, , whose matrix is : undoing the filter. If , the filter has eaten something and there is no way back.
If (more columns than rows), cannot be injective: the rank is at most , so the kernel has dimension at least . And if , 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 to the unit square formed by and , you turn it into the parallelogram formed by the columns of . And its area is .
- : areas double. That is what stretching the photo to twice its width does, .
- : areas do not change. That is what the rotation and the shear do; the shear deforms the square into a rhomboid of the same area.
- : on top of that, the photo is flipped, as in a mirror. The horizontal mirror has determinant .
- : the square is squashed into a segment or a point. Zero area, and that is why there is no inverse: you cannot «unsquash».
In it is the same with volumes: the unit cube becomes a parallelepiped of volume . The black-and-white filter squashes the colour cube into a segment of greys, and that is why .
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, , which you will look at calmly in the example below, and some new glasses: the basis of the two diagonals, . With these glasses, the coordinates mean «once the first diagonal», that is, the screen vector . What does the filter do with it, counted with the glasses on?
| Step | Computation | Why |
|---|---|---|
| 1 | New coordinates vector | The filter only works with screen coordinates: you translate first |
| 2 | Now you do apply the filter formula | |
| 3 | new coordinates | The result has to be counted with the glasses again: how many times each diagonal |
| 4 | New coordinates | The same with the second basis vector |
The new coordinates of the two images, and , 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 is the matrix of in the bases and , and you want the matrix in other bases and , the formula is
where is the change-of-basis matrix from to (its columns are the vectors of the new basis written in the old one) and , the same in the final space. Read it right to left: turns new coordinates into old ones, applies the transformation, and takes the result back to new coordinates.
If is an endomorphism and you use the same new basis at input and output, you get the version you will use most:
An example that previews the second half of the topic
Take the filter that stretches the photo diagonally,
and look at it in the basis of the two diagonals, . The change-of-basis matrix has those vectors in columns, and its inverse comes from the 2 × 2 formula:
First , which holds the images of the vectors of :
and then :
Diagonal! In the basis of the diagonals, the filter only stretches the diagonal threefold and leaves 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 : the first column, , is , and the second, , is .
Two square matrices and with for some invertible 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 . With going from the new basis to the old one (new vectors in columns), the right formula is : the 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:
- : it has changed direction.
- : same direction, three times as long.
- : exactly the same.
The last two are special: the filter does not turn them, it only multiplies them by a number. The definition: if is an endomorphism and a vector satisfies
then is an eigenvector of and is its associated eigenvalue. In the diagonal filter, is an eigenvector with eigenvalue 3 and , an eigenvector with eigenvalue 1.
A few things you need to know by heart:
- The eigenvector is never the zero vector ( for any , so it would tell us nothing). The eigenvalue can be 0: then and the eigenvector lies in the kernel.
- If is an eigenvector, so is any multiple with : and are eigenvectors with eigenvalue 3. What matters is the direction.
- All the eigenvectors of the same eigenvalue , together with , form a subspace: the eigenspace .
- 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 can be written as , that is,
It is a homogeneous system. It always has the solution , 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
is the characteristic polynomial. For the diagonal filter:
That computation, without skipping anything:
| Step | Computation | Why |
|---|---|---|
| 1 | only has on the diagonal: off it you subtract 0 | |
| 2 | determinant: main diagonal minus the other diagonal | |
| 3 | You expand the square: | |
| 4 | You look for two numbers whose product is 3 and whose sum is 4: 1 and 3 | |
| 5 | or | A product is zero when one of its factors is |
Subtracting from every entry of , 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: , and its determinant is . With a non-zero determinant, the system only has the solution , which does not count as an eigenvector. You can also see it without determinants: would be , which forces and . No direction is stretched by exactly two.
Eigenvalues: and . For each one, the eigenvectors are the solutions of :
- : . Both rows say the same, , so : , basis .
- : . Now , : , basis .
Exactly the two diagonals.
Two free checks for the characteristic polynomial. The sum of the eigenvalues is the trace of (here ) and their product is the determinant (). 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 is described by two numbers:
- Algebraic multiplicity : how many times it is a root of .
- Geometric multiplicity : the dimension of its eigenspace, that is, how many independent eigenvectors it has. You compute it without solving anything:
And it always holds that
So a simple eigenvalue () always has , and you do not need to look at it. You only have to compute the geometric multiplicity of the repeated eigenvalues.
Computing as , with without subtracting . That is the dimension of the kernel, which only matches when . The matrix to look at is , 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 holds the coordinates, with the glasses on, of the image of the first basis vector. Since is an eigenvector, its image is : three times the first vector and zero times the second, . The second one, , stays as it is: . 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 , and use the basis . Its image, , is no longer a multiple of : with these glasses it is , and its column becomes , 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 of the change of basis; in this section it is called . The same thing, stated with the official definition:
A square matrix is diagonalisable if it is similar to a diagonal matrix: there is an invertible matrix (the change-of-basis matrix, or modal matrix) with
We already did it in the diagonals example: with = the eigenvectors in columns, has the eigenvalues on the diagonal. That is no coincidence. In general:
- The columns of are eigenvectors of that form a basis.
- The diagonal of holds their eigenvalues, in the same order as the eigenvectors in .
So diagonalising means finding a basis of eigenvectors. And that cannot always be done.
When it can be done: the two conditions
A matrix of size is diagonalisable over if and only if both conditions hold:
- All eigenvalues are real: the roots of are real numbers (counted with multiplicity, they add up to ).
- For each eigenvalue, the algebraic multiplicity equals the geometric one: .
A handy consequence: if has distinct real eigenvalues, it is certainly diagonalisable, because all of them are simple and for them .
The full recipe, with a colour filter
Let us take a filter of that mixes channels: each new channel is twice itself plus the other two.
If you did the topic 1 exercises, you already computed its characteristic polynomial: .
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 adds up to the same thing:
| Step | Computation | Why |
|---|---|---|
| 1 | You subtract only on the diagonal | |
| 2 | : the first column becomes | Each row adds up to , and adding the other columns to one column does not change the determinant |
| 3 | You take out: the first column becomes | If a whole column is multiplied by a number, that number comes out multiplying the determinant |
| 4 | , : you get | Subtracting rows does not change the determinant either, and it makes zeros below the 1 |
| 5 | The determinant of a triangular matrix is the product of its diagonal |
You get , the same polynomial, and already factorised: no need to look for the roots of a degree-3 polynomial.
Step 1. Eigenvalues. with and with . All real: first condition met. Check: and .
Step 2. Geometric multiplicities. Only the repeated one needs checking, :
Second condition met: is diagonalisable.
Step 3. Eigenvectors. For , the system is a single equation, , with two parameters: . Setting and :
For :
The third row is the second with the sign changed, so we are left with and : and . Basis of : .
Step 4. Build and , in the same order:
Step 5. Check without computing : it is enough to see that . For instance, the third column of is , and the third column of is . Likewise for the other two.
Back to the photo: the colours with (not real colours, but vectors all the same) do not change, and the greys are multiplied by 4. Any other colour is a mix of the two.
Mixing up the order of and . If you put in the first column of , the 4 has to go first on the diagonal of . 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. , , slants the sticker like an italic letter. Its polynomial is : eigenvalue 1, double, . But
There is only one direction that does not turn, the horizontal . One eigenvector short of a basis: it is not diagonalisable.
The 90° rotation. Its polynomial is , which has no real roots (they are , 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 .
Symmetric matrices always can be
There is a family that never fails: every real symmetric matrix () 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: and . 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 . By hand, four matrix products. With the diagonalisation, almost nothing. From you get , and when you multiply by itself the s in the middle cancel out:
And the power of a diagonal matrix just raises each number on the diagonal. With the diagonal filter, , and :
With : , so . And with you get back, which is the quickest check of the formula.
The glasses reading: switches to the eigenvector basis, stretches each direction times and 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 » always comes after «study whether it is diagonalisable». If it is, the result is with as a letter; leave the expression with powers () and check with that you get .
Powers, step by step
This is how of the diagonal filter comes out with , multiplying from left to right:
| Step | Computation | Why |
|---|---|---|
| 1 | When you multiply two diagonal matrices, only the diagonal entries get multiplied together | |
| 2 | Multiplying by a diagonal matrix on the right scales the columns: the first by 243 and the second by 1 | |
| 3 | Row by column: and | |
| 4 | 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 swamps the 1 of the direction , and that is why the four entries of are almost equal. With 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.
. Step by step: with , , so on the diagonal and off it. Multiplying directly, the first row of times the first column gives and times the second, ; 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 , which is , ours with the sign changed (the roots are the same).null(M, 'r')solves just as on paper: it sets each free variable to 1, one at a time. That is why it gives and , the same ones we found by hand. Without'r',nullgives vectors of length 1 with decimals, which are also eigenvectors but look nothing like yours.inv(sym(P))*A*Pis computed with exact fractions (symturns the matrix into a symbolic one). If it comes out diagonal, with the eigenvalues in the order of the columns of , the diagonalisation is right. Withoutsym, MATLAB works with decimals and some zero comes out as a tiny number, whichformat ratprints 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 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 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:
- The first two outputs are equal: check on paper that lies in the kernel that
null(M, 'r')gives. - In the Workspace panel,
Mshows up with fractions (1/3) thanks toformat rat. Remove it and you will see 0.3333. - Change
Hto the rotation[0 -1; 1 0]and runeig: MATLAB will give you two numbers withi, which are not real. - Try
det(M),det(H)anddet([2 0; 0 1])and relate them to what happens to the area of the square.
Summary
| Concept | What it is | How to do it by hand | In MATLAB |
|---|---|---|---|
| Associated matrix | Images of the basis in columns | in column ; with standard bases, coefficients in rows | A |
| Image of a vector | A*v | ||
| Preimage | Vectors that land on | Solve | rref([A w]) |
| Kernel | Vectors that land on | Solve ; | null(A, 'r') |
| Image | Everything that can be reached | Columns of with a pivot; | rank(A) |
| Change of basis | Same , other coordinates | ; endomorphism, | inv(C)*A*C |
| Eigenvalues | Roots of | Characteristic polynomial | eig(A) |
| Eigenvectors | Solutions of | One system per eigenvalue | null(A - l*eye(n), 'r') |
| Diagonalising | Real and for all | inv(P)*A*P | |
| Powers | Raise the diagonal of | P*D^k*inv(P) |
Three ideas to take away:
- 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.
- : 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.
- 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, 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 →



