xref: /aosp_15_r20/external/eigen/unsupported/doc/examples/PolynomialUtils1.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li #include <unsupported/Eigen/Polynomials>
2*bf2c3715SXin Li #include <iostream>
3*bf2c3715SXin Li 
4*bf2c3715SXin Li using namespace Eigen;
5*bf2c3715SXin Li using namespace std;
6*bf2c3715SXin Li 
main()7*bf2c3715SXin Li int main()
8*bf2c3715SXin Li {
9*bf2c3715SXin Li   Vector4d roots = Vector4d::Random();
10*bf2c3715SXin Li   cout << "Roots: " << roots.transpose() << endl;
11*bf2c3715SXin Li   Eigen::Matrix<double,5,1> polynomial;
12*bf2c3715SXin Li   roots_to_monicPolynomial( roots, polynomial );
13*bf2c3715SXin Li   cout << "Polynomial: ";
14*bf2c3715SXin Li   for( int i=0; i<4; ++i ){ cout << polynomial[i] << ".x^" << i << "+ "; }
15*bf2c3715SXin Li   cout << polynomial[4] << ".x^4" << endl;
16*bf2c3715SXin Li   Vector4d evaluation;
17*bf2c3715SXin Li   for( int i=0; i<4; ++i ){
18*bf2c3715SXin Li     evaluation[i] = poly_eval( polynomial, roots[i] ); }
19*bf2c3715SXin Li   cout << "Evaluation of the polynomial at the roots: " << evaluation.transpose();
20*bf2c3715SXin Li }
21