10 double gsl_f(
double x,
void *params)
14 std::cerr <<
"Inverrting f(x = " << x <<
") = " << func_value << std::endl;
15 if(std::isnan(func_value))
17 return (func_value - func_object->
__target);
20 double gsl_df(
double x,
void *params)
24 double result = deriv->
order(1);
26 if(std::isnan(result))
31 void gsl_fdf(
double x,
void *params,
double *f,
double *df)
36 *df = deriv->
order(1);
38 if(std::isnan(deriv->
order(0)) || std::isnan(deriv->
order(1)))
46 __to_invert(to_invert),
47 __tolerance(tolerance),
48 __solver(gsl_root_fsolver_alloc(gsl_root_fsolver_brent)),
49 __search_min(search_min),
50 __search_max(search_max)
58 __solver_f.params =
reinterpret_cast<void*
>(
this);
62 "Failed to allocate GSL solver in inverse function." 82 "Failed to initialize solver for inverse function." 84 double evaluation_error = Core::Inf,
88 if(gsl_root_fsolver_iterate(
__solver))
90 result = gsl_root_fsolver_root(
__solver);
91 evaluation_error = std::abs(
__to_invert(result) - x);
96 assert(!std::isnan(result));
104 double first_deriv = 1.0 / deriv->
order(1);
105 double second_deriv = deriv->
order(2) * std::pow(first_deriv, 3);
110 InverseFunction::~InverseFunction()
friend double gsl_df(double x, void *params)
GLS format derivative of function to invert.
const Core::OneArgumentDiffFunction & __to_invert
The function being inverted.
gsl_function __solver_f
The f argument used by the GSL solver.
Declarses a class for functions that are the inverse of some analytical function. ...
double operator()(double x) const
The value of the function at the given abscissa.
virtual double order(unsigned deriv_order=1) const =0
Derivative of the given order of the function with respect to its argument.
friend void gsl_fdf(double x, void *params, double *f, double *df)
GLS format function and its derivative to invert.
A class representing arbitrary order derivatives of a function.
double __target
The value we are trying to match the function to.
InverseFunction(const OneArgumentDiffFunction &to_invert, double search_min, double search_max, double tolerance=1e-10)
Invert the given function.
double __search_min
The range which to search for a solution (must bracket a zero).
A class for the derivatives of a cubic spline (=0 for order>2).
The invrse of an existing function.
const Core::FunctionDerivatives * deriv(double x) const
Returns a pointer to the derivative of the function.
gsl_function_fdf __solver_fdf
The fdf argument used by the GSL solver.
friend double gsl_f(double x, void *params)
GLS format function to invert.
gsl_root_fsolver * __solver
The GSL derivative-based solver.
double __tolerance
The relative tolerance in the value returned by the function at the best guess for the solution...
virtual const FunctionDerivatives * deriv(double x) const =0
Returns a pointer to the derivative of the function.