示例#1
0
 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()))
示例#2
0
 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()))
示例#3
0
  def testKnown(self):
    m = Matrix([[1,2,3,4], [1,4,9,16], [1,8,27,64], [1,16,81,256]])
    l = Matrix([[1,0,0,0], [1,1,0,0], [1,3,1,0], [1,7,6,1]])
    u = Matrix([[1,2,3,4], [0,2,6,12], [0,0,6,24], [0 ,0,0,24]])

    (x,y) = m.lu()
    self.assertTrue(x.isAlmostEqual(l))
    self.assertTrue(y.isAlmostEqual(u))
    self.assertTrue(m.isAlmostEqual(x*y))
  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))
示例#6
0
 def testTransposition(self):
   m = Matrix([[1,2],[3,4]])
   tr = Matrix([[1,3], [2,4]])
   self.assertTrue(tr.isAlmostEqual(m.transpose()))
示例#7
0
 def testClone(self):
   m = Matrix(7)
   a = m.copy()
   self.assertTrue(m.isAlmostEqual(a))
示例#8
0
 def testColumnNormalization(self):
   m = Matrix([[3,3],[4,4]]) 
   norm = Matrix([[0.6, 0.6],[0.8,0.8]])
   m.normalizeColumn(0)
   m.normalizeColumn(1)
   self.assertTrue(norm.isAlmostEqual(m))
示例#9
0
 def testHilbert(self):
   m = Matrix(50)
   m.hilbert()
   (l,u) = m.lu()
   self.assertTrue(m.isAlmostEqual(l*u))
示例#10
0
 def testUnit(self):
   one = Matrix(self.size)
   one.one()
   self.assertTrue(one.isAlmostEqual(one.invertLU()))
示例#11
0
 def testRandom(self):
   m = Matrix(self.size) 
   m.random(3);
   one = Matrix(self.size)
   one.one()
   self.assertTrue(one.isAlmostEqual(m * m.invertQRHouseholder()))