Subspaces and Quotients
A vector space can contain smaller vector spaces called subspaces. We can also “divide” a space by a subspace to create a quotient space.
Subspaces
A subset of a vector space is a subspace if:
- The zero vector .
- is closed under addition: .
- is closed under scalar multiplication: .
python
1import numpy as np
2
3def is_in_subspace(vector, basis):
4 """Check if a vector is in the subspace spanned by a basis."""
5 # Solve basis * c = vector
6 A = np.array(basis).T
7 try:
8 x, residuals, rank, s = np.linalg.lstsq(A, vector, rcond=None)
9 # If residuals are near zero, it's in the subspace
10 return np.allclose(np.dot(A, x), vector)
11 except:
12 return False
13
14subspace_basis = [[1, 0, 0], [0, 1, 0]]
15v1 = [0.5, 2.0, 0.0]
16v2 = [0.5, 2.0, 1.0]
17
18print(f"Vector {v1} in subspace: {is_in_subspace(v1, subspace_basis)}")
19print(f"Vector {v2} in subspace: {is_in_subspace(v2, subspace_basis)}")
Quotient Spaces
Given a subspace , the quotient space is the set of all cosets . Intuitively, the quotient space “ignores” all differences that lie within .
The dimension of a quotient space is:
If V = R3 and W is a line through the origin, what is the dimension of V/W?
Kernels and Images
For a linear map :
- The Kernel is a subspace of .
- The Image is a subspace of .
python
1import numpy as np
2from scipy.linalg import null_space
3
4A = np.array([[1, 2, 3], [2, 4, 6], [1, 1, 1]])
5
6# Find basis for kernel
7ns = null_space(A)
8print(f"Basis for Kernel (Null Space):\n{ns}")
9
10# Find rank (dimension of image)
11rank = np.linalg.matrix_rank(A)
12print(f"Rank (dim of Image): {rank}")