Ejemplo n.º 1
0
 def testRandom(self):
   l = Matrix(5)
   l.randomLowerTriangular(5)
   u = Matrix(5)
   u.randomUpperTriangular(5)
   m = l*u
   (x,y) = m.lu()
   self.assertTrue(m.isAlmostEqual(x*y))
Ejemplo n.º 2
0
  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))
Ejemplo n.º 4
0
def genMatrix(size, kind):
  m = Matrix(size)
  if kind == "random":
    m.random(seed())
  elif kind == "triangular":
    m.randomUpperTriangular(seed())
  elif kind == "hilbert":
    m.hilbert()
  elif kind == "diagonal_dominant":
    m.randomDiagonalDominant(seed())
  elif kind == "almost_singular":
    m.randomAlmostSingular(seed())
  elif kind == "zero_minor":
    m.randomZeroMinor(seed())
  elif kind == "tridiagonal":
    m.randomTridiagonal(seed())
  else:
    return None
  return m