Tutorial 4 (AY24/25 Sem 1)¶
# Required imports
import sympy as sym
from ma1522 import Matrix
Question 2¶
Let $u_1 = \begin{pmatrix} 2 \\ 1 \\ 0 \\ 3 \end{pmatrix}$, $u_2 = \begin{pmatrix} 3 \\ -1 \\ 5 \\ 2 \end{pmatrix}$, and $u_3 = \begin{pmatrix} -1 \\ 0 \\ 2 \\ 1 \end{pmatrix}$.
(a)¶
If possible, express each of the following vectors as a linear combination of $u_1$, $u_2$, $u_3$.
(i) $\begin{pmatrix} 2 \\ 3 \\ -7 \\ 3 \end{pmatrix}$
(ii) $\begin{pmatrix} 0 \\ 0 \\ 0 \\ 0 \end{pmatrix}$
(iii) $\begin{pmatrix} 1 \\ 1 \\ 1 \\ 1 \end{pmatrix}$
(iv) $\begin{pmatrix} -4 \\ 6 \\ -13 \\ 4 \end{pmatrix}$
U = Matrix.from_str("2 1 0 3; 3 -1 5 2; -1 0 2 1").T
U
U.column_constraints(verbosity=1)
Before RREF: [self | vec]
After RREF
For the system to be consistent, the following constraints must be satisfied.
# Alternative Method based on RREF
rhs = Matrix.from_str("2 3 -7 3; 0 0 0 0; 1 1 1 1; -4 6 -13 4").T
rhs = Matrix(rhs, aug_pos=range(3))
rhs
aug_mat = U.row_join(rhs)
aug_mat
aug_mat.rref()
(b)¶
Is it possible to find 2 vectors $v_1$ and $v_2$ such that they are not a multiple of each other, and both are not a linear combination of $u_1$, $u_2$, $u_3$?
E = U.extend_basis(verbosity=2)
E
Before RREF: [self | span_subspace]
After RREF:
Select columns of rref([self | span_subspace]) corresponding to pivot positions.
v_1 = E.select_cols(-1) # Not in subspace spanned by U
v_2 = v_1 + U.select_cols(0) # Not a multiple of v_1 or in subspace spanned by U
v_1, v_2
V = Matrix([[1, -1, -1]]).nullspace()
V
S = Matrix.from_str("1 1 0; 5 2 3").T
S.is_same_subspace(Matrix.from_list(V), verbosity=2)
Check if span(self) is subspace of span(other), and vice versa. Check if span(self) is subspace of span(other) Before RREF: [other | self]
After RREF:
Span(self) is a subspace of span(other). Check if span(self) is subspace of span(other) Before RREF: [other | self]
After RREF:
Span(self) is a subspace of span(other).
True
(b)¶
Let $T = S \cup \left\{\begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix}\right\}$. Show that $\text{span}(T) = \mathbb{R}^3$.
S
T = S.row_join(Matrix.from_str("0 0 1").T)
T.rm_aug_line()
# If no `other` subspace is provided, it is assumed to be the entire R^n
T.is_same_subspace(verbosity=2)
Check rref(self) does not have zero rows Before RREF: self
After RREF:
True
Question 4¶
Which of the following sets $S$ spans $\mathbb{R}^4$?
(i)¶
$S = \left\{\begin{pmatrix} 1 \\ 0 \\ 0 \\ 1 \end{pmatrix}, \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix}, \begin{pmatrix} 1 \\ 1 \\ 1 \\ 1 \end{pmatrix}, \begin{pmatrix} 1 \\ 1 \\ 1 \\ 0 \end{pmatrix}\right\}$.
S = Matrix.from_str("1 0 0 1; 0 1 0 0; 1 1 1 1; 1 1 1 0").T
S
S.is_same_subspace(verbosity=2)
Check rref(self) does not have zero rows Before RREF: self
After RREF:
True
(ii)¶
$S = \left\{\begin{pmatrix} 1 \\ 2 \\ 1 \\ 0 \end{pmatrix}, \begin{pmatrix} 1 \\ 1 \\ -1 \\ 0 \end{pmatrix}, \begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \end{pmatrix}\right\}$
S = Matrix.from_str("1 2 1 0; 1 1 -1 0; 0 0 0 1").T
S
S.is_same_subspace(verbosity=2)
Check rref(self) does not have zero rows Before RREF: self
After RREF:
False
(iii)¶
$S = \left\{\begin{pmatrix} 6 \\ 4 \\ -2 \\ 4 \end{pmatrix}, \begin{pmatrix} 2 \\ 0 \\ 0 \\ 1 \end{pmatrix}, \begin{pmatrix} 3 \\ 2 \\ -1 \\ 2 \end{pmatrix}, \begin{pmatrix} 5 \\ 6 \\ -3 \\ 2 \end{pmatrix}, \begin{pmatrix} 0 \\ 4 \\ -2 \\ -1 \end{pmatrix}\right\}$.
S = Matrix.from_str("6 4 -2 4; 2 0 0 1; 3 2 -1 2; 5 6 -3 2; 0 4 -2 -1").T
S
S.is_same_subspace(verbosity=2)
Check rref(self) does not have zero rows Before RREF: self
After RREF:
False
(iv)¶
$S = \left\{\begin{pmatrix} 1 \\ 1 \\ 0 \\ 0 \end{pmatrix}, \begin{pmatrix} 1 \\ 2 \\ -1 \\ 1 \end{pmatrix}, \begin{pmatrix} 0 \\ 0 \\ 1 \\ 1 \end{pmatrix}, \begin{pmatrix} 2 \\ 1 \\ 2 \\ 1 \end{pmatrix}, \begin{pmatrix} 1 \\ 2 \\ 3 \\ 4 \end{pmatrix}\right\}$.
S = Matrix.from_str("1 1 0 0; 1 2 -1 1; 0 0 1 1; 2 1 2 1; 1 2 3 4").T
S
S.is_same_subspace(verbosity=2)
Check rref(self) does not have zero rows Before RREF: self
After RREF:
True
Question 5¶
Determine whether $\text{span}\{u_1, u_2, u_3\} \subseteq \text{span}\{v_1, v_2\}$ and/or $\text{span}\{v_1, v_2\} \subseteq \text{span}\{u_1, u_2, u_3\}$ if
(a)¶
$u_1 = \begin{pmatrix} 2 \\ -2 \\ 0 \end{pmatrix}$, $u_2 = \begin{pmatrix} -1 \\ 1 \\ -1 \end{pmatrix}$, $u_3 = \begin{pmatrix} 0 \\ 0 \\ 9 \end{pmatrix}$, $v_1 = \begin{pmatrix} 1 \\ -1 \\ -5 \end{pmatrix}$, $v_2 = \begin{pmatrix} 0 \\ 1 \\ 1 \end{pmatrix}$.
U = Matrix.from_str("2 -2 0; -1 1 -1; 0 0 9").T
V = Matrix.from_str("1 -1 -5; 0 1 1").T
U, V
U.is_same_subspace(V, verbosity=2)
Check if span(self) is subspace of span(other), and vice versa. Check if span(self) is subspace of span(other) Before RREF: [other | self]
After RREF:
Span(self) is not a subspace of span(other).
False
(b)¶
$u_1 = \begin{pmatrix} 1 \\ 6 \\ 4 \end{pmatrix}$, $u_2 = \begin{pmatrix} 2 \\ 4 \\ -1 \end{pmatrix}$, $u_3 = \begin{pmatrix} -1 \\ 2 \\ 5 \end{pmatrix}$, $v_1 = \begin{pmatrix} 1 \\ -2 \\ -5 \end{pmatrix}$, $v_2 = \begin{pmatrix} 0 \\ 8 \\ 9 \end{pmatrix}$.
U = Matrix.from_str("1 6 4; 2 4 -1; -1 2 5").T
V = Matrix.from_str("1 -2 -5; 0 8 9").T
U, V
U.is_same_subspace(V, verbosity=2)
Check if span(self) is subspace of span(other), and vice versa. Check if span(self) is subspace of span(other) Before RREF: [other | self]
After RREF:
Span(self) is a subspace of span(other). Check if span(self) is subspace of span(other) Before RREF: [other | self]
After RREF:
Span(self) is a subspace of span(other).
True