00001 #ifndef EIGEN_POLYNOMIALS_MODULE_H 00002 #define EIGEN_POLYNOMIALS_MODULE_H 00003 00004 #include <Eigen/Core> 00005 00006 #include <Eigen/src/Core/util/DisableStupidWarnings.h> 00007 00008 #include <Eigen/Eigenvalues> 00009 00010 // Note that EIGEN_HIDE_HEAVY_CODE has to be defined per module 00011 #if (defined EIGEN_EXTERN_INSTANTIATIONS) && (EIGEN_EXTERN_INSTANTIATIONS>=2) 00012 #ifndef EIGEN_HIDE_HEAVY_CODE 00013 #define EIGEN_HIDE_HEAVY_CODE 00014 #endif 00015 #elif defined EIGEN_HIDE_HEAVY_CODE 00016 #undef EIGEN_HIDE_HEAVY_CODE 00017 #endif 00018 00019 namespace Eigen { 00020 00021 /** \ingroup Unsupported_modules 00022 * \defgroup Polynomials_Module Polynomials module 00023 * \ingroup eigen_grp 00024 * \ingroup eigen_grp 00025 * 00026 * 00027 * 00028 * \brief This module provides a QR based polynomial solver. 00029 * 00030 * To use this module, add 00031 * \code 00032 * #include <unsupported/Eigen/Polynomials> 00033 * \endcode 00034 * at the start of your source file. 00035 */ 00036 00037 #include "src/Polynomials/PolynomialUtils.h" 00038 #include "src/Polynomials/Companion.h" 00039 #include "src/Polynomials/PolynomialSolver.h" 00040 00041 /** 00042 \page polynomials Polynomials defines functions for dealing with polynomials 00043 and a QR based polynomial solver. 00044 \ingroup Polynomials_Module 00045 00046 The remainder of the page documents first the functions for evaluating, computing 00047 polynomials, computing estimates about polynomials and next the QR based polynomial 00048 solver. 00049 00050 \section polynomialUtils convenient functions to deal with polynomials 00051 \subsection roots_to_monicPolynomial 00052 The function 00053 \code 00054 void roots_to_monicPolynomial( const RootVector& rv, Polynomial& poly ) 00055 \endcode 00056 computes the coefficients \f$ a_i \f$ of 00057 00058 \f$ p(x) = a_0 + a_{1}x + ... + a_{n-1}x^{n-1} + x^n \f$ 00059 00060 where \f$ p \f$ is known through its roots i.e. \f$ p(x) = (x-r_1)(x-r_2)...(x-r_n) \f$. 00061 00062 \subsection poly_eval 00063 The function 00064 \code 00065 T poly_eval( const Polynomials& poly, const T& x ) 00066 \endcode 00067 evaluates a polynomial at a given point using stabilized Hörner method. 00068 00069 The following code: first computes the coefficients in the monomial basis of the monic polynomial that has the provided roots; 00070 then, it evaluates the computed polynomial, using a stabilized Hörner method. 00071 00072 \include PolynomialUtils1.cpp 00073 Output: \verbinclude PolynomialUtils1.out 00074 00075 \subsection Cauchy bounds 00076 The function 00077 \code 00078 Real cauchy_max_bound( const Polynomial& poly ) 00079 \endcode 00080 provides a maximum bound (the Cauchy one: \f$C(p)\f$) for the absolute value of a root of the given polynomial i.e. 00081 \f$ \forall r_i \f$ root of \f$ p(x) = \sum_{k=0}^d a_k x^k \f$, 00082 \f$ |r_i| \le C(p) = \sum_{k=0}^{d} \left | \frac{a_k}{a_d} \right | \f$ 00083 The leading coefficient \f$ p \f$: should be non zero \f$a_d \neq 0\f$. 00084 00085 00086 The function 00087 \code 00088 Real cauchy_min_bound( const Polynomial& poly ) 00089 \endcode 00090 provides a minimum bound (the Cauchy one: \f$c(p)\f$) for the absolute value of a non zero root of the given polynomial i.e. 00091 \f$ \forall r_i \neq 0 \f$ root of \f$ p(x) = \sum_{k=0}^d a_k x^k \f$, 00092 \f$ |r_i| \ge c(p) = \left( \sum_{k=0}^{d} \left | \frac{a_k}{a_0} \right | \right)^{-1} \f$ 00093 00094 00095 00096 00097 \section QR polynomial solver class 00098 Computes the complex roots of a polynomial by computing the eigenvalues of the associated companion matrix with the QR algorithm. 00099 00100 The roots of \f$ p(x) = a_0 + a_1 x + a_2 x^2 + a_{3} x^3 + x^4 \f$ are the eigenvalues of 00101 \f$ 00102 \left [ 00103 \begin{array}{cccc} 00104 0 & 0 & 0 & a_0 \\ 00105 1 & 0 & 0 & a_1 \\ 00106 0 & 1 & 0 & a_2 \\ 00107 0 & 0 & 1 & a_3 00108 \end{array} \right ] 00109 \f$ 00110 00111 However, the QR algorithm is not guaranteed to converge when there are several eigenvalues with same modulus. 00112 00113 Therefore the current polynomial solver is guaranteed to provide a correct result only when the complex roots \f$r_1,r_2,...,r_d\f$ have distinct moduli i.e. 00114 00115 \f$ \forall i,j \in [1;d],~ \| r_i \| \neq \| r_j \| \f$. 00116 00117 With 32bit (float) floating types this problem shows up frequently. 00118 However, almost always, correct accuracy is reached even in these cases for 64bit 00119 (double) floating types and small polynomial degree (<20). 00120 00121 \include PolynomialSolver1.cpp 00122 00123 In the above example: 00124 00125 -# a simple use of the polynomial solver is shown; 00126 -# the accuracy problem with the QR algorithm is presented: a polynomial with almost conjugate roots is provided to the solver. 00127 Those roots have almost same module therefore the QR algorithm failed to converge: the accuracy 00128 of the last root is bad; 00129 -# a simple way to circumvent the problem is shown: use doubles instead of floats. 00130 00131 Output: \verbinclude PolynomialSolver1.out 00132 */ 00133 00134 } // namespace Eigen 00135 00136 #include <Eigen/src/Core/util/ReenableStupidWarnings.h> 00137 00138 #endif // EIGEN_POLYNOMIALS_MODULE_H 00139 /* vim: set filetype=cpp et sw=2 ts=2 ai: */
| Page generated by Doxygen 1.7.4 for MRPT 0.9.5 SVN:2717 at Sun Oct 16 16:08:03 PDT 2011 | Hosted on: |