Package mikera.matrixx

Examples of mikera.matrixx.Matrix


    /**
     * See if a matrix that is more singular has a lower quality.
     */
    @Test
    public void checkQuality() {
        Matrix A_good = DiagonalMatrix.create(4,3,2,1).toMatrix();
        Matrix A_bad = DiagonalMatrix.create(4,3,2,0.1).toMatrix();

        LUSolver solver = new LUSolver();
       
        assertNotNull(solver.setA(A_good));
        double q_good;
View Full Code Here


    /**
     * See if quality is scale invariant
     */
    @Test
    public void checkQuality_scale() {
        Matrix A = DiagonalMatrix.create(4,3,2,1).toMatrix();
        Matrix Asmall = A.copy();
        Asmall.scale(0.01);

        LUSolver solver = new LUSolver();
       
        assertNotNull(solver.setA(A));
        double q;
View Full Code Here

    /**
     * A very easy matrix to decompose
     */
    @Test
    public void square_trivial() {
        Matrix A = Matrix.create(new double[][] {{5, 2, 3}, {1.5, -2, 8}, {-3, 4.7, -0.5}});
        Matrix b = Matrix.create(new double[][] {{18}, {21.5}, {4.9000}});

        LUSolver solver = new LUSolver();
       
        assertNotNull(solver.setA(A));
        AMatrix x = solver.solve(b);


        Matrix x_expected = Matrix.create(new double[][] {{1}, {2}, {3}});

        assertTrue(x_expected.epsilonEquals(x,1e-8));
    }
View Full Code Here

     * perform a pivot.  Pivots can change the data structure and can cause solve to fail if not
     * handled correctly.
     */
    @Test
    public void square_pivot() {
        Matrix A = Matrix.create(new double[][] {{0, 1, 2}, {-2, 4, 9}, {0.5, 0, 5}});
        Matrix b = Matrix.create(new double[][] {{8}, {33}, {15.5}});

        LUSolver solver = new LUSolver();
       
        assertNotNull(solver.setA(A));
        Matrix x = solver.solve(b).toMatrix();

        Matrix x_expected = Matrix.create(new double[][] {{1}, {2}, {3}});

        assertTrue(x_expected.epsilonEquals(x,1e-6));
    }
View Full Code Here

    /**
     * Checks to see if the modifyA() flag is set correctly
     */
    @Test
    public void modifiesA() {
        Matrix A_orig = Matrix.createRandom(4,4);
        Matrix A = A_orig.copy();

        QRHouseColSolver solver = new QRHouseColSolver();

        assertTrue(solver.setA(A));

View Full Code Here

    /**
     * Checks to see if the modifyB() flag is set correctly
     */
    @Test
    public void modifiesB() {
        Matrix A = Matrix.createRandom(4,4);

        QRHouseColSolver solver = new QRHouseColSolver();
       
        assertTrue(solver.setA(A));

        Matrix B = Matrix.createRandom(4,2);
        Matrix B_orig = B.copy();

        solver.solve(B);

        assertTrue(B_orig.epsilonEquals(B));
    }
View Full Code Here

    /**
     * See if a matrix that is more singular has a lower quality.
     */
    @Test
    public void checkQuality() {
        Matrix A_good = DiagonalMatrix.create(4,3,2,1).toMatrix();
        Matrix A_bad = DiagonalMatrix.create(4,3,2,0.1).toMatrix();

        QRHouseColSolver solver = new QRHouseColSolver();

        assertTrue(solver.setA(A_good));
        double q_good;
View Full Code Here

    @Test
    public void testInverseAndSolve() {
      double[][] dataA = {{1,2,4},
              {2,13,23},
              {4,23,90}};
    Matrix A = Matrix.create(dataA);
    double[][] dataB = {{17},{97},{320}};
    Matrix b = Matrix.create(dataB);
//    Matrix x = Matrix.createRandom(3, 1);
    Matrix x;

        CholeskyLDUSolver solver = new CholeskyLDUSolver();
        assertTrue(solver.setA(A));
        Matrix A_inv_result = solver.invert().toMatrix();
        x = solver.solve(b).toMatrix();

        double[][] data_A_inv_expected = {{1.453515, -0.199546, -0.013605},
                          {-0.199546, 0.167800, -0.034014},
                          {-0.013605, -0.034014, 0.020408}};
        Matrix A_inv_expected = Matrix.create(data_A_inv_expected);
        double[][] data_x_expected = {{1},{2},{3}};
        Matrix x_expected = Matrix.create(data_x_expected);

        assertArrayEquals(A_inv_expected.getElements(),A_inv_result.getElements(),1e-5);
        assertArrayEquals(x_expected.getElements(),x.getElements(),1e-5);
    }
View Full Code Here

    /**
     * See if quality is scale invariant
     */
    @Test
    public void checkQuality_scale() {
        Matrix A = DiagonalMatrix.create(4,3,2,1).toMatrix();
        Matrix Asmall = A.copy();
        Asmall.scale(0.01);

        QRHouseColSolver solver = new QRHouseColSolver();

        assertTrue(solver.setA(A));
        double q;
View Full Code Here

    /**
     * A very easy matrix to decompose
     */
    @Test
    public void square_trivial() {
        Matrix A = Matrix.create(new double[][] {{5, 2, 3}, {1.5, -2, 8}, {-3, 4.7, -0.5}});
        Matrix b = Matrix.create(new double[][] {{18}, {21.5}, {4.9000}});

        QRHouseColSolver solver = new QRHouseColSolver();
        assertTrue(solver.setA(A));
        AMatrix x = solver.solve(b);


        Matrix x_expected = Matrix.create(new double[][] {{1}, {2}, {3}});

        assertTrue(x_expected.epsilonEquals(x,1e-8));
    }
View Full Code Here

TOP

Related Classes of mikera.matrixx.Matrix

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.