示例#1
0
 def test_divide(self):
     self.assertEqual(
         matrix.MatrixType([[16, -4], [12, 8]]).divide(4),
         matrix.MatrixType([[4, -1], [3, 2]]))
     self.assertEqual(
         matrix.MatrixType([[12], [-7], [-10]]).divide(
             matrix.MatrixType([[4, 2, -1], [3, -2, 2], [1, -3, 1]])),
         matrix.MatrixType([[1], [3], [-2]]))
示例#2
0
 def test_multiply(self):
     self.assertEqual(
         matrix.MatrixType([[4, -1], [3, 2]]).multiply(4),
         matrix.MatrixType([[16, -4], [12, 8]]))
     self.assertEqual(
         matrix.MatrixType([[2, 1], [0, -1]]).multiply(
             matrix.MatrixType([[-3, 4], [2, -2]])),
         matrix.MatrixType([[-4, 6], [-2, 2]]))
示例#3
0
 def test_union(self):
     self.assertEqual(
         matrix.MatrixType([[1, 1, 1], [1, 2, 3], [1, 3, 6]]).union(),
         matrix.MatrixType([[3, -3, 1], [-3, 5, -2], [1, -2, 1]]))
示例#4
0
 def test_eq(self):
     self.assertTrue(
         matrix.MatrixType([[4, 2, -1], [3, -2, 2], [1, -3, 1]]) ==
         matrix.MatrixType([[4, 2, -1], [3, -2, 2], [1, -3, 1]]))
示例#5
0
 def test_transposed(self):
     self.assertEqual(
         matrix.MatrixType([[-1, 3, 1, 0], [5, 7, -2, 4]]).transposed(),
         matrix.MatrixType([[-1, 5], [3, 7], [1, -2], [0, 4]]))
示例#6
0
 def test_determinant(self):
     self.assertEqual(
         matrix.MatrixType([[-5, 4, 1], [1, -2, 3],
                            [0, 6, 2]]).determinant(), 108)
示例#7
0
	def test_determinant(self):
		with self.assertRaises(Exception) as context:
			matrix.MatrixType([[3, 2, -4], [2, -7, 0], [4, -1, 4], [3, 2, -4], [0, 0, 1]]).determinant()
		self.assertEqual(str(context.exception), 'Нельзя вычислить определитель неквадратной матрицы')
示例#8
0
 def test_subtract(self):
     self.assertEqual(
         matrix.MatrixType([[4, -1], [3, 2]]).subtract(
             matrix.MatrixType([[1, -5], [0, -1]])),
         matrix.MatrixType([[3, 4], [3, 3]]))
示例#9
0
 def test_withoutRowAndColumn(self):
     self.assertEqual(
         matrix.MatrixType([[3, 2, -4], [2, -7, 0], [4, -1, 4], [3, 2, -4],
                            [0, 0, 1]]).withoutRowAndColumn(2, 3),
         matrix.MatrixType([[3, 2], [4, -1], [3, 2], [0, 0]]))
示例#10
0
 def test_width(self):
     self.assertEqual(
         matrix.MatrixType([[3, 2, -4], [2, -7, 0], [4, -1, 4], [3, 2, -4],
                            [0, 0, 1]]).width(), 3)
示例#11
0
 def test_height(self):
     self.assertEqual(
         matrix.MatrixType([[3, 2, -4], [2, -7, 0], [4, -1, 4], [3, 2, -4],
                            [0, 0, 1]]).height(), 5)
示例#12
0
	def test_withoutRowAndColumn(self):
		with self.assertRaises(Exception) as context:
			matrix.MatrixType([[3, 2, -4], [2, -7, 0], [4, -1, 4], [3, 2, -4], [0, 0, 1]]).withoutRowAndColumn(2, 4)
		self.assertEqual(str(context.exception), 'Координаты вне диапазона матрицы')
示例#13
0
	def test_divide(self):
		with self.assertRaises(Exception) as context:
			matrix.MatrixType([[16, -4], [12, 8]]).divide(0)
		self.assertEqual(str(context.exception), 'division by zero')
示例#14
0
	def test_multiply(self):
		with self.assertRaises(Exception) as context:
			matrix.MatrixType([[2, 1, 3], [0, -1, 8]]).multiply(matrix.MatrixType([[-3, 4], [2, -2]]))
		self.assertEqual(str(context.exception), 'Ширина первого множителя должна быть равна высоте второго множителя')
示例#15
0
	def test_subtract(self):
		with self.assertRaises(Exception) as context:
			matrix.MatrixType([[4, -1], [3, 2]]).subtract(matrix.MatrixType([[-1, 5], [0, 1], [6, 7]]))
		self.assertEqual(str(context.exception), 'Матрицы должны быть одного размера')
示例#16
0
 def test_negate(self):
     self.assertEqual(
         matrix.MatrixType([[-5, 4, 1], [1, -2, 3], [0, 6, 2]]).negate(),
         matrix.MatrixType([[5, -4, -1], [-1, 2, -3], [0, -6, -2]]))
示例#17
0
 def test_add(self):
     self.assertEqual(
         matrix.MatrixType([[4, -1],
                            [3,
                             2]]).add(matrix.MatrixType([[-1, 5], [0, 1]])),
         matrix.MatrixType([[3, 4], [3, 3]]))
示例#18
0
 def test_elementAt(self):
     self.assertEqual(
         matrix.MatrixType([[3, 2, -4], [2, -7, 0], [4, -1, 4], [3, 2, -4],
                            [0, 0, 1]]).elementAt(3, 2), -1)
示例#19
0
 def test_inverse(self):
     self.assertEqual(
         matrix.MatrixType([[1, 1, 1], [1, 2, 3], [1, 3, 6]]).inverse(),
         matrix.MatrixType([[3, -3, 1], [-3, 5, -2], [1, -2, 1]]))
示例#20
0
 def test_minor(self):
     self.assertEqual(
         matrix.MatrixType([[1, 3, -2], [4, 1, 0], [2, -1, 4]]).minor(3, 2),
         8)
示例#21
0
 def test_algebraicComplement(self):
     self.assertEqual(
         matrix.MatrixType([[-5, 4, 1], [1, -2, 3],
                            [0, 6, 2]]).algebraicComplement(2, 3), 30)
示例#22
0
文件: Autorun.py 项目: Garfild63/smo
for i in range(n):
    t[i] = t[i].copy()
    arr = input().split(' ')
    for j in range(n):
        t[i][j] = int(arr[j])
am = n * [n * [0]]
bm = n * [[0]]
for i in range(n):
    am[i] = am[i].copy()
    bm[i] = bm[i].copy()
    for j in range(n):
        am[i][j] = 0
        if i == 0:
            bm[i][0] = 1
            am[i][j] = 1
        elif i == j:
            bm[i][0] = 0
            for k in range(n):
                if t[i][k] > 0:
                    am[i][j] = am[i][j] + t[i][k]
        else:
            bm[i][0] = 0
            if t[j][i] > 0:
                am[i][j] = -t[j][i]
a = matrix.MatrixType(am)
b = matrix.MatrixType(bm)
c = b.divide(a)
print("Вероятности состояний: ")
for i in range(1, n + 1):
    print("p" + str(i) + "=" + str(c.elementAt(i, 1)))