32 #define TEST_NAME "base/polynomial"
39 #define CHECK_EQUAL_RESULT(find_func1, coeffs1, find_func2, coeffs2) \
41 Eigen::VectorXd real1; \
42 Eigen::VectorXd imag1; \
43 const bool success1 = find_func1(coeffs1, &real1, &imag1); \
44 Eigen::VectorXd real2; \
45 Eigen::VectorXd imag2; \
46 const bool success2 = find_func2(coeffs2, &real2, &imag2); \
47 BOOST_CHECK_EQUAL(success1, success2); \
49 BOOST_CHECK_EQUAL(real1, real2); \
50 BOOST_CHECK_EQUAL(imag1, imag2); \
56 (Eigen::VectorXd(5) << 1, -3, 3, -5, 10).finished(), 1),
60 1 * 2 * 2 * 2 - 3 * 2 * 2 + 3 * 2 - 5, 1
e-6);
67 BOOST_CHECK_EQUAL(real(0), 2.0 / 3.0);
68 BOOST_CHECK_EQUAL(imag(0), 0);
70 std::complex<double>(real(0), imag(0)))
74 std::complex<double>(real(0), imag(0)))
84 Eigen::Vector3d
coeffs(3, -2, -4);
86 BOOST_CHECK(real.isApprox(Eigen::Vector2d(-0.868517092, 1.535183758), 1
e-6));
87 BOOST_CHECK_EQUAL(imag, Eigen::Vector2d(0, 0));
99 const Eigen::Vector3d
coeffs(0.276025076998578, 0.679702676853675,
102 BOOST_CHECK(real.isApprox(
103 Eigen::Vector2d(-1.231233560813707, -1.231233560813707), 1
e-6));
104 BOOST_CHECK(imag.isApprox(
105 Eigen::Vector2d(0.925954520440279, -0.925954520440279), 1
e-6));
115 Eigen::VectorXd real;
116 Eigen::VectorXd imag;
117 Eigen::VectorXd
coeffs(5);
118 coeffs << 10, -5, 3, -3, 1;
121 Eigen::VectorXd ref_real(4);
122 ref_real << -0.201826, -0.201826, 0.451826, 0.451826;
123 BOOST_CHECK(real.isApprox(ref_real, 1
e-6));
124 Eigen::VectorXd ref_imag(4);
125 ref_imag << -0.627696, 0.627696, 0.160867, -0.160867;
126 BOOST_CHECK(imag.isApprox(ref_imag, 1
e-6));
133 (Eigen::VectorXd(4) << 0, 0, 1, 2).finished(),
138 (Eigen::VectorXd(5) << 0, 0, 1, 2, 3).finished(),
143 Eigen::VectorXd real;
144 Eigen::VectorXd imag;
145 Eigen::VectorXd
coeffs(5);
146 coeffs << 10, -5, 3, -3, 1;
149 Eigen::VectorXd ref_real(4);
150 ref_real << -0.201826, -0.201826, 0.451826, 0.451826;
151 BOOST_CHECK(real.isApprox(ref_real, 1
e-6));
152 Eigen::VectorXd ref_imag(4);
153 ref_imag << 0.627696, -0.627696, 0.160867, -0.160867;
154 BOOST_CHECK(imag.isApprox(ref_imag, 1
e-6));
161 (Eigen::VectorXd(4) << 0, 0, 1, 2).finished(),
165 Eigen::Vector3d(1, 2, 3));
167 (Eigen::VectorXd(5) << 0, 0, 1, 2, 3).finished(),
172 Eigen::VectorXd real;
173 Eigen::VectorXd imag;
174 Eigen::VectorXd
coeffs(5);
175 coeffs << 10, -5, 3, -3, 0;
178 Eigen::VectorXd ref_real(4);
179 ref_real << 0.692438, -0.0962191, -0.0962191, 0;
180 BOOST_CHECK(real.isApprox(ref_real, 1
e-6));
181 Eigen::VectorXd ref_imag(4);
182 ref_imag << 0, 0.651148, -0.651148, 0;
183 BOOST_CHECK(imag.isApprox(ref_imag, 1
e-6));
bool FindPolynomialRootsCompanionMatrix(const Eigen::VectorXd &coeffs_all, Eigen::VectorXd *real, Eigen::VectorXd *imag)
bool FindLinearPolynomialRoots(const Eigen::VectorXd &coeffs, Eigen::VectorXd *real, Eigen::VectorXd *imag)
bool FindQuadraticPolynomialRoots(const Eigen::VectorXd &coeffs, Eigen::VectorXd *real, Eigen::VectorXd *imag)
bool FindPolynomialRootsDurandKerner(const Eigen::VectorXd &coeffs_all, Eigen::VectorXd *real, Eigen::VectorXd *imag)
T EvaluatePolynomial(const Eigen::VectorXd &coeffs, const T &x)
BOOST_AUTO_TEST_CASE(TestEvaluatePolynomial)
#define CHECK_EQUAL_RESULT(find_func1, coeffs1, find_func2, coeffs2)