EigenDecomposition { public RealMatrix getSquareRoot() { if (!isSymmetric) { throw new MathUnsupportedOperationException(); } final double[] sqrtEigenValues = new double[realEigenvalues.length]; for (int i = 0; i < realEigenvalues.length; i++) { final double eigen = realEigenvalues[i]; if (eigen <= 0) { throw new MathUnsupportedOperationException(); } sqrtEigenValues[i] = FastMath.sqrt(eigen); } final RealMatrix sqrtEigen = MatrixUtils.createRealDiagonalMatrix(sqrtEigenValues); final RealMatrix v = getV(); final RealMatrix vT = getVT(); return v.multiply(sqrtEigen).multiply(vT); } EigenDecomposition(final RealMatrix matrix); @Deprecated  EigenDecomposition(final RealMatrix matrix,
                              final double splitTolerance);  EigenDecomposition(final double[] main, final double[] secondary); @Deprecated  EigenDecomposition(final double[] main, final double[] secondary,
                              final double splitTolerance); RealMatrix getV(); RealMatrix getD(); RealMatrix getVT(); boolean hasComplexEigenvalues(); double[] getRealEigenvalues(); double getRealEigenvalue(final int i); double[] getImagEigenvalues(); double getImagEigenvalue(final int i); RealVector getEigenvector(final int i); double getDeterminant(); RealMatrix getSquareRoot(); DecompositionSolver getSolver();  }
@Test public void testSquareRoot() { final double[][] data = { { 33, 24, 7 }, { 24, 57, 11 }, { 7, 11, 9 } }; final EigenDecomposition dec = new EigenDecomposition(MatrixUtils.createRealMatrix(data)); final RealMatrix sqrtM = dec.getSquareRoot(); final RealMatrix m = sqrtM.multiply(sqrtM); final int dim = data.length; for (int r = 0; r < dim; r++) { for (int c = 0; c < dim; c++) { Assert.assertEquals("m[" + r + "][" + c + "]", data[r][c], m.getEntry(r, c), 1e-13); } } }
@Test(expected=MathUnsupportedOperationException.class) public void testSquareRootNonSymmetric() { final double[][] data = { { 1, 2, 4 }, { 2, 3, 5 }, { 11, 5, 9 } }; final EigenDecomposition dec = new EigenDecomposition(MatrixUtils.createRealMatrix(data)); @SuppressWarnings("unused") final RealMatrix sqrtM = dec.getSquareRoot(); }
@Test(expected=MathUnsupportedOperationException.class) public void testSquareRootNonPositiveDefinite() { final double[][] data = { { 1, 2, 4 }, { 2, 3, 5 }, { 4, 5, -9 } }; final EigenDecomposition dec = new EigenDecomposition(MatrixUtils.createRealMatrix(data)); @SuppressWarnings("unused") final RealMatrix sqrtM = dec.getSquareRoot(); }