Skip to main content

Section 3.5 Sage Computations

In this section we explain how Sage can be used to explore linear transformations and deal with various concepts related to linear transformations that we have learned in this chapter.
Sage has a construction linear_transformation() to define a linear transformation. We can define a linear transformation in Sage using the following four different ways.
  1. linear_transformation(A, side='left') defines a linear transformation as a matrix transformation defined by the matrix \(A\text{.}\) Domain and the codomain and the base space are inferred by the dimension of the matrix and base ring (the ring from on matrix is defined). Side is the keyword that can be taken as ’left’ or ’right’, the default value is ’left’.
  2. linear_transformation(D, C, A, side='left') , this is same as before, however, here domain is taken as \(D\) and codomain is taken as \(C\text{.}\)
  3. linear_transformation(D, C, f), in this case \(f\) is the function that is defined on on a basis element of the domain and it produces the elements of the codomain. The linear tranformation is the unique linear transformation that is extended linearly on the domain \(D\text{.}\)
  4. linear_transformation(D, C, images), where ’images’ is a list or a touple of vectors of the codmain, whihc is equal to the size of the basis. Each element of th basis is mapped to the corresponding element of the image.

Example 3.5.1. Linear transformaation defined by a matrix..

Let us define a linear tarnsformatrion defined by a matrix \(A\) over a rational numbers.
Clearly, here \(T\) is the matrix tranformatrion defined from \(\Q^3\) to \(\Q^2\text{.}\) We can find, the domain, codmain, parent, images, kernel, that is null space etc using the dot methods. Let us explore some of them.
This returns a basis matrix of the image along with the dimension of the image space.
We can find image of any vector using the following Sage syntax.
If we take a vector \(w\) in the range space of \(T\text{,}\) we can find a representative of the \(T^{-1}(w)\text{.}\)
Note that the same linear transformation, we can also define as follows.

Problem 3.5.2.

Define a matrix \(A=\left(\begin{array}{rrr} -1 \amp 1 \amp 0 \\ 2 \amp 0 \amp -1 \\ 2 \amp -1 \amp 1 \\ 0 \amp 2 \amp 1 \end{array}\right)\) and define a linear transformation \(T:\Q^3\to \Q^4\) by \(T(x)=Ax\text{.}\) Now define two vectors \(w_1=(-3, -1, 0, -31/3)\) and \(w_2=(1, -1/2, -1, 11/6)\) . Check that \(w_1,w_2\) lie in the image space of \(T\text{.}\) Let \(v_1\in T^{-1}(w_1)\) and \(v_2\in T^{-1}(w_1)\text{.}\) Show that \(v_1, v_2\) are linearly independent in \(\Q^3\text{.}\) Can you generalize this result and prove the same?

Example 3.5.3.

Let us define a linear transformation \(T:\Q^4\to\Q^4\) given by
\begin{equation*} T(x_1,x_2,x_3,x_4)=\left(\begin{array}{r} -x_{1} + 2 \, x_{3} - x_{4} \\ x_{1} + 3 \, x_{2} + 7 \, x_{3} - 2 \, x_{4} \\ x_{1} - 3 \, x_{2} - 21 \, x_{3} + 4 \, x_{4} \\ x_{1} + 6 \, x_{2} + 16 \, x_{3} - 5 \, x_{4} \end{array}\right) \end{equation*}
and explore this in Sage.
Next we find the matrix of \(T\) with respect to a bases \(\beta\) on the domain and a basis \(\gamma\) on the codomain.
Now we define a subspace \(V_1\) of \(V\) with B as a basis and a subspace \(W_1\) of \(W\) with C as a basis. After that we rectrict T on to \(V_1\) on its domain and \(W_1\) on its codomain. We call this restriction as \(T_1\text{.}\) The matrix of \(T_1\) is the matrix of \(T\) with respect to \(\beta\) on domain and \(\gamma\) on codmain, that is \([T]_\beta^\gamma\text{.}\)
Note that the matrix \([T]_\beta^\gamma\) can also be obtained by defining a column matrix whose columns are \(w_1,w_2,w_3,w_4, T(v_1), T(v_2), T(v_3), T(v_4)\text{,}\) then applying RREF and extracting the last four columns.
The image of \(T\) can also be obtained by using RREF of the matrix whose rows are vectors \(T(u1),T(u2),T(u3),T(u4)\text{.}\)
Note that the first three rows of this is sage as what we get using T.image().
Reshufle the basis elements. Let us see what happens to the matrix of a linear transformation when we reshuffle the elemnts of a basis on domain and codomain. Let us find the matrix of the abobe linear transformation with resepect the basis \(\beta_1 =\{u_1,u_3,u_2,u_4\}\) of the domain and \(\gamma\) of the codomain. Here we have interchanged 2nd and 3rd basis elements of \(\beta\text{.}\) You may also explore with other interchanges.
Clearly in this case 2nd and 3rd columns of \([T]_\beta^\gamma\) are interchanged.
Clearly in this case 2nd and 3rd rows of \([T]_\beta^\gamma\) are interchanged.