Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/eigen3/unsupported/Eigen/Polynomials is written in an unsupported language. File is not indexed.

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla
0006 // Public License v. 2.0. If a copy of the MPL was not distributed
0007 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #ifndef EIGEN_POLYNOMIALS_MODULE_H
0010 #define EIGEN_POLYNOMIALS_MODULE_H
0011 
0012 #include "../../Eigen/Core"
0013 
0014 #include "../../Eigen/Eigenvalues"
0015 
0016 #include "../../Eigen/src/Core/util/DisableStupidWarnings.h"
0017 
0018 // Note that EIGEN_HIDE_HEAVY_CODE has to be defined per module
0019 #if (defined EIGEN_EXTERN_INSTANTIATIONS) && (EIGEN_EXTERN_INSTANTIATIONS>=2)
0020   #ifndef EIGEN_HIDE_HEAVY_CODE
0021   #define EIGEN_HIDE_HEAVY_CODE
0022   #endif
0023 #elif defined EIGEN_HIDE_HEAVY_CODE
0024   #undef EIGEN_HIDE_HEAVY_CODE
0025 #endif
0026 
0027 /**
0028   * \defgroup Polynomials_Module Polynomials module
0029   * \brief This module provides a QR based polynomial solver.
0030         *
0031   * To use this module, add
0032   * \code
0033   * #include <unsupported/Eigen/Polynomials>
0034   * \endcode
0035         * at the start of your source file.
0036   */
0037 
0038 #include "src/Polynomials/PolynomialUtils.h"
0039 #include "src/Polynomials/Companion.h"
0040 #include "src/Polynomials/PolynomialSolver.h"
0041 
0042 /**
0043         \page polynomials Polynomials defines functions for dealing with polynomials
0044         and a QR based polynomial solver.
0045         \ingroup Polynomials_Module
0046 
0047         The remainder of the page documents first the functions for evaluating, computing
0048         polynomials, computing estimates about polynomials and next the QR based polynomial
0049         solver.
0050 
0051         \section polynomialUtils convenient functions to deal with polynomials
0052         \subsection roots_to_monicPolynomial
0053         The function
0054         \code
0055         void roots_to_monicPolynomial( const RootVector& rv, Polynomial& poly )
0056         \endcode
0057         computes the coefficients \f$ a_i \f$ of
0058 
0059         \f$ p(x) = a_0 + a_{1}x + ... + a_{n-1}x^{n-1} + x^n \f$
0060 
0061         where \f$ p \f$ is known through its roots i.e. \f$ p(x) = (x-r_1)(x-r_2)...(x-r_n) \f$.
0062 
0063         \subsection poly_eval
0064         The function
0065         \code
0066         T poly_eval( const Polynomials& poly, const T& x )
0067         \endcode
0068         evaluates a polynomial at a given point using stabilized H&ouml;rner method.
0069 
0070         The following code: first computes the coefficients in the monomial basis of the monic polynomial that has the provided roots;
0071         then, it evaluates the computed polynomial, using a stabilized H&ouml;rner method.
0072 
0073         \include PolynomialUtils1.cpp
0074   Output: \verbinclude PolynomialUtils1.out
0075 
0076         \subsection Cauchy bounds
0077         The function
0078         \code
0079         Real cauchy_max_bound( const Polynomial& poly )
0080         \endcode
0081         provides a maximum bound (the Cauchy one: \f$C(p)\f$) for the absolute value of a root of the given polynomial i.e.
0082         \f$ \forall r_i \f$ root of \f$ p(x) = \sum_{k=0}^d a_k x^k \f$,
0083         \f$ |r_i| \le C(p) = \sum_{k=0}^{d} \left | \frac{a_k}{a_d} \right | \f$
0084         The leading coefficient \f$ p \f$: should be non zero \f$a_d \neq 0\f$.
0085 
0086 
0087         The function
0088         \code
0089         Real cauchy_min_bound( const Polynomial& poly )
0090         \endcode
0091         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.
0092         \f$ \forall r_i \neq 0 \f$ root of \f$ p(x) = \sum_{k=0}^d a_k x^k \f$,
0093         \f$ |r_i| \ge c(p) = \left( \sum_{k=0}^{d} \left | \frac{a_k}{a_0} \right | \right)^{-1} \f$
0094 
0095 
0096 
0097 
0098         \section QR polynomial solver class
0099         Computes the complex roots of a polynomial by computing the eigenvalues of the associated companion matrix with the QR algorithm.
0100         
0101         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
0102         \f$
0103         \left [
0104         \begin{array}{cccc}
0105         0 & 0 &  0 & a_0 \\
0106         1 & 0 &  0 & a_1 \\
0107         0 & 1 &  0 & a_2 \\
0108         0 & 0 &  1 & a_3
0109         \end{array} \right ]
0110         \f$
0111 
0112         However, the QR algorithm is not guaranteed to converge when there are several eigenvalues with same modulus.
0113 
0114         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.
0115         
0116         \f$ \forall i,j \in [1;d],~ \| r_i \| \neq \| r_j \| \f$.
0117 
0118         With 32bit (float) floating types this problem shows up frequently.
0119   However, almost always, correct accuracy is reached even in these cases for 64bit
0120   (double) floating types and small polynomial degree (<20).
0121 
0122         \include PolynomialSolver1.cpp
0123         
0124         In the above example:
0125         
0126         -# a simple use of the polynomial solver is shown;
0127         -# the accuracy problem with the QR algorithm is presented: a polynomial with almost conjugate roots is provided to the solver.
0128         Those roots have almost same module therefore the QR algorithm failed to converge: the accuracy
0129         of the last root is bad;
0130         -# a simple way to circumvent the problem is shown: use doubles instead of floats.
0131 
0132   Output: \verbinclude PolynomialSolver1.out
0133 */
0134 
0135 #include "../../Eigen/src/Core/util/ReenableStupidWarnings.h"
0136 
0137 #endif // EIGEN_POLYNOMIALS_MODULE_H