28 return std::signbit(a) == std::signbit(b);
33 return std::abs(a) <= std::numeric_limits<double>::epsilon();
40template<
typename SubType,
typename Function>
49 static_assert(std::is_same_v<double,
decltype(f(0.0))>,
50 "Using this class for functions that do not return double"
51 " involves a lot of casts. Hence it is disabled.");
63 OGS_FATAL(
"Regula falsi cannot be done, because the function values"
64 " at the interval ends have the same sign.");
69 void step(
const unsigned num_steps)
71 for (
unsigned i=0; i<num_steps; ++i)
79 const double c =
a_ -
fa_ /
s;
80 const double fc =
f_(c);
93 const double m = SubType::get_m(
fa_,
fb_, fc);
110 const double c =
a_ -
fa_ /
s;
129template <
typename SubType,
typename Function>
141 static double get_m(
const double ,
const double ,
const double )
148 static double get_m(
const double ,
const double ,
const double )
155 static double get_m(
const double ,
const double fb,
const double fc)
156 {
return fb / (fb+fc); }
162 static double get_m(
const double ,
const double fb,
const double fc)
164 const double v = 1.0 - fc / fb;
165 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)