You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2013/10/22 19:49:51 UTC
svn commit: r1534709 -
/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java
Author: erans
Date: Tue Oct 22 17:49:51 2013
New Revision: 1534709
URL: http://svn.apache.org/r1534709
Log:
MATH-1045
Unit test with matrix containing only very small values.
Modified:
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java?rev=1534709&r1=1534708&r2=1534709&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java Tue Oct 22 17:49:51 2013
@@ -20,6 +20,7 @@ package org.apache.commons.math3.linear;
import java.util.Random;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
+import org.apache.commons.math3.util.Precision;
import org.junit.Test;
import org.junit.Assert;
@@ -56,6 +57,35 @@ public class EigenSolverTest {
Assert.assertEquals(0, error.getNorm(), 4.0e-15);
}
+ /**
+ * Verifies operation on very small values.
+ * Matrix with eigenvalues {8e-100, -1e-100, -1e-100}
+ */
+ @Test
+ public void testInvertibleTinyValues() {
+ final double tiny = 1e-100;
+ RealMatrix m = MatrixUtils.createRealMatrix(new double[][] {
+ {3, 2, 4},
+ {2, 0, 2},
+ {4, 2, 3}
+ });
+ m = m.scalarMultiply(tiny);
+
+ final EigenDecomposition ed = new EigenDecomposition(m);
+ RealMatrix inv = ed.getSolver().getInverse();
+
+ final RealMatrix id = m.multiply(inv);
+ for (int i = 0; i < m.getRowDimension(); i++) {
+ for (int j = 0; j < m.getColumnDimension(); j++) {
+ if (i == j) {
+ Assert.assertTrue(Precision.equals(1, id.getEntry(i, j), 1e-15));
+ } else {
+ Assert.assertTrue(Precision.equals(0, id.getEntry(i, j), 1e-15));
+ }
+ }
+ }
+ }
+
/** test solve dimension errors */
@Test
public void testSolveDimensionErrors() {