Skip to article frontmatterSkip to article content

2.6. Vector Spaces

Chapter 2.5 was a detour into the geometric world of lines, planes, and hyperplanes. In this section, we’ll revisit the key ideas of span and linear independence that we introduced in Chapter 2.4 but from a more abstract and rigorous perspective.

Context

You might be wondering what the point of all of this is – spans, linear independence, vector spaces, etc. What does any of this have to do with machine learning, or more specifically, that problem of predicting commute times given departure times from Chapter 1?

Remember, what we’re working towards is being able to build hypothesis functions that use multiple features to make predictions.

predicted commute timei=h(departure houri,day of monthi,day of weeki,gas left in tanki,...)\text{predicted commute time}_i \\ = h(\text{departure hour}_i, \text{day of month}_i, \text{day of week}_i, \text{gas left in tank}_i, ...)

As we’ll see in Chapter 3, such a hypothesis function involves computing a linear combination of the features. To find the best possible model, we’ll need to find the best possible linear combination of the features, and to do so, we’ll need to think about the space of all possible linear combinations of the features – or the span of those features.

At times, what I’m discussing will sound abstract, pedantic, and disconnected from our overarching focus on machine learning. But bear with me – I promise it’ll all come together soon.


Vector Spaces

When we first introduced vectors back in Chapter 2.1, I mentioned that they support two key operations: addition and scalar multiplication. These two operations combine through linear combinations, as we’ve seen repeatedly throughout Chapter 2.

So far, we’ve mostly dealt with Euclidean vectors, which are the vectors that we’ve treated as ordered lists of numbers in Rn\mathbb{R}^n. (The term “Euclidean” refers to the fact that the vectors have some geometric meaning; we have thought of a vector as an arrow from the origin to a point in space. The term Euclidean is named after the Greek mathematician Euclid, who was one of the pioneers of the study of geometry.)

v=[32853],x=[x1x2xn]Euclidean vectors\underbrace{\vec v = \begin{bmatrix} 3 \\ -2 \\ 8 \\ 5 \\ 3 \end{bmatrix}, \quad \vec x = \begin{bmatrix} x_1 \\ x_2 \\ \vdots \\ x_n \end{bmatrix}}_\text{Euclidean vectors}

However, it’s sometimes useful to consider vectors in a more abstract setting. Euclidean vectors are not the only mathematica objects that support addition and scalar multiplication!

Together, the two properties above tell us that any linear combination of vectors in VV is also a vector in VV.

u,vV,c,dR    cu+dvV{\color{orange} \vec u}, {\color{#3d81f6} \vec v} \in V, \quad c, d \in \mathbb{R} \implies c {\color{orange} \vec u} + d {\color{#3d81f6} \vec v} \in V

R2\mathbb{R}^2 is a vector space: if you take any two vectors in R2\mathbb{R}^2 and add them together, you will still have a vector in R2\mathbb{R}^2. Multiply a vector in R2\mathbb{R}^2 by a scalar, and you’ll still have a vector in R2\mathbb{R}^2.

u=[34],v=[12]two vectors in R2\underbrace{{\color{orange}\vec u = \begin{bmatrix} 3 \\ 4 \end{bmatrix}}, \quad {\color{#3d81f6}\vec v = \begin{bmatrix} -1 \\ 2 \end{bmatrix}}}_\text{two vectors in $\mathbb{R}^2$}
2u3v=[92]also a vector in R2!\underbrace{2 {\color{orange}\vec u} - 3 {\color{#3d81f6}\vec v} = \begin{bmatrix} 9 \\ 2 \end{bmatrix}}_\text{also a vector in $\mathbb{R}^2$!}

The same holds for R3\mathbb{R}^3, R4\mathbb{R}^4, and more generally, Rn\mathbb{R}^n. These are all examples of vector spaces.

What might be a vector space that isn’t made up of our regular Euclidean vectors? One possible vector space is the set of all polynomials with a degree less than or equal to 3 (i.e. degree “at most 3”). This vector space, denoted by P3\mathcal{P}_3, is the set of all polynomials of the form

p(x)=a0+a1x+a2x2+a3x3p(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3

where a3,a2,a1,a0a_3, a_2, a_1, a_0 are real numbers (potentially equal to 0).

u(x)=2x316x2+7x1u(x) = 2x^3 - 16x^2 + 7x - 1
v(x)=3x34x2+2x+5v(x) = 3x^3 - 4x^2 + 2x + 5
w(x)=x+4w(x) = x + 4

u(x)u(x), v(x)v(x), and w(x)w(x) are all elements of P3\mathcal{P}_3; think of each of these polynomials as a vector in P3\mathcal{P}_3.

Why is P3\mathcal{P}_3 a vector space? If you add any two polynomials with a degree of at most 3 together, you will still have a polynomial with degree at most 3. Likewise, if you multiply a polynomial with degree at most 3 by a scalar, you will still have a polynomial with degree at most 3.

There are other examples of abstract vector spaces, too, like the set of all matrices with real entries, or the set of all continuous functions from R\mathbb{R} to R\mathbb{R}. In the definition of a vector space, I mentioned that the objects in the space should support addition and scalar multiplication. We know how these operations work for our traditional definition of vectors, but what do these operations look like for generic mathematical objects?

Technically, we could be even more abstract and not restrict the scalars to be real numbers, and instead allow them to be complex numbers. Such a vector space is called a complex vector space. But, we’ll stick with real vector spaces in this class, where the scalars involved in scalar multiplication are real numbers.

And even more practically, we’ll stick to focusing on the vector space Rn\mathbb{R}^n. Still, I wanted to provide you with some context for how to generalize these ideas.


Subspaces

As I emphasized above, we’ll stick to working with vector spaces of the form Rn\mathbb{R}^n, made up of Euclidean vectors.

A theme that we’ve studied over the past few sections is that of a subspace: a subset of a vector space.

  • The span of one vector in R2\mathbb{R}^2 is a line through the origin, which is a 1-dimensional subspace of R2\mathbb{R}^2.

  • The span of two non-collinear vectors in R3\mathbb{R}^3 is a plane through the origin, which is a 2-dimensional subspace of R3\mathbb{R}^3.

Let me be a bit more precise with what a subspace is, given our new framing of vector spaces.

The simpler way of thinking of Properties 2 and 3 above is that if you take any two vectors u,vS\vec u, \vec v \in S, then any linear combination cu+dvc\vec u + d\vec v must also be in SS. If you combine elements in a subspace, they can’t “escape” the subspace.

Subspace

Properties 2 and 3 above sound familiar, since they were the defining properties of a vector space. Indeed, a subspace is a vector space on its own, it’s just that it’s also a subset of a larger vector space, meaning all of its elements are also in VV. The “sub” in “subspace” means “under” or “within”. A subspace can also just be the entire vector space itself – R2\mathbb{R}^2 is a subspace of R2\mathbb{R}^2, for example – which is why I’ll usually phrase definitions and theorems in terms of subspaces, rather than vector spaces.

Sometimes, other math texts will use set notation to denote subspaces, like SVS \subseteq V, but I’ll try and avoid unnecessary notation like that here.

Many years ago, one of the great math teachers I had used the following example to explain what the term closure meant:

If you put two elephants in a cage, and one day a third animal comes out, that third animal must still be an elephant. - J. Bruce White, 1938-2025

The point is not just that elephants are animals, but that if you take any two elephants and add them together, you’ll still have an elephant.

Let’s look at several possible subspaces of larger vector spaces, and see if they are subspaces (and if not, why not).

Example: First Component is 1 ❌

Is the set of all vectors in R2\mathbb{R}^2 whose first component is 1 a subspace of R2\mathbb{R}^2? (Notice that when I ask whether a set is a subspace, I have to specify the vector space it’s possibly a subspace of.)

In set notation, I could write this set as

{[1y]yR}\{ \begin{bmatrix} 1 \\ y \end{bmatrix} \mid y \in \mathbb{R} \}

When I’m presented with a set like this, I like to think of some example vectors in the set, and see if those examples satisfy the properties of a subspace. If those examples satisfy the properties, then I’ll try and prove that the properties hold for any two vectors in the set.

This set contains vectors like [12]\begin{bmatrix} 1 \\ 2 \end{bmatrix} and [15]\begin{bmatrix} 1 \\ -5 \end{bmatrix}. Remember, for this set to be a subspace, it must be closed under addition and scalar multiplication. But, if I add these two example vectors together, I get

[12]+[15]=[23]\begin{bmatrix} 1 \\ 2 \end{bmatrix} + \begin{bmatrix} 1 \\ -5 \end{bmatrix} = \begin{bmatrix} 2 \\ -3 \end{bmatrix}

which is not a vector in the set, since its first component is not 1. So, this set is not closed under addition, and so it is not a subspace of R2\mathbb{R}^2. I don’t need to prove anything in a more general form here, since I’ve found a counterexample.

Also, this set doesn’t contain the zero vector [00]\begin{bmatrix} 0 \\ 0 \end{bmatrix}, which it needs to in order to be a subspace.

Example: First Component is 0 ✅

Is the set of all vectors in R2\mathbb{R}^2 whose first component is 0 a subspace of R2\mathbb{R}^2? This is the set

{[0y]yR}\{ \begin{bmatrix} 0 \\ y \end{bmatrix} \mid y \in \mathbb{R} \}

This set does contain the zero vector [00]\begin{bmatrix} 0 \\ 0 \end{bmatrix}, which is a good start.

Some example vectors in this set are [02]\begin{bmatrix} 0 \\ 2 \end{bmatrix} and [05]\begin{bmatrix} 0 \\ -5 \end{bmatrix}. Adding these vectors together gives [03]\begin{bmatrix} 0 \\ -3 \end{bmatrix}, which is also in the set.

That’s a good start – but can we verify that any linear combination of vectors in the set is another vector in the set?

To do so, let’s pick two arbitrary vectors in the set, u=[0x]\vec u = \begin{bmatrix} 0 \\ x \end{bmatrix} and v=[0y]\vec v = \begin{bmatrix} 0 \\ y \end{bmatrix}. A linear combination of these two vectors is cu+dvc \vec u + d \vec v, or

c[0x]+d[0y]=[0cx+dy]c\begin{bmatrix} 0 \\ x \end{bmatrix} + d\begin{bmatrix} 0 \\ y \end{bmatrix} = \begin{bmatrix} 0 \\ cx + dy \end{bmatrix}

No matter what scalars cc and dd we pick, and no matter what the values of scalars xx and yy are, the sum cu+dvc \vec u + d \vec v is always a vector in R2\mathbb{R}^2 with a first component of 0 and a second component of cx+dycx + dy. In other words, any linear combination of vectors in the set is also a vector in the set. So, this set is closed under addition and scalar multiplication, and so it is a subspace of R2\mathbb{R}^2.

Example: Unit Vectors ❌

Is the set of all unit vectors in R5\mathbb{R}^5 a subspace of R5\mathbb{R}^5? (There’s nothing special about R5\mathbb{R}^5; I just wanted to move away from examples in R2\mathbb{R}^2.) This is the set

{vR5v=1}\{ \vec v \in \mathbb{R}^5 \mid \lVert \vec v \rVert = 1 \}

This is not a subspace of R5\mathbb{R}^5, which we can identify quickly by realizing it doesn’t contain the zero vector [00000]\begin{bmatrix} 0 \\ 0 \\ 0 \\ 0 \\ 0 \end{bmatrix}.

If we instead changed the set to be all vectors in R5\mathbb{R}^5 with a norm of less than or equal to 1, i.e.

{vR5v1}\{ \vec v \in \mathbb{R}^5 \mid \lVert \vec v \rVert \leq 1 \}

the resulting set would contain the zero vector in R5\mathbb{R}^5, but still wouldn’t be a subspace, since it’s not closed under addition or scalar multiplication. [10000]\begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \\ 0 \end{bmatrix} is in the set, but if we multiply it by 2, we get [20000]\begin{bmatrix} 2 \\ 0 \\ 0 \\ 0 \\ 0 \end{bmatrix}, which is not in the set.

Example: Non-Negative Coordinates ❌

Is the set of all vectors in R2\mathbb{R}^2 with non-negative coordinates a subspace of R2\mathbb{R}^2? This is the set

{[xy]x0,y0}\{ \begin{bmatrix} x \\ y \end{bmatrix} \mid x \geq 0, y \geq 0 \}

Graphically, this set represents the top-right quadrant (also known as the first quadrant) of the xyxy-plane. If we add two vectors in this set, the third vector will also be in the set, since the sum of two non-negative numbers is non-negative. However, if we multiply a vector in this set by a negative scalar, the resulting vector will not be in the set.

Image produced in Jupyter

Example: Line through Origin ✅

Consider the set of all vectors in R3\mathbb{R}^3 that lie on the line spanned by [132]\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}. Is this a set a subspace of R3\mathbb{R}^3? This is the set

{[132]tR}\{ \begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix} \mid t \in \mathbb{R} \}

Visually, this line looks like

Loading...

If we pick any two vectors on this line, any of their linear combinations will also lie on this line. Any vector on this line is a scalar multiple of [132]\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}, so two arbitrary vectors on this line might look like

u=a[132],v=b[132]{\color{orange}\vec u = a\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}}, \quad {\color{#3d81f6}\vec v = b\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}}

Then, a linear combination of u\color{orange}\vec u and v\color{#3d81f6}\vec v is

cu+dv=ca[132]+db[132]=(ca+db)[132]c{\color{orange}\vec u} + d{\color{#3d81f6}\vec v} = c {\color{orange}a\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}} + d {\color{#3d81f6}b\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}} = (c{\color{orange}a} + d{\color{#3d81f6}b})\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}

which is just another vector on the line! So, since the set is closed under linear combinations, it is a subspace of R3\mathbb{R}^3.


Spans are Subspaces

The last example we walked through above, {[132]tR}\{{ \begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix} \mid t \in \mathbb{R} \}}, is a subspace of R3\mathbb{R}^3. It is also the span of the vector [132]\begin{bmatrix} 1 \\ -3 \\ 2 \end{bmatrix}. It turns out that this correspondence between spans and subspaces is true in general.

This is true essentially by the definition of a span. The span of a collection of vectors is defined to be the set of all of their possible linear combinations. If you pick any two vectors in the span, they’re both made of the same building blocks (spanning vectors), so if you make a linear combination of these two new vectors, that’ll still be made up of the same building blocks.

Example: Span of Two Vectors in R3\mathbb{R}^3

As an example, consider the span of the vectors

u=[263],v=[150]{\color{orange}\vec u = \begin{bmatrix} 2 \\ 6 \\ -3 \end{bmatrix}}, \quad {\color{#3d81f6}\vec v = \begin{bmatrix} 1 \\ 5 \\ 0 \end{bmatrix}}

span({u,v})\text{span}(\{{\color{orange}\vec u}, {\color{#3d81f6}\vec v}\}) contains all vectors of the form cu+dvc{\color{orange}\vec u} + d{\color{#3d81f6}\vec v}. Let’s pick two such vectors, say

x=2u+3v,y=4u2v\vec x =2{\color{orange}\vec u} + 3{\color{#3d81f6}\vec v}, \quad \vec y =4{\color{orange}\vec u} - 2{\color{#3d81f6}\vec v}

Both x\vec x and y\vec y are in span({u,v})\text{span}(\{{\color{orange}\vec u}, {\color{#3d81f6}\vec v}\}). Now, let’s take a linear combination of these two new vectors, say, 5x12y5 \vec x - \frac{1}{2} \vec y, and check if that’s also in span({u,v})\text{span}(\{{\color{orange}\vec u}, {\color{#3d81f6}\vec v}\}). This linear combination is

5x12y=5(2u+3v)12(4u2v)5 \vec x - \frac{1}{2} \vec y = 5(2{\color{orange}\vec u} + 3{\color{#3d81f6}\vec v}) - \frac{1}{2}(4{\color{orange}\vec u} - 2{\color{#3d81f6}\vec v})

But, simplifying this expression shows us that it’s equivalent to

5x12y=10u+15v2u+v=8u+16v5 \vec x - \frac{1}{2} \vec y = 10{\color{orange}\vec u} + 15{\color{#3d81f6}\vec v} - 2{\color{orange}\vec u} + {\color{#3d81f6}\vec v} = 8{\color{orange}\vec u} + 16{\color{#3d81f6}\vec v}

which clearly shows that a linear combination of x\vec x and y\vec y is really just a linear combination of u\color{orange} \vec u and v\color{#3d81f6} \vec v.

All of this is to say, if you pick any two vectors in span({u,v})\text{span}(\{{\color{orange}\vec u}, {\color{#3d81f6}\vec v}\}), their linear combinations will also be in span({u,v})\text{span}(\{{\color{orange}\vec u}, {\color{#3d81f6}\vec v}\}), so span({u,v})\text{span}(\{{\color{orange}\vec u}, {\color{#3d81f6}\vec v}\}) is closed under addition and scalar multiplication. It also contains the zero vector (since you could take 0u+0v=00{\color{orange}\vec u} + 0{\color{#3d81f6}\vec v} = \vec 0), so this span is a subspace of R3\mathbb{R}^3.

Let’s not forget that the span of two non-collinear vectors in R3\mathbb{R}^3 is a plane. So, since span({u,v})\text{span}(\{{\color{orange}\vec u}, {\color{#3d81f6}\vec v}\}) is a subspace, the corresponding plane is also a subspace of R3\mathbb{R}^3 (because it’s the same thing as the span of the vectors).

Loading...

Chapter 2.5 shows us how to find the equation of a plane in standard form (ax+by+cz+d=0ax + by + cz + d = 0) given two non-collinear vectors in the plane. That specific equation in this case happens to be 15x3y+4z=015x - 3y + 4z = 0, which means the set of vectors [xyz]\begin{bmatrix} x \\ y \\ z \end{bmatrix} that satisfy this equation form a subspace of R3\mathbb{R}^3.

Example: Plane x+y+z=0x + y + z = 0

What if we’re instead given a plane, rather than the span of a collection of vectors?

It turns out that not only is every span a subspace, but every subspace can be spanned by some collection of vectors. The plane x+y+z=0x + y + z = 0 is a subspace of R3\mathbb{R}^3. Can we write it as the span of a collection of vectors? Sure we can. We know that it only takes two non-collinear vectors to span a plane, so all we need to do is pick two vectors that lie in x+y+z=0x + y + z = 0.

Arbitrarily, let’s pick the vectors [110]\begin{bmatrix} 1 \\ -1 \\ 0 \end{bmatrix} and [213]\begin{bmatrix} 2 \\ 1 \\ -3 \end{bmatrix}. These vectors aren’t collinear (as a reminder, this means that one is not a scalar multiple of the other), so they span a plane.

So, the plane x+y+z=0x + y + z = 0 is the span of the vectors [110]\begin{bmatrix} 1 \\ -1 \\ 0 \end{bmatrix} and [213]\begin{bmatrix} 2 \\ 1 \\ -3 \end{bmatrix}, and so it’s a subspace of R3\mathbb{R}^3. These are not the only two vectors that span this plane; there are infinitely many pairs of vectors that can be said to span this plane. I just picked a pair that happens to have nice numbers.

I’ve plotted the plane below, without the vectors [110]\begin{bmatrix} 1 \\ -1 \\ 0 \end{bmatrix} and [213]\begin{bmatrix} 2 \\ 1 \\ -3 \end{bmatrix}, to emphasize that you should think of planes through the origin as subspaces in their own right.

Loading...

Example: Plane x+y+z=5x + y + z = 5

What about a plane that doesn’t pass through the origin? Is the plane x+y+z=5x + y + z = 5 a subspace of R3\mathbb{R}^3?

Loading...

Remember, subspaces must contain the zero vector, but the vector [000]\begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix} doesn’t satisfy x+y+z=5x + y + z = 5. So, the plane x+y+z=5x + y + z = 5 is not a subspace of R3\mathbb{R}^3.

Equivalently, you know that the span of any set of vectors must also always contain the zero vector, since you’re always able to create the zero vector by taking 0 of each of the spanning vectors, 0v1+0v2++0vd=00{\color{#3d81f6}\vec v_1} + 0{\color{#3d81f6}\vec v_2} + \cdots + 0{\color{#3d81f6}\vec v_d} = \vec 0. So, if a set does not contain the zero vector, it can’t be the span of any set of vectors, but as we just saw, all subspaces must be spanned by some set of vectors. If it can’t be a span, it can’t be a subspace, and so the plane x+y+z=5x + y + z = 5 is not a subspace of R3\mathbb{R}^3.


Basis and Dimension

In Chapter 2.4, we looked at how to find linearly independent subsets with the same span as a given set of vectors. We like the vectors we’re dealing with to be linearly independent, so that any of their linear combinations are unique and can only be created in one way. (This was proved in Chapter 2.4.)

The specific example we looked at was

v1=[340],v2=[011],v3=[322],v4=[653],v5=[251]\vec v_1 = \begin{bmatrix} 3 \\ 4 \\ 0 \end{bmatrix}, \quad \vec v_2 = \begin{bmatrix} 0 \\ 1 \\ 1 \end{bmatrix}, \quad \vec v_3 = \begin{bmatrix} -3 \\ -2 \\ 2 \end{bmatrix}, \quad \vec v_4 = \begin{bmatrix} 6 \\ 5 \\ -3 \end{bmatrix}, \quad \vec v_5 = \begin{bmatrix} 2 \\ 5 \\ 1 \end{bmatrix}

And, through the algorithm introduced at the bottom of that section, we found that the vectors v1,v2,v5\vec v_1, \vec v_2, \vec v_5 alone have the same span as the original set of 5 vectors, but are also linearly independent.

span({v1,v2,v5})=span({v1,v2,v3,v4,v5})\text{span}(\{ \vec v_1, \vec v_2, \vec v_5 \}) = \text{span}(\{ \vec v_1, \vec v_2, \vec v_3, \vec v_4, \vec v_5 \})

The vectors v3\vec v_3 and v4\vec v_4 can be written as linear combinations of v1,v2,v5\vec v_1, \vec v_2, \vec v_5, so they are not needed to describe the span of the original set of 5 vectors. In particular,

v3=v1+2v2,v4=2v13v2\vec v_3 = - \vec v_1 + 2 \vec v_2, \quad \vec v_4 = 2 \vec v_1 -3 \vec v_2

There is a special name for a set of vectors that are both linearly independent and span a subspace, like v1,v2,v5\vec v_1, \vec v_2, \vec v_5 above.

In the example above, the vectors v1,v2,v5\vec v_1, \vec v_2, \vec v_5 are a basis for the span of the original set of 5 vectors, or equivalently, a basis for the subspace of R3\mathbb{R}^3 containing all of the vectors that can be written as linear combinations of the original 5 vectors.

Think of a basis as the minimum set of vectors you need to describe every vector in a subspace:

  • If you remove a vector from a basis, you’ll no longer be able to reach every vector in the subspace.

  • If you add an extra vector to a basis, the new set will no longer be linearly independent.

Again, continuing with the example above, since we’ve found a basis containing 3 vectors for the span of the original set of 5 vectors, the dimension of the span of the original set of 5 vectors is 3 (not 5). So, I might say

dim(span({v1,v2,v3,v4,v5}))=3\dim(\text{span}(\{ \vec v_1, \vec v_2, \vec v_3, \vec v_4, \vec v_5 \})) = 3

A basis for a subspace is not unique. Sure, v1,v2,v5\vec v_1, \vec v_2, \vec v_5 is a basis for the span of the original set of 5 vectors, but so is v3,v4,v5\vec v_3, \vec v_4, \vec v_5, another collection of 3 vectors.

And, since both of these bases (v1,v2,v5\vec v_1, \vec v_2, \vec v_5 and v3,v4,v5\vec v_3, \vec v_4, \vec v_5) involve 3 linearly independent vectors in R3\mathbb{R}^3, they span all of R3\mathbb{R}^3. What’s another set of linearly independent vectors in R3\mathbb{R}^3 that span R3\mathbb{R}^3? There’s the easy choice, of [100],[010],[001]\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}.

Standard Basis for Rn\mathbb{R}^n

We say the standard basis for Rn\mathbb{R}^n is the set of vectors [1000],[0100],,[0001]\begin{bmatrix} 1 \\ 0 \\ 0 \\ \vdots \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 1 \\ 0 \\ \vdots \\ 0 \end{bmatrix}, \ldots, \begin{bmatrix} 0 \\ 0 \\ 0 \\ \vdots \\ 1 \end{bmatrix}. Sometimes these vectors are written as e1,e2,,en\vec e_1, \vec e_2, \ldots, \vec e_n. In addition to being a basis for Rn\mathbb{R}^n, they’re also unit vectors, and orthogonal.

Since the standard basis for Rn\mathbb{R}^n is, well, a basis, and any basis for a subspace has the same number of elements, we know that Rn\mathbb{R}^n is nn-dimensional.

In R2\mathbb{R}^2, the standard basis consists of e1=[10]\vec e_1 = \begin{bmatrix} 1 \\ 0 \end{bmatrix} and e2=[01]\vec e_2 = \begin{bmatrix} 0 \\ 1 \end{bmatrix}. e1\vec e_1 and e2\vec e_2 are linearly independent (neither is a scalar multiple of the other), and they span all of R2\mathbb{R}^2, which means that any other vector in R2\mathbb{R}^2 can be written as a linear combination of them.

Pick your favorite vector with two components, say [512]\begin{bmatrix} 5 \\ -12 \end{bmatrix}, and you’ll be able to write it as a linear combination of the standard basis.

[512]=5[10]12[01]=5v112v2linear combination of standard basis\begin{bmatrix} 5 \\ -12 \end{bmatrix} = 5 \begin{bmatrix} 1 \\ 0 \end{bmatrix} - 12 \begin{bmatrix} 0 \\ 1 \end{bmatrix} = \underbrace{5 \vec v_1 - 12 \vec v_2}_\text{linear combination of standard basis}

Let’s look at a few more examples of possible bases for given subspaces.

Examples

VectorsAre they a basis for...AnswerWhy?
[10],[15]\begin{bmatrix} 1 \\ 0 \end{bmatrix}, \begin{bmatrix} 1 \\ 5 \end{bmatrix}R2\mathbb{R}^2YesThey’re linearly independent, and span all of R2\mathbb{R}^2.
[100],[010]\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}R3\mathbb{R}^3NoThey’re linearly independent, but don’t span all of R3\mathbb{R}^3, since no linear combination of them can equal [001]\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix} (or any other vector with a nonzero third component).
[100],[010],[345]\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, \begin{bmatrix} 3 \\ 4 \\ 5 \end{bmatrix}R3\mathbb{R}^3YesThey’re linearly independent, and span all of R3\mathbb{R}^3. They’re not the standard basis, but they’re still a basis.
[100],[010],[001],[345]\begin{bmatrix} 1 \\ 0 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}, \begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix}, \begin{bmatrix} 3 \\ 4 \\ 5 \end{bmatrix}R3\mathbb{R}^3NoThey span all of R3\mathbb{R}^3 but they’re not linearly independent. R3\mathbb{R}^3 has dimension 3, so a basis for R3\mathbb{R}^3 must have 3 vectors.

Finding a Basis for a Subspace

Often, we’ll need to find a basis for a given subspace. If the subspace in question is the span of a set of vectors, we can use the algorithm from the bottom of Chapter 2.4 to find a basis.

given v_1, v_2, ..., v_d
initialize linearly independent set S = {v_1}
for i = 2 to d:
    if v_i is not a linear combination of S:
        add v_i to S

All this algorithm does is remove linearly dependent vectors from left to right, so that the remaining vectors are linearly independent.

For example, if

v1=[111],v2=[123],v3=[301]\vec v_1 = \begin{bmatrix} 1 \\ 1 \\ 1 \end{bmatrix}, \quad \vec v_2 = \begin{bmatrix} 1 \\ -2 \\ -3 \end{bmatrix}, \quad \vec v_3 = \begin{bmatrix} -3 \\ 0 \\ 1 \end{bmatrix}

A basis for span({v1,v2,v3})\text{span}\left( \left\{ \vec v_1, \vec v_2, \vec v_3 \right\} \right) is {v1,v2}\left\{ \vec v_1, \vec v_2 \right\}, since these two vectors are linearly independent and span the same subspace as the original three vectors; v3\vec v_3 is a linear combination of v1\vec v_1 and v2\vec v_2, specifically v3=2v1v2\vec v_3 = -2 \vec v_1 - \vec v_2.

Equivalently, {v1,v3}\{ \vec v_1, \vec v_3 \} is also a basis for the same subspace, since we can equivalently say v2=2v1v3\vec v_2 = - 2 \vec v_1 - \vec v_3. Either way, dim(span({v1,v2,v3}))=2\text{dim}\left( \text{span}\left( \left\{ \vec v_1, \vec v_2, \vec v_3 \right\} \right) \right) = 2.

See the bottom of Chapter 2.4 for another worked example.

What about subspaces that aren’t expressed explicitly as a span – how do we find a basis for them? For instance, consider the subspace of R3\mathbb{R}^3 containing vectors [xyz]\begin{bmatrix} x \\ y \\ z \end{bmatrix} such that 2x3y+4z=02x - 3y + 4z = 0. This is a plane through the origin, and so we know it’s spanned by two non-collinear vectors in R3\mathbb{R}^3.

Some subspaces aren’t explicitly expressed as a span, but we can still find a basis for them. We looked at an example of this earlier in this section, before we knew what a basis was. Specifically, we saw the plane of points [xyz]\begin{bmatrix} x \\ y \\ z \end{bmatrix} such that x+y+z=0x + y + z = 0 is spanned by [110]\begin{bmatrix} 1 \\ -1 \\ 0 \end{bmatrix} and [213]\begin{bmatrix} 2 \\ 1 \\ -3 \end{bmatrix}. Since these two vectors are linearly independent, they form a basis for the subspace (a basis of dimension 2).