You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/07/23 22:19:53 UTC
svn commit: r1364783 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java
Author: tn
Date: Mon Jul 23 20:19:52 2012
New Revision: 1364783
URL: http://svn.apache.org/viewvc?rev=1364783&view=rev
Log:
[MATH-235] Added a hasComplexEigenvalues method.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java?rev=1364783&r1=1364782&r2=1364783&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/linear/EigenDecomposition.java Mon Jul 23 20:19:52 2012
@@ -279,6 +279,24 @@ public class EigenDecomposition {
}
/**
+ * Returns whether the calculated eigen values are complex or real.
+ * <p>The method performs a zero check for each element of the
+ * {@link #getImagEigenvalues()} array and returns {@code true} if any
+ * element is not equal to zero.
+ *
+ * @return {@code true} if the eigen values are complex, {@code false} otherwise
+ * @since 3.1
+ */
+ public boolean hasComplexEigenvalues() {
+ for (int i = 0; i < imagEigenvalues.length; i++) {
+ if (!Precision.equals(imagEigenvalues[i], 0.0, epsilon)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Gets a copy of the real parts of the eigenvalues of the original matrix.
*
* @return a copy of the real parts of the eigenvalues of the original matrix.
@@ -374,10 +392,8 @@ public class EigenDecomposition {
* complex eigenvalues
*/
public DecompositionSolver getSolver() {
- for (int i = 0; i < imagEigenvalues.length; i++) {
- if (imagEigenvalues[i] != 0.0) {
- throw new MathUnsupportedOperationException();
- }
+ if (hasComplexEigenvalues()) {
+ throw new MathUnsupportedOperationException();
}
return new Solver(realEigenvalues, imagEigenvalues, eigenvectors);
}