本文整理汇总了Python中tableau.Tableau.gaussian_elimination方法的典型用法代码示例。如果您正苦于以下问题:Python Tableau.gaussian_elimination方法的具体用法?Python Tableau.gaussian_elimination怎么用?Python Tableau.gaussian_elimination使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tableau.Tableau
的用法示例。
在下文中一共展示了Tableau.gaussian_elimination方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test
# 需要导入模块: from tableau import Tableau [as 别名]
# 或者: from tableau.Tableau import gaussian_elimination [as 别名]
class Test(unittest.TestCase):
def setUp(self):
# variables
pre_var = [(0, True), (0, False), (0, False), (0, True), (0, True)]
self.vars = [Variable(*v) for v in pre_var]
# row lines
pre_row = [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 1, -1, 0, 0],
[2, -1, 0, -1, 0], [-1, 2, 0, 0, -1]]
self.rows = [RowLine(r) for r in pre_row]
# tableau
self.table = Tableau(self.vars, self.rows)
def tearDown(self):
pass
# tests about operators to help Gaussian elimination
def test_row_subtraction(self):
t_sub = self.rows[3] - self.rows[2]
self.assertListEqual(t_sub.coef, [1, -2, 1, -1, 0])
def test_row_multiplication(self):
t_mul = self.rows[4] * 3
self.assertListEqual(t_mul.coef, [-3, 6, 0, 0, -3])
def test_row_division(self):
t_div = self.rows[2] / 5
self.assertListEqual(t_div.coef, [0.2, 0.2, -0.2, 0, 0])
def test_getitem(self):
# originally, this operation should be written self.rows[2].coef[0]
# RowLine has __getitem__ method, so this abbreviation is able
self.assertEqual(self.rows[2][0], 1)
# main test
def test_gaussian_elimination(self):
self.table.gaussian_elimination(2, 0)
coef = [r.coef for r in self.table.rows]
self.assertListEqual(coef, [[-1, -1, 1, 0, 0], [0, 0, 0, 0, 0],
[1, 1, -1, 0, 0], [0, -3, 2, -1, 0],
[0, 3, -1, 0, -1]])