SLBM  3.0
Regional Seismic Travel Time
Public Member Functions | Private Attributes | List of all members
util::Brents< F > Class Template Reference

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...
 

Private Attributes

double zbTol
 Output the test 1 zero-in value. More...
 
F * zbF
 
double bMinMaxFlg
 A flag used by the minF(...) function to switch between a minimum and maximum searcher. If the flag is 1.0 the search is for a minimum. A value of -1.0 searches for a maximum. Note: The Brents minimum/maximum searcher can only find one or the other and not both without setting this flag. An end-point and associated value will be returned if the setting is wrong. More...
 

Detailed Description

template<class F>
class util::Brents< F >

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.

Constructor & Destructor Documentation

template<class F>
util::Brents< F >::Brents ( )
template<class F>
util::Brents< F >::Brents ( F &  f,
double  tol 
)

Assigns the input function, f, and a tolerance tol.

template<class F>
util::Brents< F >::Brents ( const Brents< F > &  zb)
template<class F>
virtual util::Brents< F >::~Brents ( )
virtual

Member Function Documentation

template<class F >
F & util::Brents< F >::getF ( )
inline
template<class F >
const F & util::Brents< F >::getF ( ) const
inline
template<class F >
double util::Brents< F >::getTolerance ( ) const
inline

Returns the Brents tolerance value.

template<class F >
bool util::Brents< F >::isMinimumSearch ( ) const
inline

Returns true if the search method is for a minimum. Note: Applies to function minF only.

Note: Applies only to function minF.

template<class F>
double util::Brents< F >::minF ( double  ax,
double  bx,
double  cx,
double &  xmin 
)

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.

template<class F>
Brents<F>& util::Brents< F >::operator= ( const Brents< F > &  zb)
template<class F>
void util::Brents< F >::setF ( F &  f)
inline

Sets the functional to f.

template<class F >
void util::Brents< F >::setMaximumSearch ( )
inline

Sets the search method to find a functional maximum. Note: Used by minF only.

Note: Used function minF only.

template<class F >
void util::Brents< F >::setMinimumSearch ( )
inline

Sets the search method to find a functional minimum (the default) Note: Used by minF only.

Note: Used function minF only.

template<class F >
void util::Brents< F >::setTolerance ( double  tol)
inline

Sets the Brents tolerance value.

template<class F>
double util::Brents< F >::zeroF ( double  ax,
double  bx 
)

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

Member Data Documentation

template<class F>
double util::Brents< F >::bMinMaxFlg
private
template<class F>
F* util::Brents< F >::zbF
private

The function to be zeroed, minimized, or maximized using Brents methods.

template<class F>
double util::Brents< F >::zbTol
private

Output the test 2 max-search value The zeroin convergence tolerance.


The documentation for this class was generated from the following file: