26 #ifndef _BIAS_POLYNOMIALSOLVE_
27 #define _BIAS_POLYNOMIALSOLVE_
29 #include <Base/Common/BIASpragmaStart.hh>
34 #include "Base/Debug/Debug.hh"
35 #include "Base/Debug/Error.hh"
37 #define POLYNOMIALSOLVE_TYPE double
39 #define D_PS_GSL 0x00000001
40 #define D_PS_NLREFINE 0x00000002
41 #define D_PS_COEFF 0x00000004
63 int Solve(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
64 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
72 int Solve(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
73 std::vector<std::complex<POLYNOMIALSOLVE_TYPE> >& sol);
80 int Numeric(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
81 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
87 int Numeric(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
88 std::vector<std::complex<POLYNOMIALSOLVE_TYPE> >& sol);
95 int Analytic(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
96 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
102 int Analytic(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
103 std::vector<std::complex<POLYNOMIALSOLVE_TYPE> >& sol);
110 int Linear(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
111 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
117 int Linear(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
118 std::vector<std::complex<POLYNOMIALSOLVE_TYPE> >& sol);
126 int Quadratic(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
127 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
133 int Quadratic(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
134 std::vector<std::complex<POLYNOMIALSOLVE_TYPE> >& sol);
141 int Cubic(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
142 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
148 int Cubic(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
149 std::vector<std::complex<POLYNOMIALSOLVE_TYPE> >& sol);
172 int Quartic(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
173 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
177 void CheckCoefficients(std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
178 double eps=DBL_EPSILON);
183 void CalCoefficients(
const std::vector<POLYNOMIALSOLVE_TYPE>& sol,
184 std::vector<POLYNOMIALSOLVE_TYPE>& coeff);
189 inline POLYNOMIALSOLVE_TYPE
190 EvaluatePolynomial(
const POLYNOMIALSOLVE_TYPE x,
191 const std::vector<POLYNOMIALSOLVE_TYPE>& coeff)
const;
194 int GetNumberOfRealSolutions(
const std::vector<POLYNOMIALSOLVE_TYPE>&
199 {
return (GetNumberOfRealSolutions(coeff)>0); }
205 int NonLinearRefine(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
206 std::vector<std::complex<POLYNOMIALSOLVE_TYPE> >& sol);
211 int NonLinearRefine(
const std::vector<POLYNOMIALSOLVE_TYPE>& coeff,
212 std::vector<POLYNOMIALSOLVE_TYPE>& sol);
222 int FitPolynomial(
const unsigned int degree,
223 const std::vector<double>& x,
224 const std::vector<double>& y,
225 std::vector<double> &coefficients);
235 _GetCoeff(
int order,
int b,
const std::vector<POLYNOMIALSOLVE_TYPE>& sol);
243 inline POLYNOMIALSOLVE_TYPE
245 std::vector<POLYNOMIALSOLVE_TYPE>& coeff)
const
247 register int n = (int)coeff.size() - 1;
248 POLYNOMIALSOLVE_TYPE result = coeff[n--];
249 while (n>=0) result = result*x + coeff[n--];
256 #include <Base/Common/BIASpragmaEnd.hh>
base class for solving polynomial equations
POLYNOMIALSOLVE_TYPE EvaluatePolynomial(const POLYNOMIALSOLVE_TYPE x, const std::vector< POLYNOMIALSOLVE_TYPE > &coeff) const
numerically robust way to evaluate a polynomial at position x, uses Horner scheme (same principle as ...
bool HasRealSolution(const std::vector< POLYNOMIALSOLVE_TYPE > &coeff)
determine whether the polynomial has a solution in IR