Subspaces#
What is a Subspace?#
Definition: Subspace:
In linear algebra, a subspace is a subset of a vector space that satisfies three conditions:
Contains the zero vector: The zero vector of the vector space must be within the subspace.
Closed under addition: If you add any two vectors from the subspace, the result also stays within the subspace.
Closed under scalar multiplication: If you multiply any vector from the subspace by a scalar (a number), the result remains in the subspace.
Think of subspaces as smaller “worlds” within the larger vector space that follow the same rules.
SageMath Examples
Let’s use SageMath to illustrate these concepts:
1. Creating Vector Spaces and Subspaces#
# Create a vector space over the rational numbers (ℚ)
V = VectorSpace(QQ, 4)
# Define the vectors
v1 = V([1, 0, 2, -1])
v2 = V([0, 1, -3, 2])
# Create a subspace W spanned by the given vectors
W = V.subspace([v1, v2])
print(W.vector_space())
Vector space of degree 4 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 2 -1]
[ 0 1 -3 2]
In this example:
Vis a 4-dimensional vector space where the components of the vectors are rational numbers.Wis a subspace ofVdefined by the linear combinations of the two given vectors.The returned basis matrix is the two vectors!
NOTE: The basis of a subspace is not always the same as the input vectors used to define the subspace. The basis vectors of a subspace must be linearly independent, and they span the subspace. If the input vectors are linearly independent and span the subspace, they will be a basis. However, if the input vectors are not linearly independent, SageMath will provide a reduced set of vectors that form a basis.
We can retrieve the basis directly and test for linearly independence as shown below.
2. Finding a Basis for a Subspace#
# Print the basis of the subspace W
basis = W.basis()
print("Basis of the subspace W:", basis)
Basis of the subspace W: [
(1, 0, 2, -1),
(0, 1, -3, 2)
]
This calculates a set of linearly independent vectors that span the subspace W.
Next, we can test for dependence with:
dependence = V.linear_dependence([v1, v2])
if not dependence:
print("The vectors are linearly independent.")
else:
print("The vectors are linearly dependent.")
print("Linear dependence relations:", dependence)
The vectors are linearly independent.
3. Checking if a Vector Belongs to a Subspace#
First let’s try a vector that is a linear combination of the basis
v3 = 2 * basis[0] # 2 * [1,0,2,-1]
print(v3)
v = vector(QQ, v3)
print(v in W)
(2, 0, 4, -2)
True
Now try a vector that is not a linear combination of the basis.
Here we use [1, 2, 1, 2] as it is just the first basis vector with the last element changed from -1 to 2.
You can see that this vector is not a linear combination of the basis [(1, 0, 2, -1), (0, 1, -3, 2)]
# Check if a vector is in the subspace
v = vector(QQ, [1, 2, 1, 2])
print(v in W)
False
In summary, v in W checks if v is a linear combination of the basis vectors of W.
4. Other Operations#
SageMath offers many functions for working with subspaces:
W.dimension(): Gives the dimension of the subspace.W1 + W2: Calculates the sum of two subspaces.W1.intersection(W2): Finds the intersection of two subspaces.
Visualizing Subspaces (2D and 3D)#
If you’re dealing with subspaces in 2D or 3D, you can even visualize them using SageMath’s plotting capabilities.
# Create a vector space over the rational numbers (ℚ)
V = VectorSpace(QQ, 3)
# Create a subspace spanned by two vectors
P = V.subspace([[1, 0, 1], [0, 1, -1]])
# Extract basis vectors of the subspace
basis_vectors = P.basis()
print("Basis vectors:", basis_vectors)
# definte the parameters for the plot
var('t','u')
# Create a parametric plot of the plane
plane_plot = parametric_plot3d(
# The parametric equations for the plane are given
# by the linear combination of the basis vectors,
# scaled by `t` and `u`
(basis_vectors[0][0]*t + basis_vectors[1][0]*u,
basis_vectors[0][1]*t + basis_vectors[1][1]*u,
basis_vectors[0][2]*t + basis_vectors[1][2]*u),
# The parameters `t` and `u` vary from -1 to 1
(t, -1, 1), (u, -1, 1),
color='lightblue', opacity=0.8
)
# Add arrows for the basis vectors
arrow1 = arrow3d((0, 0, 0), (basis_vectors[0][0], basis_vectors[0][1], basis_vectors[0][2]), color='red', width=2)
arrow2 = arrow3d((0, 0, 0), (basis_vectors[1][0], basis_vectors[1][1], basis_vectors[1][2]), color='green', width=2)
# Combine the plane plot and the arrows
combined_plot = plane_plot + arrow1 + arrow2
# Display the plot with arrows
combined_plot.show(aspect_ratio=[1, 1, 1])
Basis vectors: [
(1, 0, 1),
(0, 1, -1)
]
(You can interactively rotate, zoom, and pan the above 3D plots using the mouse)
This generates a parametric plot of the plane. The parametric equations for the plane are given by the linear combination of the basis vectors, scaled by \( t \) and \( u \):
\((x, y, z) = (t \cdot 1 + u \cdot 0, \: t \cdot 0 + u \cdot 1, \: t \cdot 1 + u \cdot -1)\)
Which simplifies to:
\((x, y, z) = (t, u, t - u)\)
What the Plot Shows#
The plot is a visual representation of the plane in 3D space that is spanned by the vectors \([1, 0, 1]\) and \([0, 1, -1]\). The parameters \( t \) and \( u \) vary from -1 to 1, which effectively plots a portion of the plane within this range.
The first basis vector is colored red and the second one is greed.
The plane is colored light blue and has an opacity of 0.8, making it semi-transparent.
The plane extends infinitely in all directions, but the plot shows a finite portion based on the specified range for \( t \) and \( u \).
In summary, the plot is a graphical representation of the subspace (a plane) spanned by the vectors \([1, 0, 1]\) and \([0, 1, -1]\) in the 3-dimensional vector space. The plotted plane can be described by the equation \( z = x - y \).
Why Subspaces Matter#
Subspaces are fundamental in linear algebra:
They are used to describe solutions to systems of linear equations.
They are essential in understanding the structure of matrices (e.g., null spaces, column spaces, row spaces).
They play a role in many areas of applied mathematics, physics, and engineering.