PolynomialUtils.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2010 Manuel Yguel <manuel.yguel@gmail.com>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_POLYNOMIAL_UTILS_H
00011 #define EIGEN_POLYNOMIAL_UTILS_H
00012 
00013 namespace Eigen { 
00014 
00026 template <typename Polynomials, typename T>
00027 inline
00028 T poly_eval_horner( const Polynomials& poly, const T& x )
00029 {
00030   T val=poly[poly.size()-1];
00031   for(DenseIndex i=poly.size()-2; i>=0; --i ){
00032     val = val*x + poly[i]; }
00033   return val;
00034 }
00035 
00044 template <typename Polynomials, typename T>
00045 inline
00046 T poly_eval( const Polynomials& poly, const T& x )
00047 {
00048   typedef typename NumTraits<T>::Real Real;
00049 
00050   if( internal::abs2( x ) <= Real(1) ){
00051     return poly_eval_horner( poly, x ); }
00052   else
00053   {
00054     T val=poly[0];
00055     T inv_x = T(1)/x;
00056     for( DenseIndex i=1; i<poly.size(); ++i ){
00057       val = val*inv_x + poly[i]; }
00058 
00059     return std::pow(x,(T)(poly.size()-1)) * val;
00060   }
00061 }
00062 
00073 template <typename Polynomial>
00074 inline
00075 typename NumTraits<typename Polynomial::Scalar>::Real cauchy_max_bound( const Polynomial& poly )
00076 {
00077   typedef typename Polynomial::Scalar Scalar;
00078   typedef typename NumTraits<Scalar>::Real Real;
00079 
00080   assert( Scalar(0) != poly[poly.size()-1] );
00081   const Scalar inv_leading_coeff = Scalar(1)/poly[poly.size()-1];
00082   Real cb(0);
00083 
00084   for( DenseIndex i=0; i<poly.size()-1; ++i ){
00085     cb += internal::abs(poly[i]*inv_leading_coeff); }
00086   return cb + Real(1);
00087 }
00088 
00095 template <typename Polynomial>
00096 inline
00097 typename NumTraits<typename Polynomial::Scalar>::Real cauchy_min_bound( const Polynomial& poly )
00098 {
00099   typedef typename Polynomial::Scalar Scalar;
00100   typedef typename NumTraits<Scalar>::Real Real;
00101 
00102   DenseIndex i=0;
00103   while( i<poly.size()-1 && Scalar(0) == poly(i) ){ ++i; }
00104   if( poly.size()-1 == i ){
00105     return Real(1); }
00106 
00107   const Scalar inv_min_coeff = Scalar(1)/poly[i];
00108   Real cb(1);
00109   for( DenseIndex j=i+1; j<poly.size(); ++j ){
00110     cb += internal::abs(poly[j]*inv_min_coeff); }
00111   return Real(1)/cb;
00112 }
00113 
00124 template <typename RootVector, typename Polynomial>
00125 void roots_to_monicPolynomial( const RootVector& rv, Polynomial& poly )
00126 {
00127 
00128   typedef typename Polynomial::Scalar Scalar;
00129 
00130   poly.setZero( rv.size()+1 );
00131   poly[0] = -rv[0]; poly[1] = Scalar(1);
00132   for( DenseIndex i=1; i< rv.size(); ++i )
00133   {
00134     for( DenseIndex j=i+1; j>0; --j ){ poly[j] = poly[j-1] - rv[i]*poly[j]; }
00135     poly[0] = -rv[i]*poly[0];
00136   }
00137 }
00138 
00139 } // end namespace Eigen
00140 
00141 #endif // EIGEN_POLYNOMIAL_UTILS_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:25:44