MATH-1045
Unit test with matrix containing only very small values. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1534709 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e5f5a2dbaa
commit
721444f232
|
@ -20,6 +20,7 @@ package org.apache.commons.math3.linear;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||||
|
import org.apache.commons.math3.util.Precision;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -56,6 +57,35 @@ public class EigenSolverTest {
|
||||||
Assert.assertEquals(0, error.getNorm(), 4.0e-15);
|
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 solve dimension errors */
|
||||||
@Test
|
@Test
|
||||||
public void testSolveDimensionErrors() {
|
public void testSolveDimensionErrors() {
|
||||||
|
|
Loading…
Reference in New Issue