Skip to main content

Linear Algebra with SageMath Learn math with open-source software

Section 10.2 Subspaces

A subspace of the vector space \(V\) is a nonempty subset \(W\) of \(V\) such that \(W\) is a vector space under the same addition and scalar multiplication as on \(V\text{.}\)
For a nonempty subset \(W\) of a vector space \(V\text{,}\) to check that \(W\) is a subspace of \(V\text{,}\) we need only verify that \(W\) satisfies the closure properties:
Addition
If \(u, w \in W\text{,}\) then \(u + w \in W\text{.}\)
Scalar Multiplication
If \(a \in \F\) and \(u \in W\text{,}\) then \(a \cdot u \in W\text{.}\)
Sage does not provide a way to check if a subset is a subspace. The method is_subspace admits as argument a vector space \(W\) and check if it is subspace of the ambient space \(V\text{.}\) In other words, it checks if \(W\) is a subset of \(V\text{.}\)
We obtained that \(\R^2\) is not a subspace of \(\R^3\) since it is not a subset.
Next, we will explore a method for constructing a specific type of subspace within a given vector space.

Subsection 10.2.1 Spans

A linear combination of a set of vectors \(G = \{v_1, \dots, v_k\}\) in a vector space \(V\) over the field \(\mathbb F\) is a vector of the form \(a_1 v_1 + \dots +a_k v_k\text{,}\) where \(a_1,\dots ,a_k \in \mathbb F\text{.}\)

Note 10.2.1. Sets of Vectors.

We use the term "set" to describe our collection of vectors as that is standard in linear algebra. However, most Sage commands that generate vector spaces take lists as arguments.
We use the term "set" to describe our collection of vectors as that is standard in linear algebra. However, most Sage commands that generate vector spaces take lists as arguments.
For example, let’s calculate a linear combination of the vectors \(u\) and \(v\) in \(\R^3\text{:}\)
The set of all linear combinations of a set of vectors \(G\) forms a subspace of \(V\) called the span of \(G\text{,}\) denoted \(\operatorname{span}(G)\text{.}\)
In Sage, the span command can be used to create the span of a set of vectors. Let’s find the span of the vectors \(u\) and \(v\) in \(\R^3\text{.}\)
We can verify that \(S\) is a subspace of \(\R^3\text{:}\)
Observe that the subspace spanned by the set of vectors \(u, v\) and \(3u + 2v\) is also \(S\text{:}\)
We can now check if the vector spaces are the same.
We see that the new vector added to the generators is redundant. Next, we will see how Sage can detect this redundancy.

Subsection 10.2.2 Linear Independence

The vectors \(v_1, v_2, \dots ,v_k\) are linearly dependent if there exists scalars \(c_1, c_2,\dots , c_k \in \mathbb F\text{,}\) such that
\begin{gather*} c_1 v_1 + c_2 v_2 + \dots + c_n v_k = 0 \end{gather*}
where at least one \(c_i \neq 0\text{.}\)
Otherwise, we say they are linearly independent.
Sage provides the linear_dependence method to check if a set of vectors is linearly dependent in a given vector space, and in that case outputs a list of coefficient vectors of the linear combinations.
We can then test for linear dependence in the context of \(V\text{.}\)
We obtained a list of coefficients, indicating that the vectors \(u,v\) and \(w\) are linearly dependent and the following combination gives the vector zero:
\begin{gather*} 1u + (2/3)v + (-1/3)w = 0 \end{gather*}
Observe that the coefficients in the linear combination are not unique. Sage assigns by default \(1\) as the first coefficient.
Let us now consider the set of vectors \(\{u, v\}\text{.}\) If the set of vectors is linearly independent, then Sage returns an empty list:
We can also check directly for linear independence:
Note that linear_dependence also takes matrices as arguments.
Alternatively, we can manually check if a set of vectors is linearly independent by using the matrix methods studied before.
Recall, the rank of a matrix \(M\) is the maximal number of linearly independent row vectors (rows viewed as vectors).
The result is True, so the set \(\{u, w\}\) is linearly independent. Now let’s consider a linearly dependent set.