TExcelTAD
Home › Linear Algebra & Matrix Theory › Subspaces of ℝⁿ

Subspaces of Rn\mathbb{R}^n

A subspace is a set of vectors that is closed under the two vector operations: adding and scaling never lead outside it. Lines and planes through the origin are the typical examples. Subspaces are the "flat pieces" of Rn\mathbb{R}^n that linear algebra works with: spans, solution sets of homogeneous systems, column spaces.

Definition

A subset VV of Rn\mathbb{R}^n is a subspace if

  1. 0∈V\mathbf{0} \in V (it contains the zero vector),
  2. closed under addition: u,v∈V⇒u+v∈V\mathbf{u}, \mathbf{v} \in V \Rightarrow \mathbf{u} + \mathbf{v} \in V,
  3. closed under scalar multiplication: v∈V, c∈R⇒cv∈V\mathbf{v} \in V,\ c \in \mathbb{R} \Rightarrow c\mathbf{v} \in V.

Conditions 2 and 3 together say VV is closed under all linear combinations. Condition 1 mostly serves to rule out the empty set; given a non-empty VV, it follows from 3 with c=0c = 0.

Examples and non-examples

Set Subspace? Why
{0}\{\mathbf{0}\} and Rn\mathbb{R}^n itself yes the trivial subspaces
a line through 0\mathbf{0} yes =span⁡{v}= \operatorname{span}\{\mathbf{v}\}
the plane x+2y−z=0x + 2y - z = 0 in R3\mathbb{R}^3 yes solutions of a homogeneous equation
the plane x+2y−z=4x + 2y - z = 4 no does not contain 0\mathbf{0}
the first quadrant {x≥0,y≥0}\{x \ge 0, y \ge 0\} no (−1)⋅[1,1](-1) \cdot [1, 1] leaves it
the union of the two axes in R2\mathbb{R}^2 no [1,0]+[0,1]=[1,1][1, 0] + [0, 1] = [1, 1] is on neither axis
{[x,y]:y=x2}\{[x, y] : y = x^2\} no [1,1][1, 1] is in it, 2⋅[1,1]=[2,2]2 \cdot [1, 1] = [2, 2] is not

The subspaces of R3\mathbb{R}^3 are exactly: {0}\{\mathbf{0}\}, lines through 0\mathbf{0}, planes through 0\mathbf{0}, and R3\mathbb{R}^3.

Two big sources of subspaces

Spans are subspaces. If u=a1v1+⋯+akvk\mathbf{u} = a_1\mathbf{v}_1 + \cdots + a_k\mathbf{v}_k and w=b1v1+⋯+bkvk\mathbf{w} = b_1\mathbf{v}_1 + \cdots + b_k\mathbf{v}_k, then u+w=(a1+b1)v1+⋯\mathbf{u} + \mathbf{w} = (a_1 + b_1)\mathbf{v}_1 + \cdots and cu=(ca1)v1+⋯c\mathbf{u} = (ca_1)\mathbf{v}_1 + \cdots are again combinations. Conversely, every subspace of Rn\mathbb{R}^n is the span of finitely many vectors (shown in Basis and Dimension).

Solution sets of homogeneous systems are subspaces. If Au=0A\mathbf{u} = \mathbf{0} and Av=0A\mathbf{v} = \mathbf{0}, then A(u+v)=Au+Av=0A(\mathbf{u} + \mathbf{v}) = A\mathbf{u} + A\mathbf{v} = \mathbf{0} and A(cu)=c⋅Au=0A(c\mathbf{u}) = c \cdot A\mathbf{u} = \mathbf{0}. This subspace is the null space of AA. For b≠0\mathbf{b} \ne \mathbf{0} the solution set of Ax=bA\mathbf{x} = \mathbf{b} is not a subspace (0\mathbf{0} is not a solution); it is a shifted copy xp+null⁡(A)\mathbf{x}_p + \operatorname{null}(A) of the null space, an affine subspace.

So every subspace can be described in two ways: explicitly as a span, or implicitly as the solutions of equations. Converting between them is row reduction:

