RSTT  3.2.0
Regional Seismic Travel Time
All Classes Namespaces Files Functions Variables Typedefs Friends Macros
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...
 

Detailed Description

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

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.

Definition at line 76 of file Brents.h.

Constructor & Destructor Documentation

◆ Brents() [1/3]

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

Default Constructor.

◆ Brents() [2/3]

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

Standard Constructor.

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

◆ Brents() [3/3]

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

Copy Constructor.

◆ ~Brents()

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

Destructor.

Member Function Documentation

◆ getF() [1/2]

template<class F >
F & util::Brents< F >::getF
inline

Returns a reference to the functional.

Definition at line 222 of file Brents.h.

◆ getF() [2/2]

template<class F >
const F & util::Brents< F >::getF
inline

Returns a const reference to the functional.

Definition at line 229 of file Brents.h.

◆ getTolerance()

template<class F >
double util::Brents< F >::getTolerance
inline

Returns the tolerance value.

Returns the Brents tolerance value.

Definition at line 243 of file Brents.h.

◆ isMinimumSearch()

template<class F >
bool util::Brents< F >::isMinimumSearch
inline

Returns true if the search method is a minimum.

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

Note: Applies only to function minF.

Definition at line 270 of file Brents.h.

◆ minF()

template<class F >
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.

◆ operator=()

template<class F >
Brents<F>& util::Brents< F >::operator= ( const Brents< F > &  zb)

Assignment Operator.

◆ setF()

template<class F >
void util::Brents< F >::setF ( F &  f)
inline

Sets the functional to f.

Sets the functional to f.

Definition at line 215 of file Brents.h.

◆ setMaximumSearch()

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

Sets the search method to a maximum.

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

Note: Used function minF only.

Definition at line 261 of file Brents.h.

◆ setMinimumSearch()

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

Sets the search method to a minimum (the default).

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

Note: Used function minF only.

Definition at line 252 of file Brents.h.

◆ setTolerance()

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

Sets the tolerance value.

Sets the Brents tolerance value.

Definition at line 236 of file Brents.h.

◆ zeroF()

template<class F >
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


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