def test_copy(self):

        mat = SquareMatrix.copy(self.matF1)
        self.assertTrue(mat == self.matF1)

        mat = SquareMatrix.copy(self.matF5)
        self.assertTrue(mat == self.matF5)
    def test_copy(self):

        mat = SquareMatrix.copy(self.matF1)
        self.assertTrue(mat == self.matF1)
        
        mat = SquareMatrix.copy(self.matF5)
        self.assertTrue(mat == self.matF5)
    def test_set_lower_triangular(self):

        mat = SquareMatrix.copy(self.matF2)
        mat.set_lower_triangular()
        self.is_matrix_equal_to_list(mat, self.lsF11)

        mat = SquareMatrix.copy(self.matF3)
        mat.set_lower_triangular()
        self.is_matrix_equal_to_list(mat, self.lsF12)
    def test_set_lower_symmetry(self):

        mat = SquareMatrix.copy(self.matF1)
        mat.set_lower_simmetry()
        self.is_matrix_equal_to_list(mat, self.lsF1)

        mat = SquareMatrix.copy(self.matF2)
        mat.set_lower_simmetry()
        self.is_matrix_equal_to_list(mat, [1,1,1,1,1,2,2,2,1,2,3,3,1,2,3,4])
    def test_set_transpose(self):
        
        mat = SquareMatrix.copy(self.matF1)
        mat.set_transpose()
        self.is_matrix_equal_to_list(mat, self.lsF1)

        mat = SquareMatrix.copy(self.matF2)
        mat.set_transpose()
        self.is_matrix_equal_to_list(mat, [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4])
    def test_set_unit_lower_triangular(self):

        mat = SquareMatrix.copy(self.matF2)
        mat.set_unit_lower_triangular()
        self.is_matrix_equal_to_list(mat, [1,2,3,4, 0,1,3,4,0,0,1,4,0,0,0,1])
        
        mat = SquareMatrix.copy(self.matF3)
        mat.set_unit_lower_triangular()
        self.is_matrix_equal_to_list(mat, [1,1,4,0,1,3,0,0,1])
    def test_set_strictly_lower_triangular(self):

        mat = SquareMatrix.copy(self.matF2)
        mat.set_strictly_lower_triangular()
        self.is_matrix_equal_to_list(mat, [0,2,3,4, 0,0,3,4,0,0,0,4,0,0,0,0])
        
        mat = SquareMatrix.copy(self.matF3)
        mat.set_strictly_lower_triangular()
        self.is_matrix_equal_to_list(mat, [0,1,4,0,0,3,0,0,0])
    def test_set_lower_triangular(self):

        mat = SquareMatrix.copy(self.matF2)
        mat.set_lower_triangular()
        self.is_matrix_equal_to_list(mat, self.lsF11)
        
        mat = SquareMatrix.copy(self.matF3)
        mat.set_lower_triangular()
        self.is_matrix_equal_to_list(mat, self.lsF12)
    def test_set_lower_symmetry(self):

        mat = SquareMatrix.copy(self.matF1)
        mat.set_lower_simmetry()
        self.is_matrix_equal_to_list(mat, self.lsF1)

        mat = SquareMatrix.copy(self.matF2)
        mat.set_lower_simmetry()
        self.is_matrix_equal_to_list(
            mat, [1, 1, 1, 1, 1, 2, 2, 2, 1, 2, 3, 3, 1, 2, 3, 4])
Beispiel #10
0
    def test_set_transpose(self):

        mat = SquareMatrix.copy(self.matF1)
        mat.set_transpose()
        self.is_matrix_equal_to_list(mat, self.lsF1)

        mat = SquareMatrix.copy(self.matF2)
        mat.set_transpose()
        self.is_matrix_equal_to_list(
            mat, [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4])
Beispiel #11
0
    def test_set_unit_lower_triangular(self):

        mat = SquareMatrix.copy(self.matF2)
        mat.set_unit_lower_triangular()
        self.is_matrix_equal_to_list(
            mat, [1, 2, 3, 4, 0, 1, 3, 4, 0, 0, 1, 4, 0, 0, 0, 1])

        mat = SquareMatrix.copy(self.matF3)
        mat.set_unit_lower_triangular()
        self.is_matrix_equal_to_list(mat, [1, 1, 4, 0, 1, 3, 0, 0, 1])
Beispiel #12
0
    def test_set_strictly_lower_triangular(self):

        mat = SquareMatrix.copy(self.matF2)
        mat.set_strictly_lower_triangular()
        self.is_matrix_equal_to_list(
            mat, [0, 2, 3, 4, 0, 0, 3, 4, 0, 0, 0, 4, 0, 0, 0, 0])

        mat = SquareMatrix.copy(self.matF3)
        mat.set_strictly_lower_triangular()
        self.is_matrix_equal_to_list(mat, [0, 1, 4, 0, 0, 3, 0, 0, 0])
Beispiel #13
0
    def test_lu_factorization(self):

        mat = SquareMatrix.from_list(3, [2, 4, 6, 4, -2, -4, -2, 6, 2])
        L, U = mat.lu_factorization()

        self.is_matrix_equal_to_matrix(L.mult_matrix_update_by_column(U), mat)

        #ensuring A - (LU) = zero matrix
        mat.set_add(-(L.mult_matrix_update_by_column(U)))
        self.is_matrix_equal_to_matrix(mat, SquareMatrix.copy(self.matF1))

        mat = SquareMatrix.from_list(3, [1, 5, -2, -2, -15, -11, 2, 8, -11])
        L, U = mat.lu_factorization()

        self.is_matrix_equal_to_list(L, [1, 5, -2, 0, 1, 3, 0, 0, 1])
        self.is_matrix_equal_to_list(U, [1, 0, 0, -2, -5, 0, 2, -2, -1])
    def test_lu_factorization(self):

        mat = SquareMatrix.from_list(3, [2,4,6,4, -2,-4,-2,6,2])
        L, U = mat.lu_factorization()
        
        self.is_matrix_equal_to_matrix(L.mult_matrix_update_by_column(U),mat)

        #ensuring A - (LU) = zero matrix
        mat.set_add (-(L.mult_matrix_update_by_column(U)))
        self.is_matrix_equal_to_matrix(mat,
                                        SquareMatrix.copy(self.matF1))


        mat = SquareMatrix.from_list(3,[1,5,-2,-2,-15,-11,2,8,-11])
        L,U = mat.lu_factorization()
        
        self.is_matrix_equal_to_list(L, [1,5,-2,0,1,3,0,0,1])
        self.is_matrix_equal_to_list(U, [1,0,0,-2,-5,0,2,-2,-1])
Beispiel #15
0
    def test_set_to_diagonal(self):

        self.matF2 = SquareMatrix.copy(self.matF2)
        self.matF2.set_to_diagonal([1, 1, 1, 1])
        self.is_matrix_equal_to_list(self.matF2, self.lsF8)
    def test_set_to_diagonal(self):

        self.matF2 = SquareMatrix.copy(self.matF2)
        self.matF2.set_to_diagonal([1,1,1,1])
        self.is_matrix_equal_to_list(self.matF2,self.lsF8)