3 #include <eigen3/Eigen/Dense>
4 #include <eigen3/Eigen/Eigenvalues>
15 using Index = Eigen::MatrixXd::Index;
17 std::size_t degree = coeffs.size() - 1;
18 Eigen::MatrixXd m = Eigen::MatrixXd::Zero(Index(degree + 1), Index(degree + 1));
19 m(0, Index(degree)) = -coeffs[0] / coeffs[degree];
20 for (std::size_t i = 1; i <= degree; ++i) {
21 m(Index(i), Index(i)-1) = 1;
22 m(Index(i), Index(degree)) = -coeffs[i] / coeffs[degree];
26 Eigen::VectorXcd eigenvalues = m.eigenvalues();
29 std::vector<double> tmp;
30 for (
uint i = 0; i < std::size_t(eigenvalues.size()); ++i) {
31 if (!std::isfinite(eigenvalues[Index(i)].real()) || !std::isfinite(eigenvalues[Index(i)].imag())) {
34 if (eigenvalues[Index(i)].imag() < eigenvalues[Index(i)].real() / 4) {
35 tmp.emplace_back(eigenvalues[Index(i)].real());
carl is the main namespace for the library.
std::vector< double > root_approximation(const std::vector< double > &coeffs)
Compute approximations of the real roots of the univariate polynomials with the given coefficients.