35#include "gsl/gsl_math.h"
36#include "gsl/gsl_errno.h"
37#include "gsl/gsl_poly.h"
121 return gsl_poly_eval( p,
fOrder + 1,
x);
129 for (
unsigned int i = 0; i <
fOrder; ++i )
138 return gsl_pow_int(
x, ipar);
159 std::vector<std::complex<double>>
roots;
167 roots.push_back(std::complex<double>(
r, 0.0));
175 std::cout <<
"Polynomial quadratic ::- FAILED to find roots" << std::endl;
179 roots.push_back(std::complex<double>(z1.dat[0], z1.dat[1]));
180 roots.push_back(std::complex<double>(z2.dat[0], z2.dat[1]));
184 gsl_complex z1, z2, z3;
193 std::cout <<
"Polynomial cubic::- FAILED to find roots" << std::endl;
197 roots.push_back(std::complex<double>(z1.dat[0], z1.dat[1]));
198 roots.push_back(std::complex<double>(z2.dat[0], z2.dat[1]));
199 roots.push_back(std::complex<double>(z3.dat[0], z3.dat[1]));
204 gsl_complex z1, z2, z3, z4;
214 std::cout <<
"Polynomial quartic ::- FAILED to find roots" << std::endl;
218 roots.push_back(std::complex<double>(z1.dat[0], z1.dat[1]));
219 roots.push_back(std::complex<double>(z2.dat[0], z2.dat[1]));
220 roots.push_back(std::complex<double>(z3.dat[0], z3.dat[1]));
221 roots.push_back(std::complex<double>(z4.dat[0], z4.dat[1]));
233 std::vector<double> realRoots;
234 for (
const auto &
r :
roots)
235 if (std::abs(
r.imag()) < std::numeric_limits<double>::epsilon())
236 realRoots.push_back(
r.real());
249 std::vector<std::complex<double>>
roots;
254 gsl_poly_complex_workspace *w = gsl_poly_complex_workspace_alloc(
n + 1);
255 std::vector<double> z(2 *
n);
256 int status = gsl_poly_complex_solve(
Parameters(),
n + 1, w, &z.front());
257 gsl_poly_complex_workspace_free(w);
260 for (
unsigned int i = 0; i <
n; ++i)
261 roots.push_back(std::complex<double>(z[2 * i], z[2 * i + 1]));
const double * Parameters() const override
std::vector< double > fParams
std::vector< std::complex< double > > FindRoots() const
Find the polynomial roots.
Polynomial(unsigned int n=0)
Construct a Polynomial function of order n.
std::vector< std::complex< double > > FindNumRoots() const
Find the polynomial roots using always an iterative numerical methods The numerical method used is fr...
double DoEvalPar(double x, const double *p) const override
Implementation of the evaluation function using the x value and the parameters.
ParamFunction< IParamGradFunction > ParFunc
IGenFunction * Clone() const override
Clone a function.
double DoParameterDerivative(double x, const double *p, unsigned int ipar) const override
Evaluate the gradient, to be implemented by the derived classes.
double DoDerivative(double x) const override
Function to evaluate the derivative with respect each coordinate. To be implemented by the derived cl...
std::vector< double > FindRealRoots() const
Find the only the real polynomial roots.
std::vector< double > fDerived_params
int gsl_poly_complex_solve_quartic(double a, double b, double c, double d, gsl_complex *z0, gsl_complex *z1, gsl_complex *z2, gsl_complex *z3)
Namespace for new Math classes and functions.
IBaseFunctionOneDim IGenFunction
int gsl_poly_complex_solve_cubic(double a, double b, double c, gsl_complex *z0, gsl_complex *z1, gsl_complex *z2)