RSTT
3.2.0
Regional Seismic Travel Time
|
Class supports Brents zeroF and minF functions that finds the root of or minimum (maximum) of a provided function given an input range containing the root (or minimum or maximum) and a convergence tolerance. More...
#include <Brents.h>
Public Member Functions | |
Brents () | |
Default Constructor. More... | |
Brents (F &f, double tol) | |
Standard Constructor. More... | |
Brents (const Brents< F > &zb) | |
Copy Constructor. More... | |
virtual | ~Brents () |
Destructor. More... | |
Brents< F > & | operator= (const Brents< F > &zb) |
Assignment Operator. More... | |
double | zeroF (double ax, double bx) |
function zeroF - obtains a function zero within the given range. More... | |
double | minF (double ax, double bx, double cx, double &xmin) |
Returns the functional minimum between the input abscissas ax and cx at the internall defined function zbF. More... | |
void | setF (F &f) |
Sets the functional to f. More... | |
F & | getF () |
Returns a reference to the functional. More... | |
const F & | getF () const |
Returns a const reference to the functional. More... | |
void | setTolerance (double tol) |
Sets the tolerance value. More... | |
double | getTolerance () const |
Returns the tolerance value. More... | |
void | setMinimumSearch () |
Sets the search method to a minimum (the default). More... | |
void | setMaximumSearch () |
Sets the search method to a maximum. More... | |
bool | isMinimumSearch () const |
Returns true if the search method is a minimum. More... | |
Class supports Brents zeroF and minF functions that finds the root of or minimum (maximum) of a provided function given an input range containing the root (or minimum or maximum) and a convergence tolerance.
This object must assign the functional before use (at instantiation or with the function setF(f)). A tolerance may be provided at instantiation or reset to another value at a later time. both the function to be zeroed (or minimized) and the tolerance can be accessed with predefined "get" functions.
The function that evaluates the zero, zeroF(...), or finds the minimum / maximum, minF(...), are defined in detail below.
util::Brents< F >::Brents | ( | ) |
Default Constructor.
util::Brents< F >::Brents | ( | F & | f, |
double | tol | ||
) |
Standard Constructor.
Assigns the input function, f, and a tolerance tol.
util::Brents< F >::Brents | ( | const Brents< F > & | zb | ) |
Copy Constructor.
|
virtual |
Destructor.
|
inline |
|
inline |
|
inline |
|
inline |
double util::Brents< F >::minF | ( | double | ax, |
double | bx, | ||
double | cx, | ||
double & | xmin | ||
) |
Returns the functional minimum between the input abscissas ax and cx at the internall defined function zbF.
The abscissa bx is evaluated between ax and cx such that zbF(bx) is less than or greater than both zbF(ax) and zbF(cx). This function isolates the minimum to a fractional precision of about tol using Brent's method. The abscissa of the minimum is returned in xmin, and the minimum function value is returned as the function value.
Brents<F>& util::Brents< F >::operator= | ( | const Brents< F > & | zb | ) |
Assignment Operator.
|
inline |
|
inline |
|
inline |
|
inline |
double util::Brents< F >::zeroF | ( | double | ax, |
double | bx | ||
) |
function zeroF - obtains a function zero within the given range.
Input double zeroin(ax, bx) double ax; Root will be seeked for within double bx; a range [ax, bx] double (*f)(double x); Name of the function whose zero will be seeked for double tol; Acceptable tolerance for the root value. May be specified as 0.0 to cause the program to find the root as accurate as possible
Output Zeroin returns an estimate for the root with accuracy 4*EPSILON*abs(x) + tol
Algorithm G.Forsythe, M.Malcolm, C.Moler, Computer methods for mathematical computations. M., Mir, 1980, p.180 of the Russian edition
The function makes use of the bissection procedure combined with the linear or quadric inverse interpolation. At every step the program operates on three abscissae - a, b, and c, defined as b - the last and the best approximation to the root a - the last but one approximation c - the last but one or even earlier approximation than a such that 1) |f(b)| <= |f(c)| 2) f(b) and f(c) have opposite signs, i.e. b and c confine the root
At every step Zeroin selects one of the two new approximations, the former being obtained by the bissection procedure and the latter resulting in the interpolation (if a,b, and c are all different the quadric interpolation is utilized, otherwise the linear one). If the latter (i.e. obtained by the interpolation) point is reasonable (i.e. lies within the current interval [b,c] not being too close to the boundaries) it is accepted. The bissection result is used in the other case. Therefore, the range of uncertainty is ensured to be reduced at least by the factor 1.6