00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef WM4POLYNOMIALROOTS_H
00018 #define WM4POLYNOMIALROOTS_H
00019
00020 #include "Wm4FoundationLIB.h"
00021 #include "Wm4GMatrix.h"
00022 #include "Wm4Vector3.h"
00023 #include "Wm4Polynomial1.h"
00024
00025 namespace Wm4
00026 {
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 template <class Real>
00049 class WM4_FOUNDATION_ITEM PolynomialRoots
00050 {
00051 public:
00052
00053 PolynomialRoots (Real fEpsilon);
00054 ~PolynomialRoots ();
00055
00056
00057 int GetCount () const;
00058 const Real* GetRoots () const;
00059 Real GetRoot (int i) const;
00060 Real& Epsilon ();
00061 Real Epsilon () const;
00062
00063
00064 int& MaxIterations ();
00065 int MaxIterations () const;
00066
00067
00068 bool FindA (Real fC0, Real fC1);
00069 Real GetBound (Real fC0, Real fC1);
00070
00071
00072 bool FindA (Real fC0, Real fC1, Real fC2);
00073 Real GetBound (Real fC0, Real fC1, Real fC2);
00074
00075
00076 bool FindA (Real fC0, Real fC1, Real fC2, Real fC3);
00077 bool FindE (Real fC0, Real fC1, Real fC2, Real fC3, bool bDoBalancing);
00078 Real GetBound (Real fC0, Real fC1, Real fC2, Real fC3);
00079
00080
00081
00082 Real SpecialCubic (Real fA, Real fB, Real fC);
00083
00084
00085 bool FindA (Real fC0, Real fC1, Real fC2, Real fC3, Real fC4);
00086 bool FindE (Real fC0, Real fC1, Real fC2, Real fC3, Real fC4,
00087 bool bDoBalancing);
00088 Real GetBound (Real fC0, Real fC1, Real fC2, Real fC3, Real fC4);
00089
00090
00091 bool FindB (const Polynomial1<Real>& rkPoly, int iDigits);
00092 bool FindN (const Polynomial1<Real>& rkPoly, int iDigits);
00093 bool FindE (const Polynomial1<Real>& rkPoly, bool bDoBalancing);
00094 Real GetBound (const Polynomial1<Real>& rkPoly);
00095
00096
00097 bool FindB (const Polynomial1<Real>& rkPoly, Real fXMin, Real fXMax,
00098 int iDigits);
00099
00100 bool FindN (const Polynomial1<Real>& rkPoly, Real fXMin, Real fXMax,
00101 int iDigits);
00102
00103 bool AllRealPartsNegative (const Polynomial1<Real>& rkPoly);
00104 bool AllRealPartsPositive (const Polynomial1<Real>& rkPoly);
00105
00106
00107
00108
00109
00110
00111
00112 int GetRootCount (const Polynomial1<Real>& rkPoly, Real fT0, Real fT1);
00113
00114 private:
00115
00116 bool Bisection (const Polynomial1<Real>& rkPoly, Real fXMin, Real fXMax,
00117 int iDigitsAccuracy, Real& rfRoot);
00118
00119
00120 void GetHouseholderVector (int iSize, const Vector3<Real>& rkU,
00121 Vector3<Real>& rkV);
00122
00123 void PremultiplyHouseholder (GMatrix<Real>& rkMat, GVector<Real>& rkW,
00124 int iRMin, int iRMax, int iCMin, int iCMax, int iVSize,
00125 const Vector3<Real>& rkV);
00126
00127 void PostmultiplyHouseholder (GMatrix<Real>& rkMat, GVector<Real>& rkW,
00128 int iRMin, int iRMax, int iCMin, int iCMax, int iVSize,
00129 const Vector3<Real>& rkV);
00130
00131 void FrancisQRStep (GMatrix<Real>& rkH, GVector<Real>& rkW);
00132
00133 Real GetRowNorm (int iRow, GMatrix<Real>& rkMat);
00134 Real GetColNorm (int iCol, GMatrix<Real>& rkMat);
00135 void ScaleRow (int iRow, Real fScale, GMatrix<Real>& rkMat);
00136 void ScaleCol (int iCol, Real fScale, GMatrix<Real>& rkMat);
00137 void Balance3 (GMatrix<Real>& rkMat);
00138 bool IsBalanced3 (GMatrix<Real>& rkMat);
00139 void BalanceCompanion3 (GMatrix<Real>& rkMat);
00140 bool IsBalancedCompanion3 (Real fA10, Real fA21, Real fA02, Real fA12,
00141 Real fA22);
00142 bool QRIteration3 (GMatrix<Real>& rkMat);
00143
00144 void BalanceCompanion4 (GMatrix<Real>& rkMat);
00145 bool IsBalancedCompanion4 (Real fA10, Real fA21, Real fA32, Real fA03,
00146 Real fA13, Real fA23, Real fA33);
00147 bool QRIteration4 (GMatrix<Real>& rkMat);
00148
00149
00150 bool AllRealPartsNegative (int iDegree, Real* afCoeff);
00151
00152
00153 Real m_fEpsilon;
00154 int m_iCount, m_iMaxRoot;
00155 Real* m_afRoot;
00156 int m_iMaxIterations;
00157 };
00158
00159 typedef PolynomialRoots<float> PolynomialRootsf;
00160 typedef PolynomialRoots<double> PolynomialRootsd;
00161
00162 }
00163
00164 #endif