Skip to content

Avoid exception "org.hipparchus.exception.MathIllegalArgumentException: matrix is singular" for complex implementations #337

@axkr

Description

@axkr

The EigenDecompositionNonSymmetricimplementation returns a result without an exception.

Can the exception org.hipparchus.exception.MathIllegalArgumentException: matrix is singular also be avoided for the "Complex implementations" ComplexEigenDecomposition and OrderedComplexEigenDecomposition?

@Test
  public void testEqualEigenValuesSingular() {
    Array2DRowRealMatrix matrix =
        new Array2DRowRealMatrix(new double[][] {{1, 0, 0}, {-2, 1, 0}, {0, 1, 1}});
    EigenDecompositionNonSymmetric ed = new EigenDecompositionNonSymmetric(matrix);
    for (int i = 0; i < 3; i++) {
      System.out.println(ed.getEigenvector(i));
    }

    try {
      ComplexEigenDecomposition complexEigenDecomposition = new ComplexEigenDecomposition(matrix);
      for (int i = 0; i < 3; i++) {
        System.out.println(complexEigenDecomposition.getEigenvector(i));
      }
    } catch (MathRuntimeException mre) {
      mre.printStackTrace();
    }

    try {
      ComplexEigenDecomposition ced = new OrderedComplexEigenDecomposition(matrix, //
          ComplexEigenDecomposition.DEFAULT_EIGENVECTORS_EQUALITY, //
          ComplexEigenDecomposition.DEFAULT_EPSILON, //
          ComplexEigenDecomposition.DEFAULT_EPSILON_AV_VD_CHECK, //
          (c1, c2) -> Double.compare(c2.norm(), c1.norm()));
      for (int i = 0; i < 3; i++) {
        System.out.println(ced.getEigenvector(i));
      }
    } catch (MathRuntimeException mre) {
      mre.printStackTrace();
    }
  }

See:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions