def test_creation_from_vectors(self): vec1 = Vector(self.lsF2[:4]) vec2 = Vector.copy(vec1) vec3 = Vector.copy(vec1) vec4 = Vector.copy(vec1) mat = matrix.Matrix.from_vectors([vec1, vec2, vec3, vec4]) self.is_matrix_equal(self.matF2, mat)
def test_creation_from_vectors(self): vec1 = Vector(self.lsF2[:4]) vec2 = Vector.copy(vec1) vec3 = Vector.copy(vec1) vec4 = Vector.copy(vec1) mat = matrix.Matrix.from_vectors([vec1,vec2,vec3,vec4]) self.is_matrix_equal(self.matF2, mat)
def solve_lower_triangular_system(self, b): """ This function is going to solve for L*z = b where we solve for z, b is given and L is a lower unit triangular matrix (most likely the result of a LU operation) :b: Vector, the vector needed to solve the system :returns: Vector """ res = Vector.copy(b) bit = res.vector_iterator() it = self.full_iterator() for TL, value, BL in bit: data = it.next() BL = BL + (-(value * data["a21"])) bit.merge(TL, value, BL) return res
def solve_lower_triangular_system(self, b): """ This function is going to solve for L*z = b where we solve for z, b is given and L is a lower unit triangular matrix (most likely the result of a LU operation) :b: Vector, the vector needed to solve the system :returns: Vector """ res = Vector.copy(b) bit = res.vector_iterator() it = self.full_iterator() for TL,value,BL in bit: data = it.next() BL = BL + (-(value * data["a21"])) bit.merge(TL,value,BL) return res
def solve_upper_triangular_system(self, b): """ This function is the complementary one for solving a liner equation system based on LU, with solve_lower_triangular_system we solved L* z = b where now we can solve U* x = b where z = U*x and U is the upper triangular matrix from the factoriazition, basically we are performing a backward sostiuition :b: Vector, the vector needed to solve the system :returns: Vector """ res = Vector.copy(b) bit = res.vector_iterator(True) it = self.full_iterator(True) for TL, value, BL in bit: data = it.next() value -= data["at12"].dot(BL) value /= data["a11"] bit.merge(TL, value, BL) return res
def solve_upper_triangular_system(self,b): """ This function is the complementary one for solving a liner equation system based on LU, with solve_lower_triangular_system we solved L* z = b where now we can solve U* x = b where z = U*x and U is the upper triangular matrix from the factoriazition, basically we are performing a backward sostiuition :b: Vector, the vector needed to solve the system :returns: Vector """ res = Vector.copy(b) bit = res.vector_iterator(True) it = self.full_iterator(True) for TL,value,BL in bit: data = it.next() value -= data["at12"].dot(BL) value /= data["a11"] bit.merge(TL,value,BL) return res
def copy(cls, mat): """ Alternative constructor to generate a matrix identical to the given one """ return cls(mat.columns(), [Vector.copy(v) for v in mat.column_iterator()], False)
def copy(cls, mat): """ Alternative constructor to generate a matrix identical to the given one """ return cls(mat.columns(),[Vector.copy(v) for v in mat.column_iterator()],False)