template <typename
T>
64 double(*f_) (
double,
const T&),
65 double(*df_) (
double,
const T&),
78template <typename
T>
81 double(*f_) (
double,
const T&),
92template <typename
T>
95 double(*f_) (
double,
const T&),
104template <typename
T>
107 double(*f_) (
double,
const T&),
125 double(*f_) (
double),
126 double(*df_) (
double),
140 double(*f_) (
double),
152 double(*f_) (
double),
161 double(*f_) (
double),
167 boolisLargest_ =
false);
188 double f(
doublex_,
const double&y_) {
return(*
s_f) (x_);}
189 double df(
doublex_,
const double&y_) {
return(*
s_df) (x_);}
193 double(*f_) (
doublex_),
194 double(*df_) (
doublex_),
209 double(*f_) (
doublex_),
222 double(*f_) (
doublex_),
230 return hunt(y_,
f,
ZERO, p_, q_, tol_, rtol_, itmax_);
235 double(*f_) (
doublex_),
244 return huntExtreme(y_,
f,
ZERO, p_, q_, tol_, rtol_, itmax_, isLargest_);
247 template<
typenameT>
250 double(*f_) (
double,
const T&),
251 double(*df_) (
double,
const T&),
263 assert(p_ != HUGE_VAL && p_ != -HUGE_VAL);
264 assert(q_ != HUGE_VAL && q_ != -HUGE_VAL);
267 double fp= (*f_) (p_, param_) - y_;
268 doublefq = (*f_) (q_, param_) - y_;
270 IoUtil::abort(
"Root::newtonRaphson : root not bracketed");
272 if(
fp== 0.0)
returnp_;
273 if(fq == 0.0)
returnq_;
275 if(p_ == q_)
IoUtil::abort(
"Root::newtonRaphson : p_ == q_");
279 if(q_ < p_)
swap(p_, q_);
282 if(x_ < p_ || q_ < x_) x = 0.5 * (p_ + q_);
285 if(
fp> 0.0)
swap(p_, q_);
294dxold = dx = p_ - q_;
297 Int4*itmax = itmax_ == 0 ? &iter: itmax_;
299 for( ; 0 < *itmax; --*itmax) {
301fx = (*f_) (x, param_) - y_;
304}
else if(fx < 0.0) {
309dfx = (*df_) (x, param_) - y_;
312 if((dfx * (x-p_) - fx) * (dfx * (x - q_) - fx) >= 0.0 ||
3132.0 *
fabs(fx) >
fabs(dfx * dx)) {
317dxold = 0.5 * (p_ - q_);
320 if(
fabs(dxold) <= tol_)
returnx;
329 if(
fabs(dxold) < tol_ ||
fabs(dxold) < rtol_ *
fabs(x)) {
330 if(((*f_) ((x -
Function::signum(dxold) * tol_), param_) - y_) * fx < 0.0)
returnx;
338 template<
typenameT>
341 double(*f_) (
double,
const T&),
349 assert(p_ != HUGE_VAL && p_ != -HUGE_VAL);
350 assert(q_ != HUGE_VAL && q_ != -HUGE_VAL);
353 double fp= (*f_) (p_, param_) - y_;
354 doublefq = (*f_) (q_, param_) - y_;
358 if(
fp== 0.0)
returnp_;
359 if(fq == 0.0)
returnq_;
361 if(p_ == q_)
IoUtil::abort(
"Root::bisection : p_ == q_");
364 if(
fp> 0.0)
swap(p_, q_);
370 Int4*itmax = itmax_ == 0 ? &iter: itmax_;
373 for( ; 0 < *itmax; --*itmax) {
375fx = (*f_) (x, param_) - y_;
383 if(Approx::absRelApprox <double> (p_, x, tol_, rtol_))
returnx;
389 template<
typenameT>
392 double(*f_) (
double,
const T&),
400 assert(p_ != HUGE_VAL && p_ != -HUGE_VAL);
401 assert(q_ != HUGE_VAL && q_ != -HUGE_VAL);
405 doublex0 = 0.5 * (p_ + q_);
406 doublefx0 = (*f_) (x0, param_) - y_;
407 if(fx0 == 0.0)
returnx0;
410 if(q_ < p_)
swap(p_, q_);
413 doubledel = 0.5 * (q_ - p_);
418 Int4*itmax = itmax_ == 0 ? &iter: itmax_;
420 while(tol_ <= del) {
423 for(
size_t i= 0;
i< pts && 0 < *itmax;
i++, --*itmax) {
425fx = (*f_) (x, param_) - y_;
426 if(fx * fx0 < 0.0)
returnbisection <T> (y_, f_, param_, x, x0, tol_, rtol_, itmax);
429 if(iter == 0)
return FAILED;
438 template<
typenameT>
441 double(*f_) (
double,
const T&),
451 Int4*itmax = itmax_ == 0 ? &iter: itmax_;
454 if(q_ < p_)
swap(p_, q_);
457 doublex = hunt <T> (y_, f_, param_, p_, q_, tol_, rtol_, itmax);
462 while(0 < *itmax && x !=
FAILED) {
464x = hunt <T> (y_, f_, param_, x, q_, tol_, rtol_, itmax);
467 while(0 < *itmax && x !=
FAILED) {
469x = hunt <T> (y_, f_, param_, p_, x, tol_, rtol_, itmax);
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
int32_t Int4
4-byte (32-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define END_SCOPE(ns)
End the previously defined scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define BEGIN_SCOPE(ns)
Define a new scope.
Defines Limits for the types used in NCBI C/C++ toolkit.
double f(double x_, const double &y_)
double huntExtreme(double y_, double(*f_)(double, const T &), const T ¶m_, double p_, double q_, double tol_, double rtol_, Int4 *itmax_, bool isLargest_)
double hunt(double y_, double(*f_)(double, const T &), const T ¶m_, double p_, double q_, double tol_, double rtol_, Int4 *itmax_)
double df(double x_, const double &y_)
double bisection(double y_, double(*f_)(double, const T &), const T ¶m_, double p_, double q_, double tol_, double rtol_, Int4 *itmax_)
double newtonRaphson(double y_, double(*f_)(double, const T &), double(*df_)(double, const T &), const T ¶m_, double p_, double x_, double q_, double tol_, double rtol_, Int4 *itmax_)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4