MATH Lab 7 (Programs-Basis, Dimension and LT)
MATH Lab 7 (Programs-Basis, Dimension and LT)
import numpy as np
from scipy . linalg import null_space
# Define a linear transformation interms of matrix
A = np . array ([[1 , 2 , 3], [4 , 5 , 6], [7 , 8 , 9]])
# Find the rank of the matrix A
rank = np . linalg . matrix_rank ( A )
print (" Rank of the matrix ", rank )
# Find the null space of the matrix A
ns = null_space ( A )
print (" Null space of the matrix ", ns )
# Find the dimension of the null space
nullity = ns . shape [1]
print (" Null space of the matrix ", nullity )
# Verify the rank - nullity theorem
if rank + nullity == A . shape [1]:
print ("Rank - nullity theorem holds")
else :
print ("Rank - nullity theorem does not hold ")
OUTPUT:
import numpy as np
# Define the vector space V
V = np . array ([[1 , 2 , 3],[2 , 3 , 1],[3 , 1 , 2]])
# Find the dimension and basis of V
basis = np . linalg . matrix_rank ( V )
dimension = V . shape [0]
print (" Basis of the matrix ", basis )
print (" Dimension of the matrix ", dimension )
OUTPUT:
2 c. Horizontal stretch.
2 d. Reflection
Find the image of vector (10,0) when it is reflected about y-axis.
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 ([[-1 , 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:
2 e. Rotation
2 f. Shear Transformation
import numpy as np
import matplotlib . pyplot as plt
V = np . array ([[2 , 3]])
origin = np . array ([[0 , 0 , 0],[0 , 0 , 0]])
A=np . matrix ([[1 , 2],[0 , 1]])
V1=np . matrix ( V )
V2=A*np . transpose ( V1 )
V2=np . array ( V2 )
print (" Image of given vectors is:", V2 )
plt . quiver (*origin , V[:,0], V[:,1], color =['b'], scale =20 )
plt . quiver (*origin , V2[0 ,:], V2[1 ,:], color =['r'], scale =20 )
plt . show ()
OUTPUT: