0% found this document useful (0 votes)
3 views4 pages

MATH Lab 7 (Programs-Basis, Dimension and LT)

The document outlines various computational tasks related to vector spaces, including the verification of the rank-nullity theorem, finding the dimension of a vector space, and graphical representations of linear transformations such as horizontal stretching, reflection, rotation, and shear transformation. Each section includes Python code using NumPy and Matplotlib to perform calculations and visualize the transformations. The outputs of the computations are also mentioned, indicating the results of the operations performed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

MATH Lab 7 (Programs-Basis, Dimension and LT)

The document outlines various computational tasks related to vector spaces, including the verification of the rank-nullity theorem, finding the dimension of a vector space, and graphical representations of linear transformations such as horizontal stretching, reflection, rotation, and shear transformation. Each section includes Python code using NumPy and Matplotlib to perform calculations and visualize the transformations. The outputs of the computations are also mentioned, indicating the results of the operations performed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 7 Programs

Computation of basis and dimension for a vector space


and graphical representation of linear transformation.

2a. Rank-Nullity theorem:

Verify the rank-nullity theorem for the linear transformation 𝑇: 𝑅3 → 𝑅3 defined


by 𝑇(𝑥, 𝑦, 𝑧) = (𝑥 + 4𝑦 + 7𝑧, 2𝑥 + 5𝑦 + 8𝑧, 3𝑥 + 6𝑦 + 9𝑧).

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:

2b. Dimension of a Vector Space


Find the dimension of subspace spanned by the vectors
(1, 2, 3), (2, 3, 1) and (3, 1, 2).

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.

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:

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

Find the image of vector (10,0) when it is rotated by 𝜋/2 radians.


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 ([[0 ,-1],[1 , 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 f. Shear Transformation

Find the image of vector (2,3) under 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:

You might also like