import numpy as np
9.4. Linear Transformations#
9.4.1. Subspaces of #
This section focuses on subsets of
Column space and null space#
A subspace of
. and .
Note that we can choose
Example 1
Let
Solution:
Recall that the span of a set of vectors is the set of all possible linear combinations of those vectors. Let
Both of these vectors are in
In general, if
Any
The column space of
, denoted by , is the span of the columns of :
where
The null space
, denoted by , is the solution set of the homogeneous equation :
By Theorem 2 in subsection 1.2,
Example 2
Let
Find
and .Is
?Is
?
Solution:
.
To find
M = np.array([[1, -1, 0], [2, 1, 0], [-1, 3, 0]])
M
array([[ 1, -1, 0],
[ 2, 1, 0],
[-1, 3, 0]])
# Swap two rows
def swap(matrix, row1, row2):
copy_matrix=np.copy(matrix).astype('float64')
copy_matrix[row1,:] = matrix[row2,:]
copy_matrix[row2,:] = matrix[row1,:]
return copy_matrix
# Multiple all entries in a row by a nonzero number
def scale(matrix, row, scalar):
copy_matrix=np.copy(matrix).astype('float64')
copy_matrix[row,:] = scalar*matrix[row,:]
return copy_matrix
# Replacing a row by the sum of itself and a multiple of another
def replace(matrix, row1, row2, scalar):
copy_matrix=np.copy(matrix).astype('float64')
copy_matrix[row1] = matrix[row1]+ scalar * matrix[row2]
return copy_matrix
M1 = replace(M, 1, 0, -2)
M1
array([[ 1., -1., 0.],
[ 0., 3., 0.],
[-1., 3., 0.]])
M2 = replace(M1, 2, 0, 1)
M2
array([[ 1., -1., 0.],
[ 0., 3., 0.],
[ 0., 2., 0.]])
M3 = scale(M2, 1, 1/3)
M3
array([[ 1., -1., 0.],
[ 0., 1., 0.],
[ 0., 2., 0.]])
M4 = replace(M3, 2, 1, -2)
M4
array([[ 1., -1., 0.],
[ 0., 1., 0.],
[ 0., 0., 0.]])
Therefore,
From the row-reduced form, we can see that all columns are pivots and there is no free variable. In other words, the only solution to the system is the trivial solution:
if and only if is a linear combination of the columns of . In other words, if and only if the equation has a solution. Let’s set up the augmented matrix and row-reduce it:
import numpy as np
M = np.array([[1, -1, 1], [2, 1, 2], [-1, 3, 1]])
M
array([[ 1, -1, 1],
[ 2, 1, 2],
[-1, 3, 1]])
M1 = replace(M, 1, 0, -2)
M1
array([[ 1., -1., 1.],
[ 0., 3., 0.],
[-1., 3., 1.]])
M2 = replace(M1, 2, 0, 1)
M2
array([[ 1., -1., 1.],
[ 0., 3., 0.],
[ 0., 2., 2.]])
M3 = scale(M2, 1, 1/3)
M3
array([[ 1., -1., 1.],
[ 0., 1., 0.],
[ 0., 2., 2.]])
M4 = replace(M3, 2, 1, -2)
M4
array([[ 1., -1., 1.],
[ 0., 1., 0.],
[ 0., 0., 2.]])
Clearly, the last two rows show that the system is inconsistent. Thus,
No,
is trivial. We can verify this directly:
A = np.array([[1, -1], [2, 1], [-1, 3]])
A
array([[ 1, -1],
[ 2, 1],
[-1, 3]])
u = np.array([[1],[1]])
u
array([[1],
[1]])
#computing Au
Au = A @ u
Au
array([[0],
[3],
[2]])
Thus,
Example 3
Suppose
Basis, Dimension, and Rank#
Let
According to the Invertible Matrix Theorem (Theorem 4 in section 2.1), the columns of an invertible
Example 4 (The Standard Basis)
Let
be the identity matrix. The columns of
form a basis for
The following cell computes the standard basis of
#the 4x4 identity matrix
I = np.eye(4)
print(' e1 = \n', np.array([I[0]]).T, '\n')
print(' e2 = \n', np.array([I[1]]).T, '\n')
print(' e3 = \n', np.array([I[2]]).T, '\n')
print(' e4 = \n', np.array([I[3]]).T, '\n')
e1 =
[[1.]
[0.]
[0.]
[0.]]
e2 =
[[0.]
[1.]
[0.]
[0.]]
e3 =
[[0.]
[0.]
[1.]
[0.]]
e4 =
[[0.]
[0.]
[0.]
[1.]]
A basis for col A
The column space of a matrix
Theorem 13
The pivot columns of a matrix
Example 5
Suppose
Find a basis for
.Find a basis for
Solution
We reduce
to its reduced row echelon form (RREF) to find its pivot columns:
A = np.array([[1,3,3,2,-9], [-2,-2,2,-8,2], [2,3,0,7,1], [3,4,-1,11,8]])
A
array([[ 1, 3, 3, 2, -9],
[-2, -2, 2, -8, 2],
[ 2, 3, 0, 7, 1],
[ 3, 4, -1, 11, 8]])
A1 = replace(A, 1, 0, 2)
A2 = replace(A1, 2, 0, -2)
A3 = replace(A2, 3, 0, -3)
A4 = scale(A3, 1, 1/4)
A5 = replace(A4, 2, 1, 3)
A6 = replace(A5, 3, 1, 5)
A7 = scale(A6, 2, 1/7)
A8 = replace(A7, 0, 1, -3)
A9 = replace(A8, 3, 2, -15)
A10 = replace(A9, 1, 2, 4)
A11 = replace(A10, 0, 2, -3)
A11
array([[ 1., 0., -3., 5., 0.],
[ 0., 1., 2., -1., 0.],
[ 0., 0., 0., 0., 1.],
[ 0., 0., 0., 0., 0.]])
We can see from the RREF of
It’s important to note that the columns of the RREF of
To find a basis for
, we solve in the usual manner. Let’s form the augmented matrix :
A0 = np.array([[1,3,3,2,-9,0], [-2,-2,2,-8,2,0], [2,3,0,7,1,0], [3,4,-1,11,8,0]])
A1 = replace(A0, 1, 0, 2)
A2 = replace(A1, 2, 0, -2)
A3 = replace(A2, 3, 0, -3)
A4 = scale(A3, 1, 1/4)
A5 = replace(A4, 2, 1, 3)
A6 = replace(A5, 3, 1, 5)
A7 = scale(A6, 2, 1/7)
A8 = replace(A7, 0, 1, -3)
A9 = replace(A8, 3, 2, -15)
A10 = replace(A9, 1, 2, 4)
A11 = replace(A10, 0, 2, -3)
A11
array([[ 1., 0., -3., 5., 0., 0.],
[ 0., 1., 2., -1., 0., 0.],
[ 0., 0., 0., 0., 1., 0.],
[ 0., 0., 0., 0., 0., 0.]])
From this, we can see that the general solution is:
It is also clear that
Note that a subspace
However, all bases have something in common:
Theorem 14
All bases of a subspace
The dimension of a subspace
Example 6
Show that
Solution:
We can use Example 6, where it was shown that the columns of the identity matrix
Since there are
Example 7
Find the rank of subspaces of
Solution:
In
The zero subspace
, which has zero dimension.Lines passing through the origin, which have one dimension: every line in
can be spanned by a vector.Planes passing through the origin, which have two dimensions: every plane in
can be spanned by two linearly independent vectors.The entire space
, which has three dimensions.
The next Theorem states that the sum of the dimensions of the column space and null space is equal to the number of columns in the matrix. Additionally, it provides a way to determine the dimensions of the column space and null space based on the number of pivot and non-pivot columns in the matrix, respectively.
Theorem 15 (Rank-Nullity Theorem)
If
the number of pivot columns of . the number of non-pivot columns of .
Example 8
Find the rank and dimension of
Solution
From the solution of Example 7, We know that the RREF of
A11
array([[ 1., 0., -3., 5., 0., 0.],
[ 0., 1., 2., -1., 0., 0.],
[ 0., 0., 0., 0., 1., 0.],
[ 0., 0., 0., 0., 0., 0.]])
Which has three pivot columns and two non-pivot columns. Therefore,
Exercises#
Exercises
Determine which one of the following sets are subspaces:
a.
b.
Let
Find the dimension of
Suppose
is a matrix, and has 3 pivot columns.a. Prove that
must have nontrivial solutions.b. Is there an example of
where ?Find an explicit example of a
matrix which has
9.4.2. Introduction to Linear Transformations#
This section introduces linear transformations (sometimes referred to as linear maps) and explores their relationship with linear systems. We discuss how the existence and uniqueness of solutions to linear systems can be reformulated in terms of linear transformations.
Motivation#
In many applications, the matrix equation arises in a way that is not directly connected to linear combinations of vectors. In fact, we think of an
In general any function with these properties is called a linear transformation. More precisely, a function
is a linear transformation if it satisfies the following conditions:
These two conditions lead to the following useful fact:
The last property can also be generalized to
This property states that
Example 1
Show that
is a linear transformation.
Solution:
T is linear as shown below:
Let’s write a Python function for
import numpy as np
def T(V):
W = np.zeros((3, 1)) # return the zero vector in R^3
W[0, 0] = 2 * V[1, 0] # change the first component to 2*x_2
W[2, 0] = 3 * V[0, 0] # change the third component to 3*x_1
return W
Now, let’s plug in some vectors:
# input vectors
V = np.array([[1], [1]])
U = np.array([[0], [0]])
#output vectors
W1 = T(V)
W2 = T(U)
print('T(V): \n \n', W1)
print(10*'*')
print('\n T(U): \n\n', W2)
T(V):
[[2.]
[0.]
[3.]]
**********
T(U):
[[0.]
[0.]
[0.]]
Example 2
Determine if
is a linear transformation.
Solution: T is not linear, since
Example 3
Let
Prove that the transformation
defined by
Solution:
The transformation
it doesn’t affect the first two components and replaces
# matrix A
A = np.array([[1,0,0],[0,1,0],[0,0,0]])
# vector U
U = np.array([[1,3,5]]).T
print('T maps \n\n', U,'\n\n to \n\n', A @ U)
T maps
[[1]
[3]
[5]]
to
[[1]
[3]
[0]]
Example 4
Let
Then, the transformation
defined by
For
# matrix A
A = np.array([[1,2],[0,1]])
# inpout data
e1 = np.array([1,0])
e2 = np.array([0,1])
#output
w1 = A @ e1
w2 = A @ e2
print('T maps \n\n', e1,'\n\n to \n\n', w1)
print(10*'*')
print('T maps \n\n', e2,'\n\n to \n\n', w2)
T maps
[1 0]
to
[1 0]
**********
T maps
[0 1]
to
[2 1]
Lets plot these vectors:
import matplotlib.pyplot as plt
ax = plt.axes()
ax.arrow(0, 0, 1, 0, head_width = 0.2,head_length = 0.2, fc ='b', ec ='b')
ax.arrow(0, 0, 1, 0, head_width = 0.2,head_length = 0.2, fc ='r', ec ='r')
ax.arrow(0, 0, 0, 1, head_width = 0.2,head_length = 0.2, fc ='b', ec ='b')
ax.arrow(0, 0, 2, 1, head_width = 0.2,head_length = 0.2, fc ='r', ec ='r')
ax.text(0.8,0 - 0.5,'$e1 = w1$')
ax.text(0,1.3,'$e2$')
ax.text(2.2,1.2,'$w2$')
ax.set_xticks(np.arange( -1, 5, step = 1))
ax.set_yticks(np.arange( -1, 5, step = 1))
ax.set_aspect('equal')
ax.set_xlabel("X")
ax.set_ylabel("Y")
plt.grid()
plt.show()

Observe that all points along the
Shearing a plane figure does not change its area. The shear transformation can also be generalized to three dimensions:
Let
Then, the transformation
defined by
The standard matrix representation of a linear transformation#
As we have seen previously, any
Theorem 16
Let
The matrix
Example 5
Find the standard matrix representation of the linear transformation in Example 1.
Solution:
We apply
Thus, the standard matrix representation
Let’s write Python code for this example and verify our solution:
def T(V):
W = np.zeros((3,1)) #returns the zero vector in R^3
W[0,0] = 2*V[1,0] #changes the first component to 2*x_1
W[2,0] = 3*V[0,0] #changes the third component to 3*x_2
return W
e1 = np.array([[1],[0]])
e2 = np.array([[0],[1]])
#the first column of A
c1 = T(e1)
#the second column of A
c2 = T(e2)
# formaing D
D = np.concatenate((c1,c2), axis =1)
D
array([[0., 2.],
[0., 0.],
[3., 0.]])
In Example 1, we saw that
v = np.array([[1],[1]])
D @ v
array([[2.],
[0.],
[3.]])
Example 6
Consider the linear transformation
Solution:
To find the standard matrix representation of
Therefore, the standard matrix of
import matplotlib.pyplot as plt
ax = plt.axes()
ax.arrow(0, 0, 1, 0, head_width = 0.2,head_length = 0.2, fc ='b', ec ='b')
ax.arrow(0, 0, 0, 1, head_width = 0.2,head_length = 0.2, fc ='r', ec ='r')
ax.text(1,0 - 0.5,'e1')
ax.text(0,1 + 0.5,'T(e1)')
ax.set_xticks(np.arange( -1, 5, step = 1))
ax.set_yticks(np.arange( -1, 5, step = 1))
ax.set_aspect('equal')
ax.set_xlabel("X")
ax.set_ylabel("Y")
plt.grid()
plt.show()

ax = plt.axes()
ax.arrow(0, 0, 0, 1, head_width = 0.2,head_length = 0.2, fc ='b', ec ='b')
ax.arrow(0, 0, 1, 0, head_width = 0.2,head_length = 0.2, fc ='r', ec ='r')
ax.text(0,1 + 0.5,'$e2$')
ax.text(1,0 - 0.5,'$T(e2)$')
ax.set_xticks(np.arange( -1, 5, step = 1))
ax.set_yticks(np.arange( -1, 5, step = 1))
ax.set_aspect('equal')
ax.set_xlabel("X")
ax.set_ylabel("Y")
plt.grid()
plt.show()

Exercises#
Exercises
Determine if each transformation is linear
a.
given by
b.
Find the standard matrix of
given by first reflect across the -axis and then rotate counterclockwise.Suppose
is a linear map and
Find