python · try it yourself
from sympy import Matrix

# implicit: the plane x + 2y - z = 0  ->  explicit: a span
A = Matrix([[1, 2, -1]])
basis = A.nullspace()
print("plane = span of", [list(v) for v in basis])

# explicit: span{[1,0,2],[0,1,1]} -> implicit: equations whose null space it is
S = Matrix.hstack(Matrix([1, 0, 2]), Matrix([0, 1, 1]))
normals = S.T.nullspace()                  # vectors n with n·v = 0 for both spanning vectors
print("span = solutions of n·x = 0 for n =", [list(n) for n in normals])
plane = span of [[-2, 1, 0], [1, 0, 1]]
span = solutions of n·x = 0 for n = [[-2, -1, 1]]

So the plane spanned by [1,0,2][1, 0, 2] and [0,1,1][0, 1, 1] is −2x−y+z=0-2x - y + z = 0, i.e. z=2x+yz = 2x + y.

Testing a claim numerically

A proof is needed to show a set is a subspace, but one counterexample shows it is not. Random testing is a fast way to find one (or to build confidence before proving):

python · try it yourself
import numpy as np

rng = np.random.default_rng(11)

def looks_closed(member, sample, trials=1000):
    for _ in range(trials):
        u, v, c = sample(), sample(), float(rng.normal() * 3)
        if not (member(u + v) and member(c * u)):
            return False, np.round(u, 3).tolist(), np.round(v, 3).tolist(), round(c, 3)
    return True, None, None, None

plane = lambda p: abs(p[0] + 2 * p[1] - p[2]) < 1e-9
def sample_plane():
    x, y = rng.normal(size=2)
    return np.array([x, y, x + 2 * y])

quadrant = lambda p: p[0] >= 0 and p[1] >= 0
sample_quadrant = lambda: rng.uniform(0, 1, size=2)

print("plane x+2y-z=0:", looks_closed(plane, sample_plane)[0])
print("first quadrant:", looks_closed(quadrant, sample_quadrant)[0])
plane x+2y-z=0: True
first quadrant: False

In software

  • Constraints that are homogeneous equations carve out subspaces. In a physics or network simulation, flows with "inflow = outflow at every node" form the null space of the incidence matrix; any combination of valid flows is valid (Application: Resistor Networks).
  • Embedding debiasing: researchers estimate a "bias direction" (a subspace spanned by differences like he−she\text{he} - \text{she}) in word embeddings and remove each vector's component in that subspace. That is an orthogonal projection onto the complementary subspace (Orthogonal Projections).
  • Affine vs linear: game engines keep the distinction between points and directions because of exactly this lesson. Directions (velocities, normals) form a vector space; positions do not, since "position + position" is meaningless, which is why homogeneous coordinates give points w=1w = 1 and directions w=0w = 0 (Homogeneous Coordinates).

Exercises

Exercise 1: Subspace or not?

Which of these subsets of R3\mathbb{R}^3 are subspaces? (a) {[x,y,z]:z=0}\{[x, y, z] : z = 0\}, (b) {[x,y,z]:x=y+1}\{[x, y, z] : x = y + 1\}, (c) {[x,y,z]:xyz=0}\{[x, y, z] : xyz = 0\}, (d) {[t,2t,−t]:t∈R}\{[t, 2t, -t] : t \in \mathbb{R}\}.

Answer

(a) and (d) are subspaces; (b) and (c) are not.

Solution

(a) The xyxy-plane: solutions of the homogeneous equation z=0z = 0. (b) Does not contain 0\mathbf{0} (0≠0+10 \ne 0 + 1). (c) Contains [1,1,0][1, 1, 0] and [0,0,1][0, 0, 1] (each has a zero coordinate) but not their sum [1,1,1][1, 1, 1]. (d) span⁡{[1,2,−1]}\operatorname{span}\{[1, 2, -1]\}, a line through 0\mathbf{0}.

Exercise 2: Implicit to explicit

