Tutorial 5 (AY24/25 Sem 1)¶
# Required imports
import sympy as sym
from ma1522 import Matrix
Question 1¶
For each of the following sets of vectors $S$,
(i) Determine if $S$ is linearly independent.
(ii) If $S$ is linearly dependent, express one of the vectors in $S$ as a linear combination of the others.
(a)¶
$S = \left\{\begin{pmatrix} 2 \\ -1 \\ 0 \end{pmatrix}, \begin{pmatrix} 0 \\ 3 \\ 2 \end{pmatrix}, \begin{pmatrix} 2 \\ 4 \\ 3 \end{pmatrix}, \begin{pmatrix} 3 \\ 6 \\ 6 \end{pmatrix}\right\}$.
S = Matrix.from_str("2 -1 0; 0 3 2; 2 4 3; 3 6 6").T
S
S.is_linearly_independent(verbosity=2)
Before RREF: self
After RREF:
Check if Number of columns (4) == Number of pivot columns (3)
False
Based on the RREF, the last column can be expressed as a linear combination of the first three columns
(b)¶
$S = \left\{\begin{pmatrix} 1 \\ 1 \\ 0 \end{pmatrix}, \begin{pmatrix} 3 \\ 4 \\ 2 \end{pmatrix}\right\}$.
S = Matrix.from_str("1 1 0; 3 4 2").T
S
S.is_linearly_independent(verbosity=2)
Before RREF: self
After RREF:
Check if Number of columns (2) == Number of pivot columns (2)
True
(c)¶
$S = \left\{\begin{pmatrix} 1 \\ 1 \\ 0 \end{pmatrix}, \begin{pmatrix} 3 \\ 4 \\ 2 \end{pmatrix}, \begin{pmatrix} 0 \\ 0 \\ 0 \end{pmatrix}\right\}$.
S = Matrix.from_str("1 1 0; 3 4 2; 0 0 0").T
S
S.is_linearly_independent(verbosity=2)
Before RREF: self
After RREF:
Check if Number of columns (3) == Number of pivot columns (2)
False
(d)¶
$S = \left\{\begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix}, \begin{pmatrix} 0 \\ 1 \\ 1 \end{pmatrix}, \begin{pmatrix} 1 \\ 2 \\ -1 \end{pmatrix}\right\}$.
S = Matrix.from_str("1 0 0; 0 1 1; 1 2 -1").T
S
S.is_linearly_independent(verbosity=2)
Before RREF: self
After RREF:
Check if Number of columns (3) == Number of pivot columns (3)
True
Question 2¶
Suppose $u$, $v$, $w$ are linearly independent vectors in $\mathbb{R}^n$. Determine which of the sets $S_1$ to $S_5$ are linearly independent.
(d)¶
$S_4 = \{u, u + v, u + v + w\}$.
# Tip: Use `sympy.solve` to help you find non-trivial solutions
a, b, c = sym.symbols("a b c")
u, v, w = sym.symbols("u v w")
v1 = u
v2 = u + v
v3 = u + v + w
# Solve the system of equations to find the coefficients a, b, c
sols = sym.solve(a*v1 + b*v2 + c*v3, (a, b, c))
sols # only trivial solution exists -> the set is linearly independent
(e)¶
$S_5 = \{u + v, v + w, u + w, u + v + w\}$.
a, b, c, d = sym.symbols("a b c d")
u, v, w = sym.symbols("u v w")
v1 = u + v
v2 = v + w
v3 = u + w
v4 = u + v + w
# Solve the system of equations to find the coefficients a, b, c, d
sols = sym.solve(a*v1 + b*v2 + c*v3 + d*v4, (a, b, c, d))
sols # non-trivial solution exists -> the set is linearly dependent
V = Matrix.from_str("a+b; a+c; c+d; b+d")
vecs = V.sep_unk()
vecs
V = Matrix.from_list([*vecs.values()])
V
# Tip: Use pivots in the RREF to get linearly independent vectors
V.get_linearly_independent_vectors(verbosity=1)
Before RREF: [self]
After RREF:
Select columns of self corresponding to pivot positions.
(b)¶
$V = \text{span}\left\{\begin{pmatrix} 1 \\ 0 \\ -1 \end{pmatrix}, \begin{pmatrix} -1 \\ 2 \\ 3 \end{pmatrix}, \begin{pmatrix} 0 \\ 3 \\ 0 \end{pmatrix}, \begin{pmatrix} 1 \\ -1 \\ 1 \end{pmatrix}\right\}$.
V = Matrix.from_str("1 0 -1; -1 2 3; 0 3 0; 1 -1 1").T
V
V.get_linearly_independent_vectors(verbosity=1)
Before RREF: [self]
After RREF:
Select columns of self corresponding to pivot positions.
(c)¶
$V$ is the solution space of the following homogeneous linear system $$\begin{cases} a_1 && &+& a_3 &+& a_4 &-& a_5 &=& 0 \\ && a_2 &+& a_3 &+& 2a_4 &+& a_5 &=& 0 \\ a_1 &+& a_2 &+& 2a_3 &+& a_4 &-& 2a_5 &=& 0 \end{cases}$$
mat = Matrix.from_str("1 0 1 1 -1; 0 1 1 2 1; 1 1 2 1 -2")
mat
V = mat.nullspace()
V
Matrix.from_list(V).get_linearly_independent_vectors(verbosity=1)
Before RREF: [self]
After RREF:
Select columns of self corresponding to pivot positions.
Question 4¶
For what values of $a$ will $u_1 = \begin{pmatrix} a \\ 1 \\ -1 \end{pmatrix}$, $u_2 = \begin{pmatrix} -1 \\ a \\ 1 \end{pmatrix}$, $u_3 = \begin{pmatrix} 1 \\ -1 \\ a \end{pmatrix}$ form a basis for $\mathbb{R}^3$?
a = sym.symbols("a", real=True) # remember to set real=True for real numbers only
U = Matrix([[a, 1, -1], [-1, a, 1], [1, -1, a]]).T
U
sym.solve(U.det()) # basis for R^3 if a != 0
Question 5¶
Let $U$ and $V$ be subspaces of $\mathbb{R}^n$. We define the sum $U + V$ to be the set of vectors $\{u + v \mid u \in U \text{ and } v \in V\}$.
Suppose $U = \text{span}\left\{\begin{pmatrix} 1 \\ 1 \\ 1 \\ 1 \end{pmatrix}, \begin{pmatrix} 1 \\ 2 \\ 2 \\ 1 \end{pmatrix}\right\}$, $V = \text{span}\left\{\begin{pmatrix} 1 \\ 0 \\ 1 \\ 0 \end{pmatrix}, \begin{pmatrix} 1 \\ 0 \\ 2 \\ -1 \end{pmatrix}\right\}$.
(b)¶
Show that $U + V$ is a subspace of $\mathbb{R}^n$ by showing that it can be written as a span of a set. What is the dimension?
U = Matrix.from_str("1 1 1 1; 1 2 2 1").T
V = Matrix.from_str("1 0 1 0; 1 0 2 -1").T
U, V
U.row_join(V).get_linearly_independent_vectors(verbosity=1)
Before RREF: [self]
After RREF:
Select columns of self corresponding to pivot positions.
(e)¶
Show that $U \cap V$ a subspace by showing that it can be written as a span of a set. What is the dimension?
U.intersect_subspace(V, verbosity=2) # intersection of U and V
A linear system whose solution space is the subspace of self. Null(self^T)^T
A linear system whose solution space is the subspace of other. Null(other^T)^T
Before RREF: [self ; other]
After RREF: