Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_POLYNOMIAL_UTILS_H
00026 #define EIGEN_POLYNOMIAL_UTILS_H
00027
00039 template <typename Polynomials, typename T>
00040 inline
00041 T poly_eval_horner( const Polynomials& poly, const T& x )
00042 {
00043 T val=poly[poly.size()-1];
00044 for(DenseIndex i=poly.size()-2; i>=0; --i ){
00045 val = val*x + poly[i]; }
00046 return val;
00047 }
00048
00057 template <typename Polynomials, typename T>
00058 inline
00059 T poly_eval( const Polynomials& poly, const T& x )
00060 {
00061 typedef typename NumTraits<T>::Real Real;
00062
00063 if( internal::abs2( x ) <= Real(1) ){
00064 return poly_eval_horner( poly, x ); }
00065 else
00066 {
00067 T val=poly[0];
00068 T inv_x = T(1)/x;
00069 for( DenseIndex i=1; i<poly.size(); ++i ){
00070 val = val*inv_x + poly[i]; }
00071
00072 return std::pow(x,(T)(poly.size()-1)) * val;
00073 }
00074 }
00075
00086 template <typename Polynomial>
00087 inline
00088 typename NumTraits<typename Polynomial::Scalar>::Real cauchy_max_bound( const Polynomial& poly )
00089 {
00090 typedef typename Polynomial::Scalar Scalar;
00091 typedef typename NumTraits<Scalar>::Real Real;
00092
00093 assert( Scalar(0) != poly[poly.size()-1] );
00094 const Scalar inv_leading_coeff = Scalar(1)/poly[poly.size()-1];
00095 Real cb(0);
00096
00097 for( DenseIndex i=0; i<poly.size()-1; ++i ){
00098 cb += internal::abs(poly[i]*inv_leading_coeff); }
00099 return cb + Real(1);
00100 }
00101
00108 template <typename Polynomial>
00109 inline
00110 typename NumTraits<typename Polynomial::Scalar>::Real cauchy_min_bound( const Polynomial& poly )
00111 {
00112 typedef typename Polynomial::Scalar Scalar;
00113 typedef typename NumTraits<Scalar>::Real Real;
00114
00115 DenseIndex i=0;
00116 while( i<poly.size()-1 && Scalar(0) == poly(i) ){ ++i; }
00117 if( poly.size()-1 == i ){
00118 return Real(1); }
00119
00120 const Scalar inv_min_coeff = Scalar(1)/poly[i];
00121 Real cb(1);
00122 for( DenseIndex j=i+1; j<poly.size(); ++j ){
00123 cb += internal::abs(poly[j]*inv_min_coeff); }
00124 return Real(1)/cb;
00125 }
00126
00137 template <typename RootVector, typename Polynomial>
00138 void roots_to_monicPolynomial( const RootVector& rv, Polynomial& poly )
00139 {
00140
00141 typedef typename Polynomial::Scalar Scalar;
00142
00143 poly.setZero( rv.size()+1 );
00144 poly[0] = -rv[0]; poly[1] = Scalar(1);
00145 for( DenseIndex i=1; i< rv.size(); ++i )
00146 {
00147 for( DenseIndex j=i+1; j>0; --j ){ poly[j] = poly[j-1] - rv[i]*poly[j]; }
00148 poly[0] = -rv[i]*poly[0];
00149 }
00150 }
00151
00152
00153 #endif // EIGEN_POLYNOMIAL_UTILS_H