import sglib reload(sglib) from sglib import * # The following allows us to use 'k' as a "variable" k=sy.Symbol('k') a=col(1,2); b=col(3,4); c=col(-2,5) #(1) 3*a #(2) 6*b #(3) k*c #(4) a+b #(5) b.transpose()+c.transpose() #(6) a-c #(7) 2*a+3*b #(8) 3*b-2*c+a #(9) -2*b.transpose()+2*c.transpose() #(10) inner_product(a,b) #(11) inner_product(b,c) #(12) inner_product(c,a) #(13) Matrix([(1,2), (3,4)]) * col(1,-1) #(14) Matrix([(0,1), (1,0)]) * col(2,3) #(15) # NOTE: Matrix is Identity Matrix, so we don't really need to work this! a=sy.Symbol('a'); b=sy.Symbol('b') # Need a,b as variables Matrix([(1,0), (0,1)]) * col(a,b) z1=2+3*i; z2=1-i; z3=5*i #(16) z1+z2 #(17) z1-z3 #(18) z1+z2-z3 #(19) (z1*z2).simplify() #(20) (z2*z3).simplify() #(21) z1.conjugate() #(22) z2.conjugate() #(23) abs(z1) #(24) abs(z2) #(25) abs(z3) #(26) Matrix([(1,2), (3,4)]).transpose() #(27) Matrix([(1,0,1), (0,2,3), (3,4,5)]).transpose() #(28) a=sy.Symbol('a'); b=sy.Symbol('b'); c=sy.Symbol('c'); d=sy.Symbol('d') w=sy.Symbol('w'); x=sy.Symbol('x'); y=sy.Symbol('y'); z=sy.Symbol('z') Matrix([(w,x),(y,z)]).transpose() #(29) Matrix([(1,2),(3,4)])*Matrix([(4,3),(2,1)]) #(30) # 2nd one is Identity Matrix! Matrix([(1,2),(3,4)])*Matrix([(1,0),(0,1)]) #(31) Matrix([(a,b),(c,d)])*Matrix([(w,x),(y,z)]) #(32) row(1,2)*col(4,3) #(33) col(1,2)*row(4,3) #(34) # Not the inverse Matrix([(0,1),(1,0)])*Matrix([(1,0),(0,1)]) # Their product IS the Identity, so YES Matrix([(0,1),(1,0)])*Matrix([(0,1),(1,0)]) # NO Matrix([(0,1),(1,0)])*Matrix([(0,0),(0,0)]) #(35) # We'll just ask for the inverse directly ... # It turns out to be (c) M = Matrix([(1,2),(3,4)]) Mi = M.inverse_ADJ() Mi # But, still we should CHECK it ... M*Mi #(36) # (a) - NO Matrix([(1,0),(0,0)]) * Matrix([(1,0),(0,0)]) # (b) - NO Matrix([(1,0),(0,0)]) * Matrix([(0,0),(0,1)]) # (c) - NO Matrix([(1,0),(0,0)]) * Matrix([(-1,0),(0,0)]) # So, its (d) - none of the above. # Actually, this matrix has no inverse ... Matrix([(1,0),(0,0)]).inverse_ADJ() # # Change of Basis Problems # b11 = 1/sqrt(2)*col(1,1); b12 = 1/sqrt(2)*col(1,-1) b21 = 1/sqrt(5)*col(2,1); b22 = 1/sqrt(5)*col(-1,2) #(37) v = col(2,3) v_b1 = col(inner_product(b11,v), inner_product(b12,v)) Print('$%s$' %myltx(v_b1)) #(38) v = col(3,2) v_b2 = col(inner_product(b21,v), inner_product(b22,v)) Print('$%s$' %myltx(v_b2)) #(39) v = col(1,0) v_b2 = col(inner_product(b21,v), inner_product(b22,v)) Print('$%s$' %myltx(v_b2)) #(40) v = col(5,5) v_b1 = col(inner_product(b11,v), inner_product(b12,v)) Print('$%s$' %myltx(v_b1)) M1 = Matrix([(1,2),(3,4)]) M2 = Matrix([(1,0),(0,0)]) M1*M2 M2*M1 v1 = col(a,b); v2=col(c,d) v1,v2 #(52) ip = inner_product # Yes v1 = col(1,0); v2 = col(0,1) v1.norm(), v2.norm(), ip(v1,v2) #(53) No - Orthogonal but not normalized v1 = col(2,0); v2 = col(0,2) v1.norm(), v2.norm(), ip(v1,v2) #(54) Yes (the "blue" basis) v1 = col(1,1)/sqrt(2); v2 = col(1,-1)/sqrt(2) v1.norm(), v2.norm(), ip(v1,v2) #(55) Yes v1 = col(1,0); v2 = col(0,-1) v1.norm(), v2.norm(), ip(v1,v2) #(56) Yes v1 = col(2,1)/sqrt(5); v2 = col(-1,2)/sqrt(5) v1.norm(), v2.norm(), ip(v1,v2) #(57) No - Normalized but not orthogonal v1 = col(1,1)/sqrt(2); v2 = col(-1,2)/sqrt(5) v1.norm(), v2.norm(), ip(v1,v2)