Lab 4
Lab 4
linear transformation
Objectives:
Use python
Verify the rank-nullity theorem for the linear transformation T : R3 → R3 defined byT(x, y, z) = (x + 4y
+ 7z, 2x + 5y + 8z, 3x + 6y + 9z)
import numpy as np
rank=np.linalg.matrix_rank(A)
ns=null_space(A)
nullity=ns.shape [1]
else :
output:
Rank of the matrix 2
Null space of the matrix [[-0.40824829]
[ 0.81649658]
[-0.40824829]]
Null space of the matrix 1
Rank - nullity theorem holds.
import numpy as np
V=np.array([
[1 , 2 , 3],
[2 , 3 , 1],
[3 , 1 , 2]])
basis=np.linalg.matrix_rank(V)
dimension=V.shape[0]
print("Basis of the matrix ", basis)
print(" Dimension of the matrix ", dimension)
output:
Basis of the matrix 3
Dimension of the matrix 3
output:
'REF of given matrix : '
1 −1 1 1
0 −3 0 0
[ ]
0 0 2 0
0 0 0 0
1 −1 1 1
[0 −3 0 0]
0 0 2 0
4.Graphical representation of a transformation
4.1Horizontal stretch:
Represent the horizontal stretch transformation T : R2ßR2 geometrically
Find the image of vector (10, 0) when it is stretched horizontally by 2
units.
import numpy as np
import matplotlib . pyplot as plt
V=np.array([[10,0]])
origin=np.array([[0 , 0 , 0],[0 , 0 , 0]])
A=np.matrix([[2 , 0],[0 , 1]])
V1=np.matrix( V )
V2=A*np.transpose( V1 )
V2=np.array( V2 )
plt.quiver(*origin , V[:,0], V[:,1], color =['b'], scale =50)
plt.quiver(*origin , V2[0 ,:], V2[1 ,:], color =['r'], scale =50)
plt.show()
output:
Another example:
import numpy as np
coords=coords.transpose()
coords
x=coords[0 ,:]
y=coords [1 ,:]
A_coords=A@coords
x_LT1=A_coords [0 ,:]
y_LT1=A_coords [1 ,:]
fig,ax=plt.subplots()
ax.grid( True )
ax.set_aspect('equal')
output:
4.2 Reflection:
Represent the reflection transformation T : R2 → R2 geometrically. Find the image of vector (10, 0)
when it is reflected about y axis.
import numpy as np
V=np.array([[10 , 0]])
V1=np.matrix(V)
V2=A*np.transpose( V1 )
V2=np.array ( V2 )
plt.quiver (*origin , V2[0 ,:], V2[1 ,:], color =['r'], scale =50)
plt.show()
output:
Another example.
B=np.array([[-1 , 0],[0 , 1]])
B_coords=B@coords
x_LT2=B_coords[0 ,:]
y_LT2=B_coords[1 ,:]
fig,ax=plt.subplots()
ax.plot(x,y,'r', ls="--")
ax.grid( True )
ax.set_aspect('equal')
output:
4.3 Rotation:
Represent the rotation transformation T : R2 → R2 geometrically. Find the image of vector (10, 0)
when it is rotated by π/2 radians.
import numpy as np
V=np.array([[10 , 0]])
V1=np.matrix( V )
V2=A*np.transpose( V1 )
V2=np.array( V2 )
plt.show ()
output:
Another example
theta=pi/6
R_coords=R@coords
x_LT3=R_coords[0 ,:]
y_LT3=R_coords[1 ,:]
fig,ax=plt.subplots()
ax.plot(x ,y ,'ro')
ax.grid( True )
ax.set_aspect ('equal')
output:
Represent the Shear transformation T : R2 → R2 geometrically. Find the image of (2, 3) under shear
transformation.
import numpy as np
V=np.array([[2 , 3]])
origin=np.array([[0 , 0 , 0],[0 , 0 , 0]])
V1=np.matrix( V )
V2=A*np.transpose( V1 )
V2=np.array( V2 )
plt.quiver (*origin , V2[0 ,:], V2[1 ,:], color =['r'], scale =20)
plt.show ()
output:
Image of given vectors is: [[8]
[3]]
Another example.
S_coords=S@coords
x_LT4=S_coords [0 ,:]
y_LT4=S_coords [1 ,:]
fig , ax=plt.subplots()
ax.plot(x ,y ,'ro')
ax.grid( True )
ax.set_aspect('equal')
output:
4.5 Composition
Represent the composition of two 2D transformations. Find the image of vector (10, 0) when it is
rotated by π/2 radians then stretched horizontally 2 units.
import numpy as np
V=np.array([[2 , 3]])
V2=A*np.transpose ( V1 )
V3=B*V2
V2=np.array( V2 )
V3=np.array( V3 )
plt.quiver (*origin , V2[0 ,:], V2[1 ,:], color =['r'], scale =20)
plt.quiver (*origin , V3[0 ,:], V3[1 ,:], color =['g'], scale =20)
plt.show()
output: Image of given vectors is: [[-6]
[ 2]]
Another example.
C_coords=C@coords
x_LT5=C_coords[0 ,:]
y_LT5=C_coords[1 ,:]
fig , ax=plt . subplots ()
ax.grid ( True )
ax.set_aspect ('equal')
output: