def test_columnspace_second(): M = Matrix([[1, 2, 0, 2, 5], [-2, -5, 1, -1, -8], [0, -3, 3, 4, 1], [3, 6, 0, -7, 2]]) # now check the vectors basis = M.columnspace() assert basis[0] == Matrix([1, -2, 0, 3]) assert basis[1] == Matrix([2, -5, -3, 6]) assert basis[2] == Matrix([2, -1, 4, -7]) #check by columnspace definition a, b, c, d, e = symbols('a b c d e') X = Matrix([a, b, c, d, e]) for i in range(len(basis)): eq = M * X - basis[i] assert len(solve(eq, X)) != 0 #check if rank-nullity theorem holds assert M.rank() == len(basis) assert len(M.nullspace()) + len(M.columnspace()) == M.cols
vec_in_space = proj(random_vector, orth_comp) + proj(random_vector, S[1]) #test = Matrix([Matrix(S), vec_in_space]) #print np.array(test) #print np.array(test.rref()[0]) print 'New vector inside S: ' + str(vec_in_space) # Create a vector not in span(A) vec_not_in_space = np.random.rand(1, 4)[0] #test = Matrix([Matrix(S), vec_not_in_space]) #print np.array(test) #print np.array(test.rref()[0]) print 'New vector not in S: ' + str(vec_not_in_space) # (2) # Calculate dim(S), i.e. the number of vectors in its basis dim = len(A.columnspace()) print 'Dim(S): ' + str(dim) # (3) asArray = np.array(A).astype(np.float) thing = orth(asArray) vec1 = [] vec2 = [] for i in range(len(thing)): vec1.append(thing[i][0]) vec2.append(thing[i][1]) vec1 = np.array(vec1) vec1 = np.array(vec1).astype(np.float) ortho_basis = np.array((vec1, vec2))