35 return std::signbit(a) == std::signbit(b);
40 return std::abs(a) <= std::numeric_limits<double>::epsilon();
47template<
typename SubType,
typename Function>
56 static_assert(std::is_same_v<double,
decltype(f(0.0))>,
57 "Using this class for functions that do not return double"
58 " involves a lot of casts. Hence it is disabled.");
70 OGS_FATAL(
"Regula falsi cannot be done, because the function values"
71 " at the interval ends have the same sign.");
76 void step(
const unsigned num_steps)
78 for (
unsigned i=0; i<num_steps; ++i)
86 const double c =
a_ -
fa_ /
s;
87 const double fc =
f_(c);
100 const double m = SubType::get_m(
fa_,
fb_, fc);
117 const double c =
a_ -
fa_ /
s;
136template <
typename SubType,
typename Function>
148 static double get_m(
const double ,
const double ,
const double )
155 static double get_m(
const double ,
const double ,
const double )
162 static double get_m(
const double ,
const double fb,
const double fc)
163 {
return fb / (fb+fc); }
169 static double get_m(
const double ,
const double fb,
const double fc)
171 const double v = 1.0 - fc / fb;
172 return (
v >= 0.0) ?
v : 0.5;
void step(const unsigned num_steps)
Do num_steps iteration of regula falsi.
double getResult() const
Returns the current estimate of the root.
RegulaFalsi(Function &&f, double a, double b)
double getRange() const
Returns the size of the current search interval.
bool almost_zero(double a)
bool same_sign(double a, double b)
Tells if a and b have the same sign.
RegulaFalsi< SubType, Function > makeRegulaFalsi(Function &&f, double const a, double const b)
Used by RegulaFalsi in a modified version of the regula falsi algorithm.
static double get_m(const double, const double fb, const double fc)
Used by RegulaFalsi in a modified version of the regula falsi algorithm.
static double get_m(const double, const double, const double)
Used by RegulaFalsi in a modified version of the regula falsi algorithm.
static double get_m(const double, const double fb, const double fc)
Used by RegulaFalsi in the original regula falsi algorithm.
static double get_m(const double, const double, const double)