mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-05-02 00:34:14 +08:00
PolynomialSolver: fix bugs related to linear polynomials.
This commit is contained in:
parent
df92649379
commit
eda79321be
@ -41,7 +41,7 @@ class PolynomialSolverBase
|
||||
protected:
|
||||
template< typename OtherPolynomial >
|
||||
inline void setPolynomial( const OtherPolynomial& poly ){
|
||||
m_roots.resize(poly.size()); }
|
||||
m_roots.resize(poly.size()-1); }
|
||||
|
||||
public:
|
||||
template< typename OtherPolynomial >
|
||||
@ -345,11 +345,20 @@ class PolynomialSolver : public PolynomialSolverBase<_Scalar,_Deg>
|
||||
void compute( const OtherPolynomial& poly )
|
||||
{
|
||||
eigen_assert( Scalar(0) != poly[poly.size()-1] );
|
||||
eigen_assert( poly.size() > 1 );
|
||||
if(poly.size() > 2 )
|
||||
{
|
||||
internal::companion<Scalar,_Deg> companion( poly );
|
||||
companion.balance();
|
||||
m_eigenSolver.compute( companion.denseMatrix() );
|
||||
m_roots = m_eigenSolver.eigenvalues();
|
||||
}
|
||||
else if(poly.size () == 2)
|
||||
{
|
||||
m_roots.resize(1);
|
||||
m_roots[0] = -poly[0]/poly[1];
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
template< typename OtherPolynomial >
|
||||
@ -376,8 +385,9 @@ class PolynomialSolver<_Scalar,1> : public PolynomialSolverBase<_Scalar,1>
|
||||
template< typename OtherPolynomial >
|
||||
void compute( const OtherPolynomial& poly )
|
||||
{
|
||||
eigen_assert( Scalar(0) != poly[poly.size()-1] );
|
||||
m_roots[0] = -poly[0]/poly[poly.size()-1];
|
||||
eigen_assert( poly.size() == 2 );
|
||||
eigen_assert( Scalar(0) != poly[1] );
|
||||
m_roots[0] = -poly[0]/poly[1];
|
||||
}
|
||||
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user