Tutorial 11 (AY24/25 Sem 1)¶
# Required imports
import sympy as sym
from ma1522 import Matrix
Question 1¶
For each of the following:
(i) Determine whether the following are linear transformations.
(ii) Write down the standard matrix for each of the linear transformations.
(iii) Find a basis for the range for each of the linear transformations.
(iv) Find a basis for the kernel for each of the linear transformations.
(a)¶
$T_1 : \mathbb{R}^2 \to \mathbb{R}^2$ such that $T_1\begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} x + y \\ y - x \end{pmatrix}$ for $\begin{pmatrix} x \\ y \end{pmatrix} \in \mathbb{R}^2$.
in_vec = Matrix.from_str("x; y")
out_vec = Matrix.from_str("x+y; y-x")
in_vec, out_vec
mat = in_vec.standard_matrix(out_vec, matrices=1)
mat # Double brackets indicates its a list of 1 matrix, i.e. unique solution
mat[0].columnspace()
mat[0].nullspace()
(b)¶
$T_2 : \mathbb{R}^2 \to \mathbb{R}^2$ such that $T_2\begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 2^x \\ 0 \end{pmatrix}$ for $\begin{pmatrix} x \\ y \end{pmatrix} \in \mathbb{R}^2$.
in_vec = Matrix.from_str("x; y")
out_vec = Matrix.from_str("2**x; 0")
in_vec, out_vec
try:
in_vec.standard_matrix(out_vec, matrices=1)
except ValueError as e:
print(f"Error: {e}")
Error: No solution found for the standard matrix. This may indicate that the transformation is not linear.
(c)¶
$T_3 : \mathbb{R}^2 \to \mathbb{R}^3$ such that $T_3\begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} x + y \\ 0 \\ 0 \end{pmatrix}$ for $\begin{pmatrix} x \\ y \end{pmatrix} \in \mathbb{R}^2$.
in_vec = Matrix.from_str("x; y")
out_vec = Matrix.from_str("x+y; 0; 0")
in_vec, out_vec
mat = in_vec.standard_matrix(out_vec, matrices=1)
mat
mat[0].columnspace()
mat[0].nullspace()
(d)¶
$T_4 : \mathbb{R}^3 \to \mathbb{R}^3$ such that $T_4\begin{pmatrix} x \\ y \\ z \end{pmatrix} = \begin{pmatrix} 1 \\ y - x \\ y - z \end{pmatrix}$ for $\begin{pmatrix} x \ y \ z \end{pmatrix} \in \mathbb{R}^3$.
in_vec = Matrix.from_str("x; y; z")
out_vec = Matrix.from_str("1; y-x; y-z")
in_vec, out_vec
try:
mat = in_vec.standard_matrix(out_vec, matrices=1)
except ValueError as e:
print(f"Error: {e}")
Error: No solution found for the standard matrix. This may indicate that the transformation is not linear.
(e)¶
$T_5 : \mathbb{R}^5 \to \mathbb{R}$ such that $T_5\begin{pmatrix} x_1 \\ \vdots \\ x_5 \end{pmatrix} = x_3 + 2x_4 - x_5$ for $\begin{pmatrix} x_1 \\ \vdots \\ x_5 \end{pmatrix} \in \mathbb{R}^5$.
in_vec = Matrix.create_unk_matrix(5, 1, "x", is_real=True)
out_vec = Matrix.from_str("x3 + 2*x4 - x5", col_sep="?", is_real=True)
in_vec, out_vec
in_vec.standard_matrix(out_vec, matrices=1)
mat[0].columnspace()
mat[0].nullspace()
(f)¶
$T_6 : \mathbb{R}^n \to \mathbb{R}$ such that $T_6(\mathbf{x}) = \mathbf{x} \cdot \mathbf{x}$ for $\mathbf{x} \in \mathbb{R}^n$.
x = Matrix.create_unk_matrix(3, 1) # set n=3
x, x.dot(x)
# Wrap `x.dot(x)` in a matrix so that it can be
# used with `standard_matrix`
try:
mat = x.standard_matrix(Matrix([x.dot(x)]), matrices=1)
except ValueError as e:
print(f"Error: {e}")
Error: No solution found for the standard matrix. This may indicate that the transformation is not linear.
Question 2¶
Let $F : \mathbb{R}^3 \to \mathbb{R}^3$ and $G : \mathbb{R}^3 \to \mathbb{R}^3$ be linear transformations such that
$$F\left( \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} \right) = \begin{pmatrix} x_1 - 2x_2 \\ x_1 + x_2 - 3x_3 \\ 5x_2 - x_3 \end{pmatrix} \quad \text{and} \quad G\left( \begin{pmatrix} x_1 \\ x_2 \\ x_3 \end{pmatrix} \right) = \begin{pmatrix} x_3 - x_1 \\ x_2 + 5x_1 \\ x_1 + x_2 + x_3 \end{pmatrix}$$
and let $\mathbf{A}_F$ and $\mathbf{B}_G$ be the standard matrix of $F$ and $G$, respectively.
(a)¶
Find $\mathbf{A}_F$ and $\mathbf{B}_G$.
F_in = Matrix.from_str("x1; x2; x3")
F_out = Matrix.from_str("x1 - 2*x2; x1 + x2 - 3*x3; 5*x2 - x3", col_sep="?")
F_in, F_out
A_F = F_in.standard_matrix(F_out, matrices=1)[0]
A_F
G_in = Matrix.from_str("x1; x2; x3")
G_out = Matrix.from_str("x3 - x1; x2 + 5*x1; x1 + x2 + x3", col_sep="?")
G_in, G_out
B_G = G_in.standard_matrix(G_out, matrices=1)[0]
B_G
(c)¶
Write down the formula for $F(G(\mathbf{x}))$ and find its standard matrix.
# Composition of function is the composition of their standard matrices
A_F @ B_G
(d)¶
Find a linear transformation $H : \mathbb{R}^3 \to \mathbb{R}^3$ such that $H(G(\mathbf{x})) = \mathbf{x}$, for all $\mathbf{x} \in \mathbb{R}^3$.
H = B_G.inverse(verbosity=2)
H
Left inverse found! Right inverse found! Before RREF: [self | eye]
After RREF:
Question 3¶
For each of the following linear transformations, (i) determine whether there is enough information for us to find the formula of $T$; and (ii) find the formula and the standard matrix for $T$ if possible.
(a)¶
$T : \mathbb{R}^3 \to \mathbb{R}^4$ such that $$T\left( \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix} \right) = \begin{pmatrix} 1 \\ 3 \\ 0 \\ 1 \end{pmatrix}, \quad T\left( \begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix} \right) = \begin{pmatrix} 2 \\ 2 \\ -1 \\ 4 \end{pmatrix}, \quad T\left( \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix} \right) = \begin{pmatrix} 0 \\ 4 \\ 1 \\ 6 \end{pmatrix}$$
T_in = Matrix.eye(3)
T_out = Matrix.from_str("1 3 0 1; 2 2 -1 4; 0 4 1 6").T
T_in, T_out
mat = T_in.standard_matrix(T_out, matrices=1)
mat
(b)¶
$T : \mathbb{R}^2 \to \mathbb{R}^2$ such that $$T\left( \begin{pmatrix} 1 \\ -1 \end{pmatrix} \right) = \begin{pmatrix} 2 \\ 0 \end{pmatrix}, \quad T\left( \begin{pmatrix} 1 \\ 1 \end{pmatrix} \right) = \begin{pmatrix} 0 \\ 2 \end{pmatrix}, \quad T\left( \begin{pmatrix} 2 \\ 0 \end{pmatrix} \right) = \begin{pmatrix} 2 \\ 2 \end{pmatrix}$$
T_in = Matrix.from_str("1 -1; 1 1; 2 0").T
T_out = Matrix.from_str("2 0; 0 2; 2 2").T
T_in, T_out
mat = T_in.standard_matrix(T_out, matrices=1)
mat
(c)¶
$T : \mathbb{R}^3 \to \mathbb{R}$ such that $$T\left( \begin{pmatrix} 1 \\ -1 \\ 0 \end{pmatrix} \right) = -1, \quad T\left( \begin{pmatrix} 0 \\ 1 \\ -1 \end{pmatrix} \right) = 1, \quad T\left( \begin{pmatrix} -1 \\ 0 \\ 1 \end{pmatrix} \right) = 0$$
T_in = Matrix.from_str("1 -1 0; 0 1 -1; -1 0 1").T
T_out = Matrix.from_str("-1 1 0")
T_in, T_out
mat = T_in.standard_matrix(T_out, matrices=1)
mat # free parameters in the solution means its not unique