13#ifndef OPTIMIST_SCALAR_ROOT_FINDER_ALGO748_HH
14#define OPTIMIST_SCALAR_ROOT_FINDER_ALGO748_HH
20 namespace ScalarRootFinder
41 template <
typename Real>
77 return a != b && a != c && a != d && b != c && b != d && c != d;
94 Real hba{(this->
m_b - this->
m_a)/2.0};
102 if (this->
m_fc == 0) {
104 this->
m_d = 0.0; this->
m_fd = 0.0;
129 Real d_1{this->
m_b - this->
m_a};
130 Real d_2{this->
m_d - this->
m_a};
131 Real d_3{this->
m_e - this->
m_a};
133 Real dd_0{d_1/(this->
m_fb - this->
m_fa)};
134 Real dd_1{(d_1-d_2)/(this->
m_fb - this->
m_fd)};
135 Real dd_2{(d_2-d_3)/(this->
m_fd - this->
m_fe)};
137 Real ddd_0 {(dd_0 - dd_1)/(this->
m_fa - this->
m_fd)};
138 Real ddd_1 {(dd_1 - dd_2)/(this->
m_fb - this->
m_fe)};
140 Real dddd_0{(ddd_0-ddd_1)/(this->
m_fa-this->
m_fe)};
143 Real root{this->
m_a - this->
m_fa*(dd_0 - this->
m_fb*(ddd_0 - this->
m_fd*dddd_0))};
146 root = (this->
m_a + this->
m_b)/2.0;
161 Real a_0{this->
m_fa};
166 if (a_2 == 0) {
return this->
m_a - a_0/a_1;}
169 Real c{a_2*this->
m_fa > 0.0 ? this->
m_a : this->
m_b};
172 bool is_nonzero{
true};
173 Real pc{0.0}, pdc{0.0};
174 for (
Integer i{0}; i < n && is_nonzero ; ++i ) {
175 pc = a_0 + (a_1 + a_2*(c - this->
m_b))*(c - this->
m_a);
176 pdc = a_1 + a_2*((2.0 * c) - (this->
m_a + this->
m_b));
177 is_nonzero = pdc != 0;
178 if (is_nonzero) {c -= pc/pdc;}
181 if (is_nonzero) {
return c;}
182 else {
return this->
m_a - a_0/a_1;}
208 this->
m_e = QUIET_NAN;
209 this->
m_fe = QUIET_NAN;
212 while (!(std::isfinite(this->
m_fa) && std::isfinite(this->
m_fb))) {
227 Real abs_fa{std::abs(this->
m_fa)};
228 Real abs_fb{std::abs(this->
m_fb)};
230 abs_fa < tolerance_function ||abs_fb < tolerance_function;
236 Real b_a{this->
m_b - this->
m_a};
237 Real r{b_a/(this->
m_fb - this->
m_fa)};
238 this->
m_c = std::abs(this->
m_fb) < std::abs(this->
m_fa) ?
241 if (this->
m_c < (a_min = this->
m_a + delta)) {this->
m_c = a_min;}
242 else if (this->
m_c > (b_max = this->
m_b - delta)) {this->
m_c = b_max;}
253 Real a0_b0{this->
m_b - this->
m_a};
257 Real abs_fa {std::abs(this->
m_fa)};
258 Real abs_fb {std::abs(this->
m_fb)};
259 this->
m_converged = abs_fa < tolerance_function || abs_fb < tolerance_function;
264 bool do_newton_quadratic{
false};
265 if (!std::isfinite(this->
m_fe)) {
266 do_newton_quadratic =
true;
268 do_newton_quadratic =
true;
271 do_newton_quadratic = (this->
m_c-this->
m_a)*(this->
m_c-this->
m_b) >= 0.0;
281 return std::abs(this->
m_fa) < std::abs(this->
m_fb) ? this->
m_a : this->
m_b;
284 do_newton_quadratic =
true;
287 do_newton_quadratic = (this->
m_c - this->
m_a)*(this->
m_c - this->
m_b) >= 0.0;
294 Real abs_fa{std::abs(this->
m_fa)};
295 Real abs_fb{std::abs(this->
m_fb)};
303 if (abs_fa < abs_fb) {u = this->
m_a; fu = this->
m_fa;}
304 else {u = this->
m_b; fu = this->
m_fb;}
305 Real hba{(this->
m_b - this->
m_a)/2.0};
306 this->
m_c = u - 4.0*(fu/(this->
m_fb - this->
m_fa))*hba;
307 if (std::abs(this->
m_c - u) > hba) {this->
m_c = this->
m_a + hba;}
313 return std::abs(this->
m_fa) < std::abs(this->
m_fb) ? this->
m_a : this->
m_b;
317 if ((this->
m_b-this->
m_a) < this->
m_mu*a0_b0) {
continue;}
324 Real b_a{this->
m_b-this->
m_a};
325 this->
m_c = this->
m_a + b_a/2.0;
330 return std::abs(this->
m_fa) < std::abs(this->
m_fb) ? this->
m_a : this->
m_b;
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
bool bracketing(FunctionWrapper function)
Definition Algo748.hh:90
Real cubic_interpolation()
Definition Algo748.hh:126
std::string name_impl() const
Definition Algo748.hh:65
static constexpr bool requires_function
Definition Algo748.hh:45
typename Bracketing< Real, Algo748< Real > >::SecondDerivativeWrapper SecondDerivativeWrapper
Definition Algo748.hh:54
Algo748()
Definition Algo748.hh:59
bool all_different(Real a, Real b, Real c, Real d) const
Definition Algo748.hh:76
typename Bracketing< Real, Algo748< Real > >::FunctionWrapper FunctionWrapper
Definition Algo748.hh:52
static constexpr bool requires_first_derivative
Definition Algo748.hh:46
static constexpr bool requires_second_derivative
Definition Algo748.hh:47
Real newton_quadratic(Integer n)
Definition Algo748.hh:158
typename Bracketing< Real, Algo748< Real > >::FirstDerivativeWrapper FirstDerivativeWrapper
Definition Algo748.hh:53
Real find_root_impl(FunctionWrapper function)
Definition Algo748.hh:198
Bracketing()
Definition Bracketing.hh:69
Real m_fb
Definition Bracketing.hh:60
Real m_fd
Definition Bracketing.hh:62
Real m_fc
Definition Bracketing.hh:61
Real m_c
Definition Bracketing.hh:61
Real m_a
Definition Bracketing.hh:59
Real m_interval_shink
Definition Bracketing.hh:57
Real m_tolerance_bracketing
Definition Bracketing.hh:55
Real m_b
Definition Bracketing.hh:60
Real m_mu
Definition Bracketing.hh:56
Real m_fa
Definition Bracketing.hh:59
Real m_e
Definition Bracketing.hh:63
Real m_d
Definition Bracketing.hh:62
Real m_fe
Definition Bracketing.hh:63
Real m_tolerance
Definition Solver.hh:92
bool m_converged
Definition Solver.hh:99
Real tolerance() const
Definition Solver.hh:377
void evaluate_function(FunctionWrapper function, const InputType &x, OutputType &out)
Definition Solver.hh:710
Integer m_iterations
Definition Solver.hh:85
Integer m_max_iterations
Definition Solver.hh:86
Namespace for the Optimist library.
Definition Optimist.hh:87
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:95