10 double gsl_f(
double x,
void *params)
14 if(std::isnan(func_value))
16 return (func_value - func_object->
__target);
19 double gsl_df(
double x,
void *params)
23 double result = deriv->
order(1);
25 if(std::isnan(result))
30 void gsl_fdf(
double x,
void *params,
double *f,
double *df)
35 *df = deriv->
order(1);
37 if(std::isnan(deriv->
order(0)) || std::isnan(deriv->
order(1)))
45 __to_invert(to_invert),
46 __tolerance(tolerance),
47 __solver(gsl_root_fsolver_alloc(gsl_root_fsolver_brent)),
48 __search_min(search_min),
49 __search_max(search_max)
57 __solver_f.params =
reinterpret_cast<void*
>(
this);
61 "Failed to allocate GSL solver in inverse function." 81 "Failed to initialize solver for inverse function." 83 double evaluation_error = Core::Inf,
87 if(gsl_root_fsolver_iterate(
__solver))
89 result = gsl_root_fsolver_root(
__solver);
90 evaluation_error = std::abs(
__to_invert(result) - x);
95 assert(!std::isnan(result));
103 double first_deriv = 1.0 / deriv->
order(1);
104 double second_deriv = deriv->
order(2) * std::pow(first_deriv, 3);
109 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.