List of usage examples for org.apache.commons.math.linear EigenDecomposition getImagEigenvalues
double[] getImagEigenvalues();
From source file:com.opengamma.analytics.math.matrix.CommonsMatrixAlgebra.java
/** * Returns a real matrix raised to some real power * Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices * @param m The <strong>symmetric</strong> matrix to take the power of. * @param p The power to raise to matrix to * @return The result/*from www .j av a 2 s . c o m*/ */ @Override public DoubleMatrix2D getPower(final Matrix<?> m, final double p) { if (m instanceof DoubleMatrix2D) { final RealMatrix temp = CommonsMathWrapper.wrap((DoubleMatrix2D) m); final EigenDecomposition eigen = new EigenDecompositionImpl(temp, 0.0); final double[] rEigenValues = eigen.getRealEigenvalues(); final double[] iEigenValues = eigen.getImagEigenvalues(); final int n = rEigenValues.length; final double[][] d = new double[n][n]; for (int i = n - 1; i >= 0; --i) { d[i][i] = Math.pow(rEigenValues[i], p); if (iEigenValues[i] != 0.0) { throw new NotImplementedException("Cannot handle complex eigenvalues in getPower"); } } final RealMatrix res = eigen.getV().multiply((new Array2DRowRealMatrix(d)).multiply(eigen.getVT())); return CommonsMathWrapper.unwrap(res); } throw new IllegalArgumentException("Can only find pow of DoubleMatrix2D; have " + m.getClass()); }