#include <rootsolver.h>
A class used for calculating the root of a one-dimensional equation.
It takes care of all technicalities and provides an interface to GSL.
Definition at line 30 of file rootsolver.h.
Public Member Functions | |
RootSolver1D (std::function< double(double)> eq) | |
Construct a new Root Solver 1D object. More... | |
~RootSolver1D () | |
std::optional< double > | try_find_root (double initial_guess_low, double initial_guess_high, size_t itermax) |
Attempt to find a root in a given interval. More... | |
Static Private Member Functions | |
static double | gsl_func (const double x, void *) |
The function of which a root should be found in the form that GSL expects. More... | |
Private Attributes | |
const gsl_root_fsolver_type * | Solver_name_ = gsl_root_fsolver_brent |
GSL solver to use for root finding. More... | |
gsl_root_fsolver * | Root_finder_ = nullptr |
GSL root finding object to take care of root finding. More... | |
double | solution_precision_ = 1e-7 |
Expected precision of the root. More... | |
Static Private Attributes | |
static std::unique_ptr< std::function< double(double)> > | root_eq_ |
Static pointer to the function to solve. More... | |
|
inlineexplicit |
Construct a new Root Solver 1D object.
[in] | eq | The function of which a root is desired |
Definition at line 37 of file rootsolver.h.
|
inline |
Definition at line 41 of file rootsolver.h.
|
inline |
Attempt to find a root in a given interval.
[in] | initial_guess_low | Lower boundary of the interval |
[in] | initial_guess_high | Higher boundary of the interval |
[in] | itermax | maximum number of steps for root finding |
Definition at line 51 of file rootsolver.h.
|
inlinestaticprivate |
The function of which a root should be found in the form that GSL expects.
[in] | x | Argument of the function |
static
because GSL uses an object of type gsl_function
that has to be initialised with a pointer to a function and this cannot be created from a class non-static method as a class non-static method cannot exist as entity without an instance of that type. On the contrary, a pointer to a static member function can be used as a normal pointer to a free function, because a static
method exists without needing any instance of the class. Definition at line 125 of file rootsolver.h.
|
private |
GSL solver to use for root finding.
Definition at line 91 of file rootsolver.h.
|
private |
GSL root finding object to take care of root finding.
Definition at line 94 of file rootsolver.h.
|
inlinestaticprivate |
Static pointer to the function to solve.
static
since it is used inside the static gsl_func
method. As static
methods exist and can be used without a class instance, it is not possible to use non-static members inside them (non-static members are bound to a class instance). static
as well. Definition at line 103 of file rootsolver.h.
|
private |
Expected precision of the root.
Definition at line 107 of file rootsolver.h.