Class root_cern (o2scl)

O2scl : Class List

template<class func_t = funct, class fp_t = double>
class root_cern : public o2scl::root<funct, funct, double>

One-dimensional version of cern_mroot.

This one-dimensional root-finding routine, based on o2scl::mroot_cern. Previous testing has suggested that it is probably slower than the more typical 1-D solvers, but also tends to converge for a larger class of functions than o2scl::root_bkt_cern, o2scl::root_cern, or o2scl::root_stef. It has been modified from o2scl::mroot_cern and slightly optimized, but has the same basic behavior.

If \( x_i \) denotes the current iteration, and \( x^{\prime}_i \) denotes the previous iteration, then the calculation is terminated if either (or both) of the following tests is successful

\[ 1:\quad \mathrm{max} | f_i(x) | \leq \mathrm{tol\_rel} \]
\[ 2:\quad \mathrm{max} |x_i-x^{\prime}_i| \leq \mathrm{tol\_abs} \times \mathrm{max} | x_i | \]

See the One-dimensional solvers section of the User’s guide for general information about O2scl solvers.

Todo

class root_cern

Future:

  • Double-check this class to make sure it cannot fail while returning 0 for success.

Note

This class has difficulty finding the root when the desired root is near 0 (AWS 1/22/19)

Note

This code has not been checked to ensure that it cannot fail to solve the equations without calling the error handler and returning a non-zero value. Until then, the solution may need to be checked explicitly by the caller.

Public Functions

inline root_cern()
inline virtual ~root_cern()
inline int get_info()

Get the value of INFO from the last call to solve() (default 0)

The value of info is assigned according to the following list. The values 1-8 are the standard behavior from CERNLIB. 0 - The function solve()

has not been called. 1 - Test 1 was successful.

2 - Test 2 was successful.

3 - Both tests were successful.

4 - Number of iterations is greater than

root_cern::maxf

.

5 - Approximate (finite difference) Jacobian matrix is singular.

6 - Iterations are not making good progress.

7 - Iterations are diverging.

8 - Iterations are converging, but either root_cern::tol_abs

is too small or the Jacobian is nearly singular or the variables are badly scaled.

9 - Either

root::tol_rel or root::tol_abs is not greater than zero.

inline virtual const char *type()

Return the type, "root_cern".

template<typename func2_t, class fp2_t>
inline int solve_int_multip(fp2_t &ux, func2_t &func, double root_tol, double func_tol)

Internal multiprecision version of the solve function.

template<typename func2_t, class fp2_t>
inline int solve_multip(fp2_t &x1, func2_t &&f, fp2_t &err, double tol_loc = -1.0)

Solve f in returning x1 (adaptive multiprecision version)

inline virtual int solve(fp_t &ux, func_t &func)

Solve func using x as an initial guess, returning x.

Public Members

o2scl::table<std::vector<fp_t>, fp_t> tab

For storing function evaluations.

double pow_tol_func

Power for tolerance of function evaluations with adaptive multiprecision (default 1.33)

int maxf

Maximum number of function evaluations.

If \( \mathrm{maxf}\leq 0 \), then 200 (which is the CERNLIB default) is used. The default value of maxf is zero which then implies the default from CERNLIB.

fp_t scale

The original scale parameter from CERNLIB (default 10.0)

fp_t eps

The square root of epsilon.

The constructor sets this value to sqrt(std::numeric_limits<fp_t>::epsilon()). The original prescription from CERNLIB for eps is given below:

#if !defined(CERNLIB_DOUBLE)
PARAMETER (EPS =  0.84293 69702 17878 97282 52636 392E-07)
#endif
#if defined(CERNLIB_IBM)
PARAMETER (EPS =  0.14901 16119 38476 562D-07)
#endif
#if defined(CERNLIB_VAX)
PARAMETER (EPS =  0.37252 90298 46191 40625D-08)
#endif
#if (defined(CERNLIB_UNIX))&&(defined(CERNLIB_DOUBLE))
PARAMETER (EPS =  0.14901 16119 38476 600D-07)
#endif

bool store_funcs

If true, store function evaluations.

Protected Attributes

int info

Internal storage for the value of info.