Write the subspace {[x,y,z,w]:x−y+2w=0, y+z−w=0}\{[x, y, z, w] : x - y + 2w = 0,\ y + z - w = 0\} of R4\mathbb{R}^4 as a span.

Answer

span⁡{[−1,−1,1,0],[−1,1,0,1]}\operatorname{span}\{[-1, -1, 1, 0], [-1, 1, 0, 1]\}.

Solution
free variables z,w:y=−z+w,x=y−2w=−z−w[x,y,z,w]=z⋅[−1,−1,1,0]+w⋅[−1,1,0,1]\begin{aligned} &\text{free variables } z, w\text{:} \quad y = -z + w, \quad x = y - 2w = -z - w \\ &[x, y, z, w] = z \cdot [-1, -1, 1, 0] + w \cdot [-1, 1, 0, 1] \end{aligned}
python · try it yourself
from sympy import Matrix
A = Matrix([[1, -1, 0, 2], [0, 1, 1, -1]])
print([list(v) for v in A.nullspace()])
[[-1, -1, 1, 0], [-1, 1, 0, 1]]

Exercise 3: Union and intersection

If UU and WW are subspaces of Rn\mathbb{R}^n, prove that U∩WU \cap W is a subspace. Give an example showing U∪WU \cup W need not be.

Answer

U∩WU \cap W is always a subspace; the union of the xx-axis and yy-axis in R2\mathbb{R}^2 is not.

Solution

0\mathbf{0} is in both, so 0∈U∩W\mathbf{0} \in U \cap W. If u,v∈U∩W\mathbf{u}, \mathbf{v} \in U \cap W, then u+v\mathbf{u} + \mathbf{v} and cuc\mathbf{u} lie in UU (UU is closed) and in WW (WW is closed), hence in U∩WU \cap W. For the union: [1,0][1, 0] and [0,1][0, 1] lie in it, but their sum [1,1][1, 1] lies on neither axis.

Exercise 4: Explicit to implicit

Find one linear equation ax+by+cz=0ax + by + cz = 0 that describes span⁡{[1,1,1],[1,−1,3]}\operatorname{span}\{[1, 1, 1], [1, -1, 3]\}.

Answer

2x−y−z=02x - y - z = 0 (or any non-zero multiple).

Solution

[a,b,c][a, b, c] must be orthogonal to both spanning vectors: a+b+c=0a + b + c = 0 and a−b+3c=0a - b + 3c = 0. Adding gives 2a+4c=0→a=−2c2a + 4c = 0 \to a = -2c, then b=−a−c=cb = -a - c = c. With c=−1c = -1: [2,−1,−1][2, -1, -1]. Check: 2−1−1=02 - 1 - 1 = 0 ✓, 2+1−3=02 + 1 - 3 = 0 ✓. (The cross product of the two vectors gives the same normal: [1,1,1]×[1,−1,3]=[4,−2,−2][1, 1, 1] \times [1, -1, 3] = [4, -2, -2].)

Test yourself

Which set is a subspace of R2\mathbb{R}^2?

  1. {[x,y]:y=2x+1}\{[x, y] : y = 2x + 1\}
  2. {[x,y]:x2+y2≤1}\{[x, y] : x^2 + y^2 \le 1\}
  3. {[x,y]:x≥0}\{[x, y] : x \ge 0\}
  4. {[x,y]:y=3x}\{[x, y] : y = 3x\}

Why is the solution set of Ax=bA\mathbf{x} = \mathbf{b} with b≠0\mathbf{b} \ne \mathbf{0} never a subspace?

  1. It may be empty
  2. It is always a single point
  3. It does not contain the zero vector
  4. It is not closed under scaling by 1

What are the possible subspaces of R3\mathbb{R}^3?

  1. Only {0}\{\mathbf{0}\} and R3\mathbb{R}^3
  2. {0}\{\mathbf{0}\}, lines through 0\mathbf{0}, planes through 0\mathbf{0}, and R3\mathbb{R}^3
  3. Any line or plane
  4. Spheres centred at 0\mathbf{0}