def test_LU_3x3_matrix(self):
     matrix = Matrix([[1, 2, 4], [2, 1, 2], [1, 2, 1]])
     matrix.LU()
     self.assertEqual(matrix.L.tolist(),
                      [[1, 0, 0], [0.5, 1, 0], [0.5, 1, 1]])
     self.assertEqual(matrix.U.tolist(),
                      [[2, 1, 2], [0, 1.5, 0], [0, 0, 3]])
Пример #2
0
def get_index():
    if request.method == "POST":
        matrix = request.form['matrix']
        print(to_matrix(matrix))
        new_matrix = Matrix(to_matrix(matrix))
        new_matrix = new_matrix.matrix_inverse()
        return render_template('index.html', matrix=matrix, new_matrix=new_matrix)
    else:
        return render_template('index.html')
Пример #3
0
def get_index():
    if request.method == "POST":
        matrix = request.form['matrix']
        new_matrix = Matrix(to_matrix(matrix))
        new_matrix = new_matrix.matrix_inverse()
     #   new_matrix = '$\\left(\\begin{matrix}\n'
        new_matrix = matrix_to_sring(new_matrix)
        return render_template('index.html', matrix=matrix, new_matrix=new_matrix)
    else:
        return render_template('index.html')
Пример #4
0
def get_index():
    try:
        if request.method == "POST":
            matrix = request.form['matrix']
            print(to_matrix(matrix))
            new_matrix = Matrix(to_matrix(matrix))
            new_matrix = new_matrix.matrix_inverse()
            new_matrix = matrix_to_string(new_matrix)
            return render_template('matrix_index.html', matrix=matrix, new_matrix=new_matrix)
        else:
            return render_template('matrix_index.html')
    except WrongSize:
        return render_template('matrix_index.html', error_message="Matrix should be square")
    except NonInvertibleMatrix:
        return render_template('matrix_index.html', error_message="It is a singular matrix")
 def test_LU_2x2_matrix(self):
     matrix = Matrix([[3, 4], [5, 6]])
     matrix.LU()
     self.assertEqual(matrix.L.tolist(), [[1.0, 0.0], [0.6, 1.0]])
     self.assertEqual(matrix.U.tolist(), [[5.0, 6], [0.0, 0.4]])
 def final_check_3x3_matrix(self):
     matrix = Matrix([[1, 0, 0], [0.5, 1, 0], [0.5, 1, 1]])
     expected = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
     self.assertEqual(matrix.final_check().tolist(), expected)
 def final_check_2x2_matrix(self):
     matrix = Matrix([[1, 2], [2, 1]])
     expected = [[1, 0], [0, 1]]
     self.assertEqual(matrix.final_check().tolist(), expected)
 def test_wrong_matrix(self):
     with self.assertRaises(Exception):
         matrix  = Matrix([[1,2,3],[2, 3, 4], ["a", "b", "c"]])
         matrix.check_matrix()
 def test_det_matrix(self):
     matrix = Matrix([[1, 2, 3], [4, 5, 6], [5, 7, 9]])
     self.assertEqual(matrix.det(), "The determinant of a matrix is equal to zero, then the matrix does not have an inverse")
 def test_not_square_matrix_2(self):
     with self.assertRaises(Exception):
         matrix = Matrix([[1, 2], [2, 3], [1, 2, 3]])
         matrix.check_matrix()
 def test_inverse_3x3_matrix(self):
     matrix = Matrix([[1, 0, 0], [0.5, 1, 0], [0.5, 1, 1]])
     expected = [[1, 0, 0], [-0.5, 1, 0], [0, -1, 1]]
     self.assertEqual(matrix.matrix_inverse().tolist(), expected)
 def test_inverse_2x2_matrix(self):
     matrix = Matrix([[3, 4], [5, 6]])
     expected = [[-3, 2], [2.5, -1.5]]
     self.assertEqual(matrix.matrix_inverse().tolist(), expected)
 def test_wrong_matrix(self):
     matrix = Matrix([[1, 2, 3], [2, 3, 4], ["a", "b", "c"]])
     self.assertEquals(matrix.check_matrix(), "Wrong matrix")
 def test_not_square_matrix_2(self):
     matrix = Matrix([[1, 3], [1, 2, 3]])
     self.assertEqual(
         matrix.check_matrix(),
         "Matrix is not square matrix, it doesn't have inverse")
 def test_inverse_3x3_matrix(self):
     matrix = Matrix([[1, 2, 4], [2, 1, 2], [1, 2, 1]])
     expected = [[0, -0.33, 0.66], [0.6, 0, -0.3], [-0.3, 0.3, 0]]
     self.assertEqual(matrix.matrix_inverse().tolist(), expected)