0% found this document useful (0 votes)
4 views12 pages

Lab Manual Engineering Maths 2 VTU-10

The document outlines a lab exercise focused on the computation of basis and dimension for vector spaces, as well as graphical representations of linear transformations. It includes objectives such as verifying the Rank-Nullity theorem, computing dimensions, and visualizing transformations like horizontal stretch, reflection, rotation, and shear. Code snippets in Python demonstrate how to implement these concepts using libraries like NumPy and Matplotlib.

Uploaded by

ramyakrishna4675
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Lab Manual Engineering Maths 2 VTU-10

The document outlines a lab exercise focused on the computation of basis and dimension for vector spaces, as well as graphical representations of linear transformations. It includes objectives such as verifying the Rank-Nullity theorem, computing dimensions, and visualizing transformations like horizontal stretch, reflection, rotation, and shear. Code snippets in Python demonstrate how to implement these concepts using libraries like NumPy and Matplotlib.

Uploaded by

ramyakrishna4675
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 12
LAB 4: Computation of basis and dimension for a vec- tor space and graphical representation of linear trans- formation 4.1 Objectives: Use python 1. to verify the Rank nullity theorem of given linear transformation 2. to compute the dimension of vector space 3, to represent linear transformations graphically 4.2. Rank Nullity Theorem Verify the rank-mnllity theorem for the linear transformation T : R° —+ R® defined by T(x, y,2) = (w+ dy + Tz, 20 + Sy + 82, 3x + Gy + 92). import numpy ae ap from scipy.linalg import null_space # Define a linear transformation interms of matrix A= np.array([[1, 2, 31, [4, 5, 61, [7, 8, 911) # Find the rank of the matrix 4 rank = np. linalg.aatrix_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-aullity theorem if rank + nullity == A. shape [1] print (*Rank-nullity theorem holds.*) else print (*Rank-nullity theorem does not hold.") Rank of the matrix 2 Null space of the matrix [(~ [ 0.81649658) [-0.40824829]] Null space of the matrix 1 Rank-nullity theorem holds 40824829] 63 © scanned ith OREN Samer 4.3 Dimension of Vector Space Find the dimension of subspace spanned by the vectors (1, 2,3), (2.3,1) and (3, 1,2). import numpy as ap # Define the vector space V V = np.array([ Us 25 BIe 1B. 85 iis [3, 4, 211) # Find the dimension and basis of V basie = mp. linalg-aatrix_rank(V) dimension = V.shape [0] print ("Basis of the matrix",basis) print("Dimension of the aatrix",dimension) Basis of the matrix 3 Dimension of the matrix 3 Extract the linearly independent rows in given matrix : Basis of Row space from numpy import + import sympy as sp A=[(1,-1,1,1] ,(2,-5,2,2],(3,-3,5,3),[4,-4,4,411 ABearray (A) S=shape(A) aelen(A) for i in range(n) if ABLi,i]--0 ab= copy (AB) for k in range (iti.8(0)) if ablk,i]!=0 ab(i,:)=AB(k,:] ab ik, :J-ABLi, ©] AB= copy (ab) for j in range(i#1.n) Fact=AB(j,4]/AB(i, i] for k in range (i.n) ABL4,4]=ABCj,k]-Fact +ABL4 ,k] display ("REF of given matrix: ",sp.Matrix(AB)) temp = ((0, 0, 0,0)} result = [] for idx, row in enumerate(sap(tuple, AB)): Sf row not in temp result. append (idx) print("\n Basis are non-zero rows of A:") Gisplay (sp. Matrix (AB[result])) 4 © scanned ith OREN Samer "REF of given matrix: P-rid 0300 0 2. Oi o 0 00 Basis are non-zero rows of A: P-lad 0-300 0020 4.4 Graphical representation of a transformation 4.4.1 Horizontal stretch: Represent the horizontal stretch transformation T : R°8R? geometrically Find the image of vector (10.0) when it is stretched horizontally by 2 units import numpy as np import matplotlib.pyplot as pit V = np.array([(10,01]) origin = np.array([[0, 0, 0],(0, 0, 0]]) # origin point A-np.matrix(( (2,0) ,(0,1]]) Vienp.matrix(¥) V2-Aenp. transpose (V1) Vamp. array (V2) plt quiver (sorigin, V[:,0], V[:,1], color=('b'], scale=50) plt quiver (sorigin, V2(0,:], V2(1,.:], color-['r'], scale=50) plt. show 0 002 0.00 ew 0m Another example. from math import pi, sin, cos 65 © scanned ith OREN Samer import matplotlib.pyplot as plt import numpy as np coords = mp-array({[0,0],(0.5,0.81, (0.8.1.5) [0,1] ,(0,0]]) coords = coords .transpose () coords x = coords [0,:1 y = coords (1, :] A= np-array(((2,0],[0,1]1) A.coords = Agcoords xLLTL = A_coords [0,1 yuLT1 = A_coords[1,:] # Create the figure and axes objects fig, ax = plt.subplots() # Plot the points. x and y are original vectors, xLT1 and y_LT1 are images ax. plot (x,y, 'ro') ax. plot (x.LT1,y_LT1,*bo") # Connect the points by lines ax.plot (x,y, 'r*,1ls="--") ax. plot (x LT1,y.LT1,'b') # Edit some settings ax. axvline(x=0,color="k",1s=":") ax.axhline(y=0,color="k",1s=":") ax. grid (True) ax-axis([-2,2,-1,2]) ax. set_aspect (‘equal') ax.set_title ("Horizontal Stretch"); Horizontal Stretch 20 ‘30-15 0 -05 00 05 10 a5 20 66 © scanned ith OREN Samer 4.4.2 Reflection: Represent the reflection transformation T : R* + R? geometricall Find the image of vector (10,0) when it is reflected about y axis import numpy as np import matplotlib.pyplot as plt Vv = np.array([[10,0]1) origin = np.array({[0, 0, 01,(0, 0, 01]) # origin point A=np.matrix({{-1,0],[0,1]]) Vienp.matrix(¥) V2-Aenp. transpose (V1) v2=np. array (V2) plt.quiver(+origin, V[:,0], Vi:,1], color=('b'l, scale=50) plt.quiver(+origin, V2(0,:], V2i1,:, color=('r'], scale=50) plt. show () 0.04 0.00 —_——— ~o02 “oor 00 ob) ~~ Another example. B= np-array([(-1,0], (0,111) B.coords = B@coords x.LT2 = B.coords(0,:] y-LT2 = B_coords[1,:] # Create the figure and axes objects fig, ax = plt.eubplote() # Plot the points. x and y are original vectors, x_LT1 and y_LTi are images ax.plot(x,y,'ro') ax.plot (x-LT2,y_LT2,*bo') # Connect the points by lines ax.plot (x,y, 'r!,18="--") ax.plot (x-LT2,y-LT2,"b') # Edit some settings ax.axvline(x=0,color="k",1s=":") 67 © scanned ith OREN Samer ax.axhline(y=0,color="k",1s=":") ax. grid (True) ax-axis((-2,2,-1,21) ax.set_aspect (‘equal') ax.set_title ("Reflection"); Reflection -20 -15 -10 -05 00 OF 10 15 20 4.4.3 Rotation: Represent the rotation transformation T’: R? + R? geometrically. Find the image of vector (10,0) when it is rotated by /2 radians. import numpy as mp import matplotlib.pyplot as pit V = np.array({[10,0]]) origin - mp.array(([0, 0, 0],(0, 0, 0]]) # origin point Aenp.matrix(((0,-1),(1,1])) Vienp.matrix(¥) V2-Aenp. transpose (V1) V2=np. array (V2) plt.quiver(+origin, V[:,0], Vi:,1], color=['b'], scale=60) plt.quiver(+origin, V2(0,:}, V2(1,:], celer=['r'], scale=50) pt. show 68 © scanned ith OREN Samer 008 “oe 9090090 _—Another example. theta = pi/6 R = np.array({[cos(theta) ,~sin(theta)],[sin(theta), cos (theta)]]) Rcoords = R@coords LTS = R_coords (0, :1 yLT3 = R_coords(1,:] # Create the figure and axes objects fig, ax = plt. subplots () # Plot the points. x and y are original vectors, x_LT1 and y_LT1 are images ax.plot (x,y, 'ro') ax. plot (x_LT3 , y.LT3,"bo") # Connect the points by lines ax.plot (x,y, 'r!,le="~ ax. plot (x_LT3,y.LT3,'b') # Edit some settings ax.axvline(x=0,color="k",1s=":") ax.axhline(y=0,color="k",le=":") ax. grid (True) ax-axis((-2,2,-1,2]) ax.set_aspect (‘equal') 69 © scanned ith OREN Samer “20 -15 -10 -05 . o5 10 15 20 4.4.4 Shear Transformation Represent the Shear transformation T : R? + R? geometrically. Find the image of (2,3) under shear transformation import numpy as ap import matplotlib.pyplot as plt V = np.array([[2,3]]) origin = mp.array({{0, 0, 0],(0, 0, 0J]) # origin point Aenp.matrix({([1,2],[0,1]]) Vienp. matrix (V) V2=A+np. transpose (V1) va=np. array (V2) print ("Image of given vectors is:", V2) plt.quiver(+origin, V(:,0], V{:,1], color=('b'], scale=20) plt.quiver(vorigin, V2(0,:], V2(1,:1, color=('r'], scale=20) pit. show () 70 © scanned ith OREN Samer 008 “Joe 00?~ODSCSSC Another example. S$ = mp.array(((1,2),(0,1]]) S_coords = S@coords x1T4 = S_coords (0,1 yLT4 = S coords it, :1 # Create the figure and axes objects fig, ax = plt.subplots() # Plot the points. x and y are original vectors, x_LT1 and y_LT1 are images ax. plot (x,y, 'r0') ax. plot (x LT4,y_LT4,*bo") # Connect the points by lines ax.plot(x,y,'r' 41 ax. plot (x LT4,y.LT4,"b') # Edit some settings ax.axvline(x=0,color="k",1s=":") ax. axhline(y=0,color="k",18=":") ax. grid (True) ax-axie((-2,4,-1,2]) ax.set_aspect (‘equal') ax.set_title ("Shear"); 7 © scanned ith OREN Samer Shear 2.0 : 1s ios | it 10 1 i i 05 2 4.4.5 Composition Represent the composition of two 2D transformations. Find the image of veetor (10,0) when it is rotated by /2 radians then stretched hori- zontally 2 units. import numpy as mp import matplotlib.pyplot as plt V = np.array({(2,3]]) origin = mp.array(([0, 0, 01,0, 0, 011) # origin point np.matrix(((0,-1],(1,0]]) Benp.matrix(((2,0],[0,1]]) Vienp.matrix(V) V2=Aenp. transpose (V1) V3=B+V2 V2enp. array (V2) v3np. array (V3) print ("Image of given vectors is:", V3) plt.quiver(+origin, V[:,0], V{:,1], color=['b'], scale=20) plt.quiver(+origin, V2(0.:]. V2(1,:], color=['r'], scale=20) plt quiver (sorigin, V3(0,:], V3[1,:1, color=['g'], scale=20) plt.title('Bluesoriginal, Red=Rotated ,Green=Rotated+Streached') pit. show ( © scanned ith OREN Samer Blue=original, Red=Rotated ,Green=Rotated+Streached 008 002 0.00 ~Joe 002000 SSCS Another example. © = np. array ({[-cos (theta) , sia (theta) 1, [sin (theta) , cos (theta)11) Ceoords = COcoorde XLT = C_coords (0, :1 yLTS = C_coords(1,:] 4 Create the figure and axes objects fig, ax = plt.subplots 0 # Plot the points. x and y are original vectors, x_LT1 and y_LT1 are images ax. plot (x,y, 'ro') ax. plot (x_LTS ,y.LTS,'bo") 4 Connect the points by lines ax.plot (x.y, 'r',1s="--") ax. plot (x LTS ,y LTS, *b') ¥ Edit some settings ax.axvline(x=0,color="k",1s=":") ax. axhline(y=0,color="k",1e= ax. grid (True) ax.axis([-2,2,-1,2]) ax.set_aspect (‘equal') © scanned ith OREN Samer 2.0 15 1.0 os 0.0 -20 -15 -10 -05 00 oS 10 15 20 4.5 Exercise: 1. Ver the rank nullity theorem for the following linear transformation a) T:R? > RS defined by T(x, y) = (x + 4y, 2 + By, 3x + Gy) Ans: Rank=2, Nullity=1, RNT verified b) T:R— RY defined by T(x, y. 2) = (x+dy—2, 2e+5y+82, 3rty422,r4+y+2). Ans: Rank=3, Nullity=1, RNT verified 2, Find the dimension of the subspace spanned following set of vectors a) $= (1,2,3,4), (2,4,6,8), (1,1,1. 1) Ans: Dimension of subspace is 2 b) S=(1,-1,3,4), (2,1,6,8).(1,1,1, 1), (3,3,3.3) Ans: Dimension of subspace is 3 3. Find the image of (1,3) under following 2 transformations a) Horizontal stretch b) Reflection ©) Shear 4d) Rotation 74 © scanned ith OREN Samer

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy