Vector spaces and subspaces — theory with screen colours: linear combinations, bases, dimension and subspaces (and the grey you can always take out)
In quiz 3 on the Campus I got the very first question wrong: whether a vector was in the subspace spanned by four others, and I ticked “true”. Four vectors in a space of dimension 3 look like more than enough to reach anywhere. They weren’t: two of them were combinations of the other two, so there were really only two directions, and two directions span a plane, not the whole space. The vector was outside that plane.
That is what this topic is about: how many genuinely different directions there are in a bunch of vectors, which ones are enough to reach everything (a basis), how many you need (the dimension), and the “pieces” of the space that behave like a smaller space (subspaces). The example for the whole article is screen colours: every pixel mixes red, green and blue light, so every colour is a vector in . Everything rests on topic 2, because each question today ends up as a system of equations. After the theory you have the guided practice.
In a nutshell: a vector space is a set where you can add vectors and multiply them by numbers. A basis is a set of linearly independent vectors that span the whole space, and the number of vectors in it is the dimension. A subspace is a piece of the space that contains and is closed under addition and scalar multiplication; it is described by a basis, by parametric equations or by implicit equations.
Table of Contents
Before you start. For this topic you only need two things from the previous topics: row-reducing a matrix by Gaussian elimination and reading off its rank (topic 1), and knowing when a system has a solution, exactly one or infinitely many (topic 2, with Rouché-Frobenius). Nothing else. The topic has three big ideas, in this order: mixing vectors and seeing whether any of them is spare (linear combinations, dependence and rank); the smallest set of vectors that reaches everything, how many it has and the recipe of every vector in it (basis, dimension, coordinates and change of basis); and the pieces of the space that work like a smaller space, how to describe them and how to combine them (subspaces, equations, sum and intersection). If you get lost at any point, go back to the tiny lights on the screen: the whole topic can be told with them.
A colour is a vector
A screen has three tiny lights in every pixel: red, green and blue. A colour is how much you switch on each one, so I can write it as three numbers . Pure red is , green , blue , and when you mix light the intensities add up: red and green together give yellow, ; green and blue, cyan, ; red and blue, magenta, ; and all three, white, .
Two operations on colours are the basis of the whole topic:
- Adding two colours, component by component: . Yellow plus blue gives white (with light, not with paint).
- Multiplying by a number: , a cyan twice as bright.
A vector space is exactly that: a non-empty set of objects (the vectors) with an addition and a product by real numbers (the scalars) that satisfy ten rules. For all and :
| Rule | What it says |
|---|---|
| 1 | : adding does not take you out of the set |
| 2 | |
| 3 | |
| 4 | There is a with |
| 5 | Every has an opposite with |
| 6 | : multiplying does not take you out of the set |
| 7 | |
| 8 | |
| 9 | |
| 10 |
The example you will use almost always is , the vectors with components and componentwise addition and product. is the colours; the exam uses a lot, which you could picture as colours with a fourth number for transparency. But vectors do not have to be arrows: matrices form a vector space (), and so do polynomials of degree at most 2 (). They can be added and multiplied by numbers, and they satisfy the ten rules.
Just for the curious. A real screen only accepts intensities from 0 to 255 in each channel, and a “negative green” does not exist. In algebra we let the components be any real number: the calculations stay clean and, when needed, you clip to the range the screen accepts. A colour with a negative component is not a calculation error; it is a colour the screen cannot light up.
Linear combinations: mixing lights
Before the definition, let’s do it in your head. Imagine you only have two lamps, a yellow one and a cyan one, each with its own dimmer. If you set the yellow one to intensity and the cyan one to , what colour comes out?
Yellow switches on red and green; cyan, green and blue. So red only comes from the yellow lamp, blue only comes from the cyan lamp, and green comes from both. The colour you get is .
Look at what that expression says: with these two lamps, green is always as much as red and blue together. That already tells you, without solving any system, which colours you can make and which you cannot:
- can be made: .
- Pure red cannot: it would need .
What you have just done, putting a number in front of each vector and adding up, is called a linear combination. The numbers are the dimmers.
A linear combination of the vectors is any vector of the form
With colours, it is a mixing recipe: “two of yellow and one of cyan” is
And the reverse question is the one you will ask most: can you get a given colour by mixing some specific colours? For example, is a linear combination of yellow and cyan? You set up , which component by component is a system:
It has a solution (, ), so yes. What about pure red ? The first and third components would give , , but then the second says : inconsistent. With yellow and cyan there is no way to make pure red.
“Is a linear combination of these vectors?” always turns into “is this system consistent?”. The vectors are the columns of the coefficient matrix and is the column of constants. Rouché-Frobenius (topic 2) answers it: it is a linear combination if and only if the rank does not change when you add .
Linear dependence and independence
Again, first in your head. You have a red lamp and a green one. Someone offers you a third one, yellow. Does it add anything? No: anything you do with the yellow lamp you can do by switching on red and green at the same time. That lamp is spare. With a blue one it is the other way round: there is no way to make blue out of red and green, so blue does add something.
A vector being spare means it is a linear combination of the others. To check that literally you would have to test the vectors one by one against the rest: with four vectors, four systems. The formal definition packs it all into a single equation with a trick: move everything to one side. Saying is the same as saying : a mix that gives black without all the dimmers at 0. And the other way round, if you find a mix like that, you solve for any vector whose number is not 0 and there is your spare one.
Some vectors are linearly dependent if one of them can be obtained by mixing the others. The formal definition says it with a single equation: is linearly dependent if there are scalars , not all 0, with
And it is linearly independent if that equation only has the trivial solution . Notice it is a homogeneous system: it always has the trivial solution (topic 2), and the question is whether it has more.
Red, green and yellow are dependent, because yellow is red plus green:
with , not all 0. Yellow, cyan and magenta, on the other hand, are independent. You set up :
Adding the three, ; subtracting each equation from that gives . Only the trivial one: independent. With three vectors of there is a shortcut: the determinant of the matrix they form. If it is not 0, they are independent:
Three facts that save you calculations (and quiz questions):
- A set containing is always dependent: with a non-zero scalar.
- Two vectors are dependent if and only if one is a multiple of the other: and are.
- A single non-zero vector is independent.
Yellow, cyan and magenta, without skipping anything
The calculation from above, with the reason for every step. The trick works because each appears in exactly two of the three equations:
| Step | Calculation | Why |
|---|---|---|
| 1 | You add the three equations: the three right-hand sides are 0 | |
| 2 | , so | Each appears twice; you divide by 2 |
| 3 | From the sum of the three you subtract the first, : only is left | |
| 4 | You subtract the second, | |
| 5 | You subtract the third, |
The only way for the mix to give black is to switch everything off: none of the three is spare.
The determinant is the shortcut. Of the six products in Sarrus’ rule, with yellow, cyan and magenta as rows, the three that are added (the main diagonal and its two parallels) give 1, 1 and 0, and the three that are subtracted give 0 all three: each of them has a 0 in it. Total, 2. Why does a non-zero determinant mean independent? Because the homogeneous system above has that same matrix (transposed), and a square system with a non-zero determinant has a unique solution (topic 2): its only solution is the trivial one.
In the system the colours go in columns, and in the determinant I have put them in rows. It does not matter: a matrix and its transpose have the same determinant.
Check you’ve got it: are red, cyan and white independent?
No, they are dependent. The determinant with , and as rows is 0. Step by step, expanding along the first row, which only has one non-zero number: . And the reason with colours: white is red plus cyan, . Moving everything to one side, , with , which are not all 0.
The rank of a set of vectors
The rank of a set , , is the largest number of linearly independent vectors in . It is computed as in topic 1: you write the vectors as rows (or columns) of a matrix, and . For example, with yellow, cyan, magenta and white:
Three steps: . There are four vectors but only three independent directions; white is spare, because . So: is independent if and only if equals the number of vectors.
Spanning sets
A set is a spanning set (or generating set) of if every vector of is a linear combination of those in . With colours: with those lights, can you get any colour?
Red, green and blue span , of course: . Yellow, cyan and magenta also give any colour, even if it is not obvious. For any colour , the system
has determinant 2 (the one above), so it has a unique solution for any : there is always a recipe, and only one. Yellow and cyan do not span : we saw that pure red cannot be made.
The rank decides again: spans if and only if .
Basis and dimension
Before the names, five sets of lamps. For each one, two questions: is any lamp spare? and can you make any colour?
| Lamps | Any spare? | Any colour? | Why |
|---|---|---|---|
| Red, green, blue | No | Yes | Each one switches on a channel the others do not touch |
| Yellow, cyan, magenta | No | Yes | The determinant is 2: independent, and the system has a solution for any colour |
| Red, green, blue, white | Yes | Yes | White is red plus green plus blue |
| Yellow, cyan | No | No | Pure red cannot be made (we saw it with linear combinations) |
| Red, green, yellow | Yes | No | Yellow is red plus green, and none of them gives blue |
The two good sets, the ones with no extra lamp and no missing colour, have three lamps. With two, something is always missing; with four, one is always spare. It is not a coincidence: in there are exactly three independent directions, and any good set has to cover all three without repeating.
A set like that, with nothing extra and nothing missing, is called a basis, and its number of vectors is the dimension. That is what comes now, with the official names.
Check you’ve got it: are yellow, cyan and white a good set?
Yes, they are a basis of . Step by step: they are three vectors of , so it is enough to see that the determinant is not 0. With , and as rows, expanding along the first row: .
A basis of is a set of vectors that does both things at once:
- It is linearly independent (none is spare).
- It is a spanning set of (none is missing).
The standard basis of is made of the vectors with a 1 and zeros elsewhere: with colours, , red, green and blue. But it is not the only one: yellow, cyan and magenta are also a basis of , because we have just seen they are independent and spanning. Red, green, blue and white span but are not a basis (one is spare); yellow and cyan are independent but are not a basis (one is missing).
What is the same in every basis of a space is the number of vectors. That number is the dimension, :
| Space | A basis | Dimension |
|---|---|---|
| (colours) | red, green, blue | 3 |
| the 4 standard vectors | 4 | |
| the 4 matrices with a single 1 | 4 | |
| 3 |
Knowing the dimension saves a lot of work. If and you have vectors:
- If , they are certainly dependent (four colours can always be mixed from each other).
- If , they cannot span (two colours never give them all).
- If , you only need to check one of the two conditions: independent spanning basis. With vectors of , that means a non-zero determinant.
Saying that two independent vectors of are a basis of . They are independent, yes, but two vectors only span a plane. A basis of has exactly 3 vectors: not one more, not one less.
Coordinates in a basis
You have already done this without a name. In spanning sets we saw that with yellow, cyan and magenta every colour has a recipe, and only one (the determinant was 2). That recipe, the list of how much of each lamp, is what we call the coordinates of the colour in that basis. Being unique matters: if the same colour had two recipes, “the coordinates of that colour” would mean nothing. That is why we only talk about coordinates in a basis: with a spanning set that has a spare vector, the same colour would have several recipes.
If is a basis of , every vector can be written in exactly one way as . The numbers are the coordinates of in . Uniqueness is exactly what independence gives you: if there were two recipes, subtracting them would give a zero combination with coefficients not all 0.
In the standard basis, the coordinates of the colour are : the components themselves. In the basis of yellow, cyan and magenta they are different. You set up :
Adding the three equations, , so . Subtracting each equation: , , . The coordinates of in are : two of yellow, three of cyan and one of magenta. Check: .
Same colour, two different lists of numbers. The coordinates are not the vector: they are the recipe in a particular basis, and they change if you change the basis.
Change of basis
Before the formula, think about what you do when you are given the recipe and asked for the colour. If the coordinates in are , the colour is : each lamp times its number, and everything added up. Written component by component, that is exactly multiplying a matrix by the vector , if that matrix has , and as columns: when you multiply, the first column goes with the first number, the second with the second and the third with the third. That is why the basis vectors go in columns, not in rows.
That is what the general rule coming up says: column of the change-of-basis matrix is the recipe, in the target basis, of vector of the starting basis. When you see the inverse below, look at its first column: is the recipe for red with yellow, cyan and magenta. Check it: .
Moving coordinates from one basis to another is multiplying by a matrix. If are the coordinates of in and in , the change-of-basis matrix satisfies
and each column of holds the coordinates of one vector of written in . In , with the standard basis, three rules follow:
- From to the standard basis: has the vectors of as columns, as they are.
- From the standard basis to : , the inverse of the previous one.
- Between two non-standard bases and : . First you go from to the standard basis and then from the standard basis to .
With colours, the matrix that takes to the standard basis has yellow, cyan and magenta as columns:
And to go from the standard basis to without solving a system every time, the inverse (with the Gauss-Jordan method of topic 1):
Writing the basis vectors as rows of the change-of-basis matrix. They go as columns: column is vector of the starting basis written in the target one. If you put them as rows you have the transpose, and the coordinates come out wrong (except by coincidence).
Vector subspaces
Before the definition, keep only the colours with no blue, the ones with . Inside that piece, can you do everything you did in the whole space without leaving it?
- You mix two colours with no blue: the sum still has no blue, because .
- You turn up the intensity, or flip its sign: still no blue, because .
- Black is inside, and it is the that rule 4 needs.
In other words, you never have to leave the piece to operate: the piece is a vector space in its own right, a smaller one (a plane). And the other seven rules, commutativity, associativity and the rest? Those already held for all colours, so they also hold for the colours in a piece. The only things that can go wrong when you keep just a piece are leaving it when you operate, or not having . That is why, in the definition coming up, three checks are enough. Before reading it, put them to the test:
Check you’ve got it: are the colours with (the ones with no red or no green) a subspace?
No. Step by step, with the three conditions: black is there, because . Multiplying by a number does not take you out either: . But the sum fails: red and green are both inside, and their sum, yellow , has . Notice that the colours with no green are a subspace (a plane) and the colours with no red are another; what is not a subspace is putting them together.
A vector subspace of is a subset that, with the same operations, is a vector space itself. You do not need to check the ten rules: three are enough.
- .
- If , then .
- If and , then .
Two collections of colours explain it better than the definition:
- The greys, the colours with . They contain black ; two greys added give a grey; a grey times a number is still grey. It is a subspace: the line from black to white, of dimension 1.
- The colours with no blue, with . They contain black, the sum of two colours with no blue has no blue and multiplying does not add any. It is another subspace: the plane of red-green mixes, of dimension 2.
Every space has two subspaces that add nothing, the trivial ones: itself and , of dimension 0. And in there are no other kinds: subspaces of dimension 1 are lines through the origin, and of dimension 2, planes through the origin.
And what is not a subspace? The colours with are not, because black does not satisfy : the first condition fails. Nor are the colours a screen can really light up, with components between 0 and 255: yellow is there, but is not. A line or a plane that does not pass through the origin is never a subspace.
To rule out a subspace, first check whether it contains . It is the fastest check and it knocks out almost every quiz example: any equation with a non-zero constant term, like , leaves the origin out.
The subspace spanned by some vectors
Given , the set of all its linear combinations is a subspace, the subspace spanned by :
It is everything you can get by mixing those vectors, and . There are two methods to find a basis. You will need both, because they give different things. With (yellow, magenta and two mixes):
Method 1: vectors as rows and Gauss. Row operations mix vectors, so the non-zero rows of the echelon form still span the same thing:
Basis: , and . It is a valid basis, but the second vector is no longer one of those in .
Method 2: vectors as columns and Gauss-Jordan. If the question asks for a basis made of vectors of (on the Campus: “with original vectors”), you put them as columns. Row operations do not change which columns are combinations of which, so the pivot columns point to the original vectors that form a basis:
Pivots in columns 1 and 2, so the basis is the first and second vectors of : , yellow and magenta. And the reduced form also tells you how to write the others: column 3, , means , and column 4, , that . Check: .
Reading the pivots of the reduced form and giving the columns of the reduced form as the basis. The pivot columns tell you which positions to choose; the vectors you copy are those of the original matrix. It is the mistake that costs the most points in the MATLAB assignment, because rref shows you the reduced form and it is very tempting to copy it.
Parametric and implicit equations
A subspace can be described in three ways, and the exam asks you to go from one to another.
With a basis, as we have just seen: .
With parametric equations: you set a generic vector equal to the combination of the basis with parameters that take any real value.
The number of (independent) parameters is the dimension: here, 2.
With implicit equations (or Cartesian equations): a homogeneous system satisfied by the coordinates of the vectors in and only by them. They are the conditions for belonging. Here, from and you get :
In words: the colours in have as much red as green and blue together. And the number of independent implicit equations is fixed:
Here, . The greys, of dimension 1, need equations: and .
The two steps that come up in the exam:
From implicit equations to a basis. You solve the homogeneous system by Gaussian elimination (topic 2) and split by parameters. With the greys: , gives , , , that is, and .
From a basis to implicit equations. A vector is in if and only if adding it to the basis does not raise the rank. You write the basis as rows, add a row and require the rank to stay :
Expanded along the third row: . The same equation. When the matrix is not square (for example, two vectors in ), you row-reduce with inside the last row and require the positions left without a pivot to be 0: each one is an implicit equation. We will do it in the practice.
Always check your implicit equations with the basis vectors: every basis vector must satisfy every equation. With : ; with : . If one fails, there is a sign error.
Sum and intersection of subspaces
First in your head, with the two planes of colours you are about to use: , the colours with no blue (), and , the ones with as much red as green ().
The first thing anyone thinks of to “put them together” is to keep the colours that are in one or the other. But that is not a subspace: red is in , blue is in (it has ), and their sum, magenta , is in neither (it has blue, and it has red but no green). When you put two subspaces together like that, adding takes you outside.
What does work is keeping everything you can get by adding one colour from each: that is the sum. And what they have in common, the colours with no blue and with , is the intersection: the yellows .
Confusing the sum of subspaces with the union. The union of two subspaces is almost never a subspace (only when one is inside the other); the sum is the smallest subspace that contains both.
Check you’ve got it: can two planes of through the origin meet only at the origin?
No, never. Step by step: you put the two bases together and you have four vectors in , so the sum has dimension at most 3. With the Grassmann formula, a few lines below, , and if , then : they share at least a line. With the colours, and share the line of the yellows.
With two subspaces and of you can build two more:
- The sum : all vectors of the form with and . A spanning set comes from putting both bases together; a basis, from row-reducing and removing the spare ones.
- The intersection : the vectors that are in both. A basis comes from putting the implicit equations of both together and solving the system.
With colours: = colours with no blue (, basis ) and = colours with as much red as green (, basis ).
Sum. The four rows have rank 3 (the third is the sum of the first two), so and : adding a colour with no blue and one with you reach any colour. As it is the whole space, it has no implicit equations.
Intersection. You put together and : , . , the yellows, of dimension 1.
And the four dimensions are tied by the Grassmann formula:
Here . The intuition: when you merge the two bases, what they have in common is counted twice, and the intersection is exactly what is spare.
Computing the dimension of the sum by adding the dimensions. is only when the intersection is . With the two planes above, would be impossible in .
Direct sum and complementary subspaces
When , the sum is called a direct sum and is written : each vector of the sum splits in exactly one way. And if, moreover, , the subspaces are complementary (supplementary). The exam asks you to justify it: you have to check both things, and (or, with Grassmann, one of them and that the dimensions add up to ).
Here is the grey from the title. The colours with no blue (, dimension 2) and the greys (, dimension 1) only meet at black: a grey with no blue has and therefore . The dimensions add up to , so they are complementary: every colour splits in exactly one way into a grey plus a colour with no blue. With , the grey has to take all the blue, , and what is left is
The first term is the grey and the second, the colour with no blue, and there is no other way to split it.
Just for the curious. This is not how a photo editor removes grey (it works in the 0-255 range and with other colour models), but the idea of splitting a vector into two pieces from complementary subspaces is the same one you will use in topic 4, when the “leftover” piece is perpendicular, and in topic 5, when the pieces are eigen-directions.
The same in MATLAB
Everything today is ranks, systems and matrices, so MATLAB does it with the commands of topics 1 and 2:
Y = [1 1 0]; C = [0 1 1]; M = [1 0 1]; W = [1 1 1]; rank([Y; C; M]) % 3: independent, and with three in R^3, a basis rank([Y; C; M; W]) % still 3: white is spare P = [Y' C' M'] % change from B' to the standard basis: vectors as columns
Output:
ans =
3
ans =
3
P =
1 0 1
1 1 0
0 1 1
[Y; C; M] stacks the colours as rows; Y' is the transpose, yellow as a column. Now the coordinates of in and the matrix that goes from the standard basis to :
format rat coord = P \ [3; 5; 4] % solves P * X' = X: the coordinates in B' inv(P) % change from the standard basis to B'
Output:
coord =
2
3
1
ans =
1/2 1/2 -1/2
-1/2 1/2 1/2
1/2 -1/2 1/2
They match the ones on paper: and the inverse with the halves. And the two methods for the basis of , plus implicit equations turned into a basis:
S = [1 1 0; 1 0 1; 2 1 1; 0 1 -1]; % the four vectors, as rows rank(S) % dim L(S) [R, piv] = rref(S') % as columns: piv says which original vectors form a basis null([1 -1 -1], 'r') % basis of the subspace r - g - b = 0
Output:
ans =
2
R =
1 0 1 1
0 1 1 -1
0 0 0 0
piv =
1 2
ans =
1 1
1 0
0 1
piv is 1 2: vectors 1 and 2 of , yellow and magenta, as in method 2. And null(A, 'r') solves the homogeneous system and returns a basis of the subspace as columns, with “nice” numbers thanks to the 'r': yellow and magenta again. Note that null gives the basis as columns (in the assignment quiz you must write it correctly).
Try it in the MATLAB playground
In the website’s MATLAB playground you can play with the colours:
% Is it a basis of R^3? What coordinates does a colour have in it?
B1 = [1 1 0]; B2 = [0 1 1]; B3 = [1 0 1]; % yellow, cyan, magenta
P = [B1' B2' B3'];
if rank(P) == 3
disp('It is a basis of R^3')
format rat
coordinates = P \ [3; 5; 4]
else
disp('Not a basis')
end
Things to look at:
- Swap magenta for white,
B3 = [1 1 1], and check it is still a basis. WithB3 = [1 2 1](yellow plus cyan), it no longer is. - Change
[3; 5; 4]to the grey[2; 2; 2]: the coordinates come out equal, . Why? - Try
null([0 0 1; 1 -1 0], 'r'): it is the intersection of “no blue” and “red equals green”, the yellows. - If you want to see each row operation with fractions, put the matrix of the four vectors into the Gauss-Jordan step-by-step simulator: it gives you the rank and marks the pivots.
Summary
| Concept | What it is | How to compute it |
|---|---|---|
| Linear combination | Does it exist? Consistent system | |
| Linearly independent | Only the trivial combination gives | = no. of vectors |
| Spanning set of | Every vector is a combination of them | |
| Basis | Independent and spanning | vectors with (or ) |
| Dimension | No. of vectors in any basis | |
| Coordinates | The recipe of the vector in a basis | Solve a system, or |
| Subspace | Contains , closed under addition and product | The three conditions |
| Implicit equations | Conditions for belonging | no. |
| Sum | Merge bases and row-reduce | |
| Intersection | Merge implicit equations and solve | |
| Grassmann | Check both results |
Three ideas to take away:
- Almost everything is the rank: independence, spanning, basis, dimension and membership are decided by row-reducing a matrix with the vectors.
- A subspace has three portraits (basis, parametric and implicit equations), and you go from one to another by solving a system or requiring the rank not to grow.
- The sum is done with bases and the intersection with equations; Grassmann checks that both calculations agree.
Now it is your turn: in the vector spaces guided practice we solve five problems step by step, checked in MATLAB: independence with a parameter, a change between two non-standard bases, the basis with original vectors, the implicit equations of a subspace of and the whole subspaces exercise from the exam. And to check you have got it, the vector spaces exercises go from easy to hard and come with commented solutions and a quiz like the Campus ones. Next comes topic 4, the Euclidean space, where these vectors get a rule to measure lengths and angles.
Next step: practiceVector spaces — guided practice with colours: independence, change of basis, original vectors and the exam’s subspaces exercise (and the basis that did not come out of rref)Did this article help you? Here is how you can support SergioLearns →



