def testRandom(self): m = Matrix(5) m.random(3) q, r = m.QRSimple() one = Matrix(5) one.one() self.assertTrue(m.isAlmostEqual(q*r)) self.assertTrue(one.isAlmostEqual(q*q.transpose()))
def testRandom(self): m = Matrix(self.size) m.random(3) q, r = m.QRHouseholder() one = Matrix(self.size) one.one() self.assertTrue(m.isAlmostEqual(q*r)) self.assertTrue(one.isAlmostEqual(q*q.transpose()))
def test(self, m, size): one = Matrix(size) one.one() e_lu = (m * m.invertLU() - one).frobeniusNorm() e_qr_simple = (m * m.invertQRSimple() - one).frobeniusNorm() e_qr_house = (m * m.invertQRHouseholder() - one).frobeniusNorm() self.putMany([size, e_lu, e_qr_simple, e_qr_house])
def testRandom(self): l = Matrix(self.size) u = Matrix(self.size) l.randomLowerTriangular(5) u.randomUpperTriangular(5) m = l * u one = Matrix(self.size) one.one() self.assertTrue(one.isAlmostEqual(m * m.invertLU()))
def testUpperTriangularInversion(self): a = Matrix(15) a.randomUpperTriangular(87) b = a.invertUpperTriangular() c = Matrix(15) c.one() print (c - a * b).frobeniusNorm() self.assertTrue(c.isAlmostEqual(a * b)) self.assertTrue(c.isAlmostEqual(b * a))
def test(self, m, size): one = Matrix(size) one.one() m.random(int(time())) q, r = m.QRSimple() a_simple = (q*q.transpose() - one).frobeniusNorm() b_simple = (m - q*r).frobeniusNorm() q, r = m.QRHouseholder() a_house = (q*q.transpose() - one).frobeniusNorm() b_house = (m - q*r).frobeniusNorm() self.putMany([size, a_simple, b_simple, a_house, b_house])
def testManipulators(self): a = Matrix(44) a.zero() a.one() a.hilbert()
def testUnit(self): one = Matrix(self.size) one.one() self.assertTrue(one.isAlmostEqual(one.invertLU()))
def testRandom(self): m = Matrix(self.size) m.random(3); one = Matrix(self.size) one.one() self.assertTrue(one.isAlmostEqual(m * m.invertQRHouseholder()))