import numpy as np

9.4. Linear Transformations#

9.4.1. Subspaces of Rn#

This section focuses on subsets of Rn that preserve Rn’s linear structure. We will see that any matrix m×n matrix A admits two important subspaces that contain useful information about the solution set of Ax=b for some bRm

Column space and null space#

A subspace of Rn is a subset HRn that is closed under addition and scalar multiplication in the following sense:

  1. u+vHu,vH.

  2. ruHuH and rR.

Note that we can choose c=0, which implies 0 is an element of any subspace. The smallest subspaces of Rn is H={0} and the largest possible subspace of Rn is itself. Other subspaces of Rn are lines, planes, and their n-dimensional counterparts (n3) that pass through the origin.

Example 1

Let u,vR2. Show that H:=span(u,v) is a subspace of R2.

Solution:

Recall that the span of a set of vectors is the set of all possible linear combinations of those vectors. Let x,yspan(u,v) and rR. There exist c1,c2,d1,d2R such that x=c1u+c2v and y=d1u+d2v. We have:

x+y=(c1+d1) u+(c2+d2) vandrx=(rc1) u+(rc2) v

Both of these vectors are in H.

In general, if u1,u2,,upRn, then the span of of u1,u2,,up, is a subspace HRn, and we say H is spanned (or generated) by u1,u2,,up.

Any m×n matrix A is associated with important subspaces:

  1. The column space of A, denoted by col(A), is the span of the columns of A:

col(A)=span({a1,a2,,an})

where vis are the columns of A for i=1,2,,n. By definition, col(A) is a subspace of Rm.

  1. The null space A, denoted by null(A), is the solution set of the homogeneous equation Ax=0:

null(A)={x: Ax=0}

By Theorem 2 in subsection 1.2, null(A) is a subspace of Rn.

Example 2

Let A=[112113].

  1. Find col(A) and null(A).

  2. Is b=[123]col(A)?

  3. Is u=[11]null(A)?

Solution:

  1. col(A)=span{ [121],[113] }.

To find null(A), we solve the homogeneous equation Ax=0. Let’s set up the augmented matrix [A | 0] and row-reduce it:

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,

[11|021|013|0][11|001|000|0].

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: null(A)=0

  1. bcol(A) if and only if b is a linear combination of the columns of A. In other words, if and only if the equation Ax=b has a solution. Let’s set up the augmented matrix [A | b] 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, b is not in col(A).

  1. No, null(A) is trivial. We can verify this directly:

unull(A) if and only if Au=0:

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, u is not in null(A).

Example 3

Suppose A is an invertible n×n matrix. Then, by the Invertible Matrix Theorem (Theorem 4 in section 2.1), we have the following:

  1. col(A)=Rn

  2. null(A)={0}

Basis, Dimension, and Rank#

Let HRn be a subspace. A basis for H is a linearly independent set in H that spans H.

According to the Invertible Matrix Theorem (Theorem 4 in section 2.1), the columns of an invertible n×n matrix form a linearly independent set that spans Rn. Thus, the column space of any invertible matrix is a basis for Rn. It’s important to note that bases are not unique.

Example 4 (The Standard Basis)

Let

In=[e1e2en]

be the identity matrix. The columns of In, denoted by

e1,e2,,en,

form a basis for Rn, which is called the standard basis of Rn. For instance, the standard basis elements for R3 are

e1=[100],e2= [010], e3=[001]

The following cell computes the standard basis of R4

#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 A is generated by the set of all columns of A. If A is invertible, by the invertible matrix theorem, the columns are all pivot columns and form a linearly independent set and therefore, a basis for col A. In general, we have:

Theorem 13

The pivot columns of a matrix A form a basis for col(A).

Example 5

Suppose

A=[133292228223071341118].
  1. Find a basis for col(A).

  2. Find a basis for null(A).

Solution

  1. We reduce A 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 A that A has 3 pivot columns, which are the first two columns and the last column. Therefore, a basis for col(A) is the set consisting of the first two columns and the last column of A:

{[1223],[3234],[9218]}

It’s important to note that the columns of the RREF of A are not necessarily in col(A), and we cannot use them to form a basis for col(A).

  1. To find a basis for null(A), we solve Ax=0 in the usual manner. Let’s form the augmented matrix [A | 0]:

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:

[x1x2x3x4x5]=[3x35x42x3+x4x3x40]=x3[32100]+x4[51010]=span( [32100],[51010] )

It is also clear that [32100] and [51010] are linearly independent. So they form a basis for null(A).

Note that a subspace H can have different bases. For example, the following sets are both bases for R2:

B={[10],[01]}andG={[12],[21]}

However, all bases have something in common:

Theorem 14

All bases of a subspace H in Rn have the same number of vectors.

The dimension of a subspace H, denoted as dim(H), is the number of vectors in any of its bases. Furthermore, we define dim({0}) to be 0. The dimension of the column space of a matrix A, denoted as rank(A), is referred to as the rank of A.

Example 6

Show that dim(Rn)=n.

Solution:

We can use Example 6, where it was shown that the columns of the identity matrix In, denoted as {e1,,en}, form a basis for Rn.

Since there are n columns in the identity matrix In, the dimension of Rn is equal to n. Hence, dim(Rn)=n.

Example 7

Find the rank of subspaces of R3.

Solution:

In R3, we have the following subspaces:

  1. The zero subspace {0}, which has zero dimension.

  2. Lines passing through the origin, which have one dimension: every line in R3 can be spanned by a vector.

  3. Planes passing through the origin, which have two dimensions: every plane in R3 can be spanned by two linearly independent vectors.

  4. The entire space R3, 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 A be an m×n matrix, then dim(col(A))+dim(null(A))=n. Moreover,

  1. dim(col(A))= the number of pivot columns of A.

  2. dim(null(A))= the number of non-pivot columns of A.

Example 8

Find the rank and dimension of null(A), where A=[133292228223071341118]

Solution

From the solution of Example 7, We know that the RREF of A is

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, rank(A)=3 and dim(null(A))=2

Exercises#

Exercises

  1. Determine which one of the following sets are subspaces:

    a.

    H={ [xyz]R3 with x0,}.

    b.

    H={ [x12x]R3}.
  2. Let

A=[129222230].

Find the dimension of col(A) and null(A) .

  1. Suppose A is a 5×5 matrix, and A has 3 pivot columns.

    a. Prove that Ax=0 must have nontrivial solutions.

    b. Is there an example of A where col(A)=null(A) ?

  2. Find an explicit example of a 4×4 matrix A which has colA=null(A)

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 m×n matrix A as a function that transforms xRm to AxRn. With this perspective, finding the solution set of a linear system Ax=b is the same as finding the set of all x that A transforms into b. Theorem 1 in the previous section states that:

  1. A(u+v)=Au+Av

  2. A(cu)=cAu

In general any function with these properties is called a linear transformation. More precisely, a function

T:RmRn

is a linear transformation if it satisfies the following conditions:

T(u+v)=T(u)+T(v)u,vRm
T(cu)=cT(u)uRmandcR

These two conditions lead to the following useful fact:

T:RmRn is a linear transformation if and only if

  1. T(0)=0

  2. T(cu+dv)=cT(u)+dT(v)u,vRmandcR

The last property can also be generalized to n vectors:

T(c1u1+c2u2++cpup)=c1T(u1)+c2T(u2)++cpT(up)where1ip

This property states that T preserves linear combinations of vectors.

Example 1

Show that

T:R2R3 given by

T([x1x2])=[2x203x1].

is a linear transformation.

Solution:

T is linear as shown below:

T([x1x2]+[y1y2])=T([x1+y1x2+y2])=[2(x2+y2)03(x1+y1)]=[2x2+2y203x1+3x2].
T([x1x2])+T([y1y2])=[2x203x1]+[2y203y1]=[2x2+2y203x1+3x2].
T(c[x1x2])=T([cx1cx2])=[2cx203cx1].
cT([x1x2])=c[2x203x1]=[c2x20c3x1].

Let’s write a Python function for T:

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 T:R2R3 given by

T([x1x2])=[2x213x1].

is a linear transformation.

Solution: T is not linear, since

T([00])=[010][000]

Example 3

Let

A=[100010000].

Prove that the transformation

T:R3R2

defined by T(x)=Ax is a linear transformation. T is called the projection onto the xy-plane.

Solution:

The transformation T is defined by a matrix multiplication. According to Theorem 1 in the previous section, the matrix product satisfies the linearity property. T is called a projection because when applied to

u=[xyz],

it doesn’t affect the first two components and replaces z with zero. Let’s verify this by evaluating it for

u=[135]:
# 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

A=[1λ01].

Then, the transformation

T:R2R2

defined by T(x)=Ax is a linear transformation and is called a shear transformation.

For λ=2, we have:

# 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()
../../_images/db9ca14657d0d4c998023d7d57f4ae9cbaf5c0b97e4fbd6a2281a9bfd1c6c503.png

Observe that all points along the y-axis remain fixed while other points are shifted parallel to the y-axis by a distance proportional to their perpendicular distance from the x-axis; more specifically,

T([xy])=[x+2yy].

Shearing a plane figure does not change its area. The shear transformation can also be generalized to three dimensions:

Let

A=[10λ010001].

Then, the transformation

T:R3R3

defined by T(x)=Ax is a shear transformation.

The standard matrix representation of a linear transformation#

As we have seen previously, any m×n matrix A defines a linear transformation T:RnRm given by xAx. The converse of this statement is also true, as stated in the following theorem:

Theorem 16

Let T:RnRm be a linear transformation. There exists a unique m×n matrix A such that T(x)=Ax for all xRn. In fact, the ith column of matrix A is given by T(ei), where eiRn represents the ith column of the identity matrix In.

The matrix A is called the standard matrix representation of T. The name is motivated by the fact that we are using the standard basis of Rn, eis, to construct A.

Example 5

Find the standard matrix representation of the linear transformation in Example 1.

Solution:

We apply T to the standard basis vectors e1=[10] and e2=[01] to obtain the columns of the matrix representation D of T:

T(e1)=[2(0)03(1)]=[003]

T(e2)=[2(1)03(0)]=[200]

Thus, the standard matrix representation D of T is:

D=[020030]

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 T([11])=[203]. Let’s verify that D[11]=[203]:

v = np.array([[1],[1]])

D @ v 
array([[2.],
       [0.],
       [3.]])

Example 6

Consider the linear transformation T:R2R2 defined as follows: T(x) first reflects x across the x-axis and then rotates it 90 counterclockwise. Find the standard matrix representation of T.

Solution:

To find the standard matrix representation of T we apply T to the standard basis vectors of R2:

T reflects [10] to itself and then rotates it to [01].

T reflects [01] to [01] and then rotates it to [10].

Therefore, the standard matrix of T is

[0110].
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()
../../_images/192eeb8b15d2f2a08f882c1dc92d8bf387351fe542b99d182c82e532278d728f.png
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()
../../_images/c60fe040446537793209da92ff57dda059619a28f7700be8c8be78e7dd0d9398.png

Exercises#

Exercises

  1. Determine if each transformation is linear

    a. T:R2R2 given by

T([x1x2])=[x2x1].

b. T:R2R2 given by

T([x1x2])=[(x1)20].
  1. Find the standard matrix of T:R2R2 given by T(x)= first reflect x across the x-axis and then rotate 45 counterclockwise.

  2. Suppose T:R2R3 is a linear map and

T([10])=[123]andT([01])=[011].

Find T[23].