/** * Compute the generalised eigenvalues, L, of the problem A x = L B x. * The returned eigenvalues are not ordered. * * @param A symmetric Matrix A; only the upper triangle is used. * @param B symmetric Matrix B; only the upper triangle is used. * @return the eigenvalues L. */ public static DenseVector symmetricGeneralisedEigenvalues(DenseMatrix A, DenseMatrix B) { if (!A.isSquare() || !B.isSquare()) throw new IllegalArgumentException("Input matrices must be square"); DenseVector W = new DenseVector(A.numRows()); sygvd(1, "N", "U", A.copy(), B.copy(), W); return W; }
/** * Solve the general problem A x = L B x. * The returned eigenvalues are not ordered. * * @param A symmetric matrix A * @param B symmetric matrix B * @return The eigenvectors x and eigenvalues L. */ public static IndependentPair<DenseMatrix, DenseVector> symmetricGeneralisedEigenvectors(DenseMatrix A, DenseMatrix B) { if (!A.isSquare() || !B.isSquare()) throw new IllegalArgumentException("Input matrices must be square"); DenseMatrix vecs = A.copy(); DenseVector W = new DenseVector(A.numRows()); sygvd(1, "V", "U", vecs, B.copy(), W); return new IndependentPair<DenseMatrix, DenseVector>(vecs, W); }
@Override public Matrix solve(Matrix B, Matrix X) { // We allow non-square matrices, as we then use a least-squares solver if (numRows != B.numRows()) throw new IllegalArgumentException("numRows != B.numRows() (" + numRows + " != " + B.numRows() + ")"); if (numColumns != X.numRows()) throw new IllegalArgumentException("numColumns != X.numRows() (" + numColumns + " != " + X.numRows() + ")"); if (X.numColumns() != B.numColumns()) throw new IllegalArgumentException( "X.numColumns() != B.numColumns() (" + X.numColumns() + " != " + B.numColumns() + ")"); if (isSquare()) return LUsolve(B, X); else return QRsolve(B, X, Transpose.NoTranspose); }
@Override public Matrix solve(Matrix B, Matrix X) { // We allow non-square matrices, as we then use a least-squares solver if (numRows != B.numRows()) throw new IllegalArgumentException("numRows != B.numRows() (" + numRows + " != " + B.numRows() + ")"); if (numColumns != X.numRows()) throw new IllegalArgumentException("numColumns != X.numRows() (" + numColumns + " != " + X.numRows() + ")"); if (X.numColumns() != B.numColumns()) throw new IllegalArgumentException( "X.numColumns() != B.numColumns() (" + X.numColumns() + " != " + B.numColumns() + ")"); if (isSquare()) return LUsolve(B, X); else return QRsolve(B, X, Transpose.NoTranspose); }
/** * Computes the eigenvalue decomposition of the given matrix * * @param A * Matrix to factorize. Overwritten on return * @return The current decomposition * @throws NotConvergedException */ public EVD factor(DenseMatrix A) throws NotConvergedException { if (!A.isSquare()) throw new IllegalArgumentException("!A.isSquare()"); else if (A.numRows() != n) throw new IllegalArgumentException("A.numRows() != n"); intW info = new intW(0); LAPACK.getInstance().dgeev(jobLeft.netlib(), jobRight.netlib(), n, A.getData(), Matrices.ld(n), Wr, Wi, jobLeft == JobEig.All ? Vl.getData() : new double[0], Matrices.ld(n), jobRight == JobEig.All ? Vr.getData() : new double[0], Matrices.ld(n), work, work.length, info); if (info.val > 0) throw new NotConvergedException( NotConvergedException.Reason.Iterations); else if (info.val < 0) throw new IllegalArgumentException(); return this; }
/** * Computes the eigenvalue decomposition of the given matrix * * @param A * Matrix to factorize. Overwritten on return * @return The current decomposition * @throws NotConvergedException */ public EVD factor(DenseMatrix A) throws NotConvergedException { if (!A.isSquare()) throw new IllegalArgumentException("!A.isSquare()"); else if (A.numRows() != n) throw new IllegalArgumentException("A.numRows() != n"); intW info = new intW(0); LAPACK.getInstance().dgeev(jobLeft.netlib(), jobRight.netlib(), n, A.getData(), Matrices.ld(n), Wr, Wi, jobLeft == JobEig.All ? Vl.getData() : new double[0], Matrices.ld(n), jobRight == JobEig.All ? Vr.getData() : new double[0], Matrices.ld(n), work, work.length, info); if (info.val > 0) throw new NotConvergedException( NotConvergedException.Reason.Iterations); else if (info.val < 0) throw new IllegalArgumentException(); return this; }