commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/linear RealMatrixImplTest.java
Date Tue, 18 May 2004 04:08:39 GMT
psteitz     2004/05/17 21:08:38

  Modified:    math/src/test/org/apache/commons/math/linear
                        RealMatrixImplTest.java
  Log:
  Added tests corresponding to examples in user guide.
  
  Revision  Changes    Path
  1.14      +30 -1     jakarta-commons/math/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java
  
  Index: RealMatrixImplTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/linear/RealMatrixImplTest.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- RealMatrixImplTest.java	8 Apr 2004 07:08:22 -0000	1.13
  +++ RealMatrixImplTest.java	18 May 2004 04:08:38 -0000	1.14
  @@ -435,6 +435,35 @@
           }
       }
       
  +    /** test examples in user guide */
  +    public void testExamples() {
  +        // Create a real matrix with two rows and three columns
  +        double[][] matrixData = { {1d,2d,3d}, {2d,5d,3d}};
  +        RealMatrix m = new RealMatrixImpl(matrixData);
  +        // One more with three rows, two columns
  +        double[][] matrixData2 = { {1d,2d}, {2d,5d}, {1d, 7d}};
  +        RealMatrix n = new RealMatrixImpl();
  +        n.setData(matrixData2); 
  +        // Now multiply m by n
  +        RealMatrix p = m.multiply(n);
  +        assertEquals(2, p.getRowDimension());
  +        assertEquals(2, p.getColumnDimension());
  +        // Invert p
  +        RealMatrix pInverse = p.inverse(); 
  +        assertEquals(2, pInverse.getRowDimension());
  +        assertEquals(2, pInverse.getColumnDimension());
  +        
  +        // Solve example
  +        double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
  +        RealMatrix coefficients = new RealMatrixImpl(coefficientsData);
  +        double[] constants = {1, -2, 1};
  +        double[] solution = coefficients.solve(constants);
  +        assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0],
1E-12);
  +        assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1],
1E-12);
  +        assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2],
1E-12);   
  +        
  +    }
  +    
       //--------------- -----------------Protected methods
           
       /** verifies that two matrices are close (1-norm) */              
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message