Package org.matrix

Examples of org.matrix.Matrix


        myMatrix.clear();
        assertTrue(myMatrix.isZero());
    }
    @Test
    public void cloneAndEqualMatrixes() {
        Matrix myMatrix = new Matrix(2, 2);
        myMatrix.set(0, 0, 1.0);
        myMatrix.set(0, 1, 2.0);
        myMatrix.set(1, 0, 3.0);
        myMatrix.set(1, 1, 4.0);
        Matrix myClonedMatrix = myMatrix.clone();
        assertTrue(myMatrix.equals(myClonedMatrix));
        assertEquals(2, myClonedMatrix.getRows());
        assertEquals(2, myClonedMatrix.getColumns());
    }
View Full Code Here


        assertEquals(2, myClonedMatrix.getRows());
        assertEquals(2, myClonedMatrix.getColumns());
    }
    @Test
    public void testPrecisionEquals() {
        Matrix myMatrix = new Matrix(1,1);
        myMatrix.set(0, 0, 1.001);
        Matrix myWrongPrecisionMatrix = new Matrix(1,1);
        myWrongPrecisionMatrix.set(0, 0, 1.0);
        assertTrue(myMatrix.equals(myWrongPrecisionMatrix, 2));
        assertFalse(myMatrix.equals(myWrongPrecisionMatrix, 3));
    }
View Full Code Here

        assertTrue(myMatrix.equals(myWrongPrecisionMatrix, 2));
        assertFalse(myMatrix.equals(myWrongPrecisionMatrix, 3));
    }
    @Test
    public void differentMatrixes() {
        Matrix myMatrix1 = new Matrix(1, 1);
        Matrix myMatrix2 = new Matrix(1, 1);
        myMatrix1.set(0, 0, 1.0);
        myMatrix2.set(0, 0, 2.0);
        assertFalse(myMatrix1.equals(myMatrix2));
    }
View Full Code Here

    private static final double EPSILON = 0.0001;
    @Test
    public void testAdd() {
        double [][]initMatrix = {{1, 2}, {3, 4}};
        double [][]sumMatrix = {{2, 4}, {6, 8}};
        Matrix myMatrix1 = new Matrix(initMatrix);
        Matrix myMatrix2 = new Matrix(initMatrix);
        Matrix myOutputMatrix = new Matrix(sumMatrix);
        Matrix mySumMatrix = MatrixMath.add(myMatrix1, myMatrix2);
        assertTrue(mySumMatrix.equals(myOutputMatrix));
    }
View Full Code Here

        assertTrue(mySumMatrix.equals(myOutputMatrix));
    }
    @Test
    public void testSubtract() {
        double [][]initMatrix = {{1, 2}, {3, 4}};
        Matrix myMatrix1 = new Matrix(initMatrix);
        Matrix myMatrix2 = new Matrix(initMatrix);
        Matrix myOutputMatrix = new Matrix(2, 2);
        Matrix mySubtractMatrix = MatrixMath.subtract(myMatrix1, myMatrix2);
        assertTrue(mySubtractMatrix.equals(myOutputMatrix));
        assertTrue(mySubtractMatrix.isZero());
    }
View Full Code Here

    }
    @Test
    public void testDivide() {
        double [][]initMatrix = {{2, 4}, {8, 16}};
        double [][]dividedMatrix = {{1, 2}, {4, 8}};
        Matrix myMatrix = new Matrix(initMatrix);
        Matrix myOutputMatrix = new Matrix(dividedMatrix);
        Matrix myDividedMatrix = MatrixMath.divide(myMatrix, 2.0);
        assertTrue(myDividedMatrix.equals(myOutputMatrix));
    }
View Full Code Here

        assertTrue(myDividedMatrix.equals(myOutputMatrix));
    }
    @Test
    public void createIdentityMatrix() {
        double [][]initMatrix = {{1, 0}, {0, 1}};
        Matrix myMatrix = new Matrix(initMatrix);
        Matrix identityMatrix = MatrixMath.identity(2);
        assertTrue(identityMatrix.equals(myMatrix));
    }
View Full Code Here

    }
    @Test
    public void testDotProduct() {
        double []rowMatrix = {1, 2, 3, 4};
        double []columnMatrix = {5, 6, 7, 8};
        Matrix myRowMatrix = Matrix.createRowMatrix(rowMatrix);
        Matrix myColumnMatrix = Matrix.createColumnMatrix(columnMatrix);
        assertEquals(70.0, MatrixMath.dotProduct(myRowMatrix, myColumnMatrix), EPSILON);
    }
View Full Code Here

    }
    @Test
    public void testTransposeMatrix() {
        double [][]initMatrix = {{1, 2}, {3, 4}, {5, 6}};
        double [][]outMatrix = {{1, 3, 5}, {2, 4, 6}};
        Matrix myMatrix = new Matrix(initMatrix);
        Matrix myOutputMatrix = new Matrix(outMatrix);
        Matrix myTransposedMatrix = MatrixMath.transpose(myMatrix);
        assertTrue(myTransposedMatrix.equals(myOutputMatrix));
    }
View Full Code Here

        assertTrue(myTransposedMatrix.equals(myOutputMatrix));
    }
    @Test
    public void testTransposeVectorMatrix() {
        double []inputData = {1, 2, 3};
        Matrix myColMatrix = Matrix.createColumnMatrix(inputData);
        Matrix myRowMatrix = Matrix.createRowMatrix(inputData);
        Matrix myTransposedMatrix1 = MatrixMath.transpose(myColMatrix);
        Matrix myTransposedMatrix2 = MatrixMath.transpose(myRowMatrix);
        assertTrue(myTransposedMatrix1.equals(myRowMatrix));
        assertTrue(myTransposedMatrix2.equals(myColMatrix));
    }
View Full Code Here

TOP

Related Classes of org.matrix.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.