Object-oriented Scientific Computing Library: Version 0.910
Public Member Functions | Protected Member Functions | Protected Attributes
cern_root< func_t > Class Template Reference

One-dimensional root-finding routine (CERNLIB) More...

#include <cern_root.h>

Inheritance diagram for cern_root< func_t >:
root_bkt< func_t > root< func_t, func_t >

Detailed Description

template<class func_t = funct>
class cern_root< func_t >

This class attempts to find $ x_1 $ and $ x_2 $ in $ [a,b] $ such that $ f(x_1) f(x_2) \leq 0 $, $ |f(x_1)| \leq|f(x_2)| $, and $ | x_1-x_2| \leq 2~\mathrm{tol\_abs}~(1+|x_0|) $. The function solve_bkt() requires inputs x1 and x2 such that $ f(x_1) f(x_2) \leq 0 $.

The variable cern_root::tol_abs defaults to $ 10^{-8} $ and cern_root::ntrial defaults to 200.

The function solve_bkt() returns 0 for success, gsl_einval if the root is not initially bracketed, and gsl_emaxiter if the number of function evaluations is greater than cern_root::ntrial.

Based on the CERNLIB routines RZEROX and DZEROX, which was based on Bus75 and is documented at http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/c200/top.html

Definition at line 58 of file cern_root.h.

Public Member Functions

int set_mode (int m)
 Set mode of solution (1 or 2)
virtual const char * type ()
 Return the type, "cern_root".
virtual int solve_bkt (double &x1, double x2, func_t &func)
 Solve func in region $ x_1<x<x_2 $ returning $ x_1 $.

Protected Member Functions

double sign (double a, double b)
 FORTRAN-like function for sign.

Protected Attributes

int mode
 Internal storage for the mode.

Member Function Documentation

template<class func_t = funct>
int cern_root< func_t >::set_mode ( int  m) [inline]
  • 1 should be used for simple functions where the cost is inexpensive in comparison to one iteration of solve_bkt(), or functions which have a pole near the root (this is the default).
  • 2 should be used for more time-consuming functions.

If an integer other than 1 or 2 is specified, the error handler is called.

Definition at line 100 of file cern_root.h.

template<class func_t = funct>
virtual int cern_root< func_t >::solve_bkt ( double &  x1,
double  x2,
func_t &  func 
) [inline, virtual]

The parameters x1 and x2 should be set so that $ f(x_1) f(x_2) \leq 0 $ before calling solve_bkt(). If this is not the case, the error handler will be called and the solver will fail.

This function converges unless the number of iterations is larger than root::ntrial, in which case root::last_conv is set to gsl_emaxiter and the error handler is called if root::err_nonconv is true.

Implements root_bkt< func_t >.

Definition at line 125 of file cern_root.h.


Field Documentation

template<class func_t = funct>
int cern_root< func_t >::mode [protected]

This internal variable is actually defined to be smaller by 1 than the "mode" as it is defined in the CERNLIB documentation in order to avoid needless subtraction in solve_bkt().

Definition at line 71 of file cern_root.h.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.