From 721444f232751d93211735a1a2f56757b74622b1 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Tue, 22 Oct 2013 17:49:51 +0000 Subject: [PATCH] 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 --- .../commons/math3/linear/EigenSolverTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java b/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java index 054137dcc..f9fe7859f 100644 --- a/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java +++ b/src/test/java/org/apache/commons/math3/linear/EigenSolverTest.java @@ -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() {