Beispiel #1
0
	def det(self):
		'''
		Caluculate determinant.
		'''
		dimension = self.dim()
		if dimension == [2,2]:
			v1 = self.rows[0]
			v2 = self.rows[1]
			a = v1.cols[0]
			b = v1.cols[1]
			c = v2.cols[0]
			d = v2.cols[1]
		
			return a*d-b*c
		
		elif dimension == [3,3]:
			row1 = self.rows[0]
			row2 = self.rows[1]
			row3 = self.rows[2]
		
			A = row1.cols[0]
			B = row1.cols[1]
			C = row1.cols[2]
			x = row2.cols[0]
			y = row2.cols[1]
			z = row2.cols[2]
			a = row3.cols[0]
			b = row3.cols[1]
			c = row3.cols[2]
		
			return A*y*c+B*z*a+C*x*b-A*z*b-B*x*c-C*y*a
		
		else:#TODO: Not work...
			_mat = self.decomp()
			
			reop = []
			for i, col in enumerate(_mat):
				for j, ele in enumerate(col): 
					if i == j: reop.append(ele)
			
			return ut.mac(reop)			
Beispiel #2
0
	def test_mac(self):
		ls = [1,2,3,4,5]
		res = ut.mac(ls)
		self.assertEqual(120, res)