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')
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')
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_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_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)