/** * Compute the eigenvalue of square matrix. * * @param matrix Input matrix A. * @return A pair of column vectors A and B s.t. each row of A + Bi is a eigenvalue of the * underlying matrix * @throws UnsupportedOperationException if unable to compute */ public Pair compute(Matrix matrix) { Throw.when() .isNull(() -> matrix, () -> "No input matrix.") .isFalse( () -> matrix.getRowCount() == matrix.getColCount(), () -> "Input matrix is not square."); switch (matrix.getRowCount()) { case 0: return Pair.EMPTY; case 1: return Pair.of(Matrices.scalar(matrix.get(0, 0)), Matrices.zeros(1)); case 2: return DoubleShift.of(matrix, 0).eig(); default: break; } return this.findEig(this.qrImpl.compute(new DefaultMatrix(matrix), null, false)); }