Exemplo n.º 1
0
def test_Matrix_LUP(Matrix120):
  list = [[1, 2, 0],
          [3, 5, 4],
          [5, 6, 3],
         ]
  LUP = [[5, 6, 3],
        [3/5., 7/5., 11/5.],
        [1/5., 4/7., -13/7.],
        ]
  LTrue = [[1, 0, 0],
       [3/5., 1, 0],
       [1/5., 4/7., 1],
      ]
  UTrue = [[5, 6, 3],
       [0, 7/5., 11/5.],
       [0, 0, -13/7.],
      ]
  PTrue = [[0, 0, 1],
       [0, 1, 0],
       [1, 0, 0],
      ]
  L, U, P = Matrix.LUP(Matrix120)
  assert Matrix120 == Matrix(list)
  #assert Matrix120 == Matrix(LUP)
  assert L == Matrix(LTrue)
  assert U == Matrix(UTrue)
  assert P == Matrix(PTrue)
Exemplo n.º 2
0
def test_Matrix_solveUxy(Matrix120):
  b = Matrix([[0.1],
              [12.5],
              [10.3]])
  L, U, P = Matrix.LUP(Matrix120)
  y = Matrix120._solveLyPb(L, P, b)
  assert y == Matrix([[10.3], [6.319999], [-5.571428]])
  x = Matrix120._solveUxy(U, y)
  assert x == Matrix([[0.5], [-0.2], [3]])