Example #1
0
  @Test
  public void testLU() {
    // we are testing that PA = LU

    AMatrix a = Matrixx.create(new double[][] {{4, 3}, {6, 3}});

    AMatrix[] ms = SimpleLUP.decomposeLUP(a);
    AMatrix lu = ms[0].innerProduct(ms[1]);

    assertEquals(ms[2].innerProduct(a), lu);

    // assertEquals(Matrixx.create(new double[][] {{1,0},{1.5,1}}),lu[0]);
    // assertEquals(Matrixx.create(new double[][] {{4,3},{0,-1.5}}),lu[1]);

    a = Matrixx.createRandomSquareMatrix(4);
    ms = SimpleLUP.decomposeLUP(a);
    lu = ms[0].innerProduct(ms[1]);
    assertTrue(ms[2].innerProduct(a).epsilonEquals(lu));

    a = PermutationMatrix.create(0, 2, 1, 3);
    ms = SimpleLUP.decomposeLUP(a);
    lu = ms[0].innerProduct(ms[1]);
    assertTrue(ms[2].innerProduct(a).epsilonEquals(lu));
    assertEquals(IdentityMatrix.create(4), ms[0]);
    assertEquals(IdentityMatrix.create(4), ms[1]);
    assertEquals(a, ms[2].inverse());
  }
Example #2
0
 public CholeskyResult(AMatrix L) {
   this(L, IdentityMatrix.create(L.rowCount()), L.getTranspose());
 }