Package mikera.matrixx

Examples of mikera.matrixx.AMatrix


    validateQR(A, result);
  }

  @Test
  public void testZeroDecompose() {
    AMatrix a = ZeroMatrix.create(4, 3);
    HouseholderQR alg = new HouseholderQR(false);
    IQRResult result = alg.decompose(a);
    AMatrix q = result.getQ();
    AMatrix r = result.getR();

    assertEquals(IdentityMatrix.create(3), q.subMatrix(0, 3, 0, 3));
    assertTrue(r.isZero());
    validateQR(a, result);
  }
View Full Code Here


      v.addMultiple(v2,2.0);
    }
  }
 
  public void timeMatrixInverse(int runs) {
    AMatrix m=Matrixx.createRandomSquareMatrix(5);
    for (int i=0; i<runs; i++) {
      m=m.inverse();
    }
  }
View Full Code Here

    validateQR(a, result);
  }

  @Test
  public void testZeroDecomposeSquare() {
    AMatrix a = ZeroMatrix.create(3, 3);
    HouseholderQR alg = new HouseholderQR(false);
    IQRResult result = alg.decompose(a);
    AMatrix q = result.getQ();
    AMatrix r = result.getR();

    assertEquals(IdentityMatrix.create(3), q);

    assertTrue(r.isZero());
    validateQR(a, result);
  }
View Full Code Here

   *
   * @param a
   * @param result
   */
  public void validateQR(AMatrix a, IQRResult result) {
    AMatrix q = result.getQ();
    AMatrix r = result.getR();
    assertTrue(r.isUpperTriangular());
    assertTrue(q.innerProduct(r).epsilonEquals(a));
    assertTrue(q.hasOrthonormalColumns());
   
  }
View Full Code Here

   
    SparseColumnMatrix c=SparseColumnMatrix.create(Matrix.create(
        Vector.of(1,3),
        Vector.of(2,4)));

    AMatrix mc=m.innerProduct(c);
    assertEquals(5,mc.get(0,0),0.0);
  }
View Full Code Here

        M.set(SSIZE-1, SSIZE-1, M.get(SSIZE-1, SSIZE-1) + 3.14159);
    assertFalse(M.equals(D));
        D.set(SSIZE-1, SSIZE-1, D.get(SSIZE-1, SSIZE-1) + 3.14159);
    assertTrue(M.equals(D));

        AMatrix N = M.getTranspose();
        AMatrix Dt = D.getTranspose();
    assertTrue(N.equals(Dt));
        N.set(SSIZE-1, SSIZE-1, N.get(SSIZE-1, SSIZE-1) + 3.14159);
    assertFalse(N.equals(Dt));
        Dt.addAt(SSIZE-1, SSIZE-1, 3.14159);        // also test addAt
    assertTrue(N.equals(Dt));
  }
View Full Code Here

    for (int i=1; i<=30; i++) {
      long start,end;
      int size=i*i*10;
      Matrix a=Matrix.createRandom(size, size);
      Matrix b=Matrix.createRandom(size, size);
      AMatrix r;
     
      start=System.currentTimeMillis();
      r=Multiplications.directMultiply(a, b)
      end=System.currentTimeMillis();   
      System.out.println("Size: "+size +"    direct    timing = "+(end-start)*0.001);
 
View Full Code Here

public class TestLinear {
   
    @Test
    public void testSimpleSquareSolve() {
        AMatrix m= Matrix.create(new double[][] {{1,-2,1},{0,1,6},{0,0,1}});
        AMatrix mi=m.inverse();
        assertTrue(m.innerProduct(mi).isIdentity());
       
        AVector x=Linear.solve(m, Vector.of(4,-1,2));
       
        assertEquals(Vector.of(-24,-13,2),x);
View Full Code Here

        assertEquals(Vector.of(-24,-13,2),x);
    }
   
    @Test
    public void testSolveLeastSquaresVector() {
        AMatrix m= Matrix.create(new double[][] {{1,2},{3,4},{5,6}});
       
        AVector x = Linear.solveLeastSquares(m, Vector.of(1,2,3));
       
        assertEquals(Vector.of(0,0.5),x);
    }
View Full Code Here

        assertEquals(Vector.of(0,0.5),x);
    }
   
    @Test
    public void testSolveSquareVector() {
        AMatrix m= Matrix.create(new double[][] {{1,2,2},{1,4,1},{5,9,2}});
       
        AVector x = Linear.solveLeastSquares(m, Vector.of(1,3,3));
        assertTrue(Vector.of(-1.35294117647,1.05882352941,0.11764705882).epsilonEquals(x, 1e-8));
    }
View Full Code Here

TOP

Related Classes of mikera.matrixx.AMatrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.