26 #ifndef O2SCL_ROOT_CERN_H 27 #define O2SCL_ROOT_CERN_H 31 #include <o2scl/string_conv.h> 32 #include <o2scl/root.h> 69 #ifdef DOXYGEN_NO_O2NS 70 template<
class func_t=funct11>
class root_cern :
public root
81 eps=0.1490116119384766e-07;
119 virtual const char *
type() {
return "root_cern"; }
151 virtual int solve(
double &ux, func_t &func) {
157 if (maxf<=0) lmaxf=200;
162 if (this->tol_rel<=0.0 || this->
tol_abs<=0.0) {
164 std::string str=
"Invalid value of tol_rel ("+
dtos(this->
tol_rel)+
165 ") or tol_abs ("+
dtos(this->
tol_abs)+
") in root_cern::solve().";
169 int iflag=0, numf=0, nfcall=0, nier6=-1, nier7=-1, nier8=0;
170 double fnorm=0.0, difit=0.0, xnorm=0.0;
173 if (xnorm<fabs(ux)) {
178 double delta=scale*xnorm;
179 if (
set==
false) delta=
scale;
181 double wmat, farr, w0arr, w1arr, w2arr;
183 bool solve_done=
false;
184 while (solve_done==
false) {
209 if (fnorm<fabs(fky)) fnorm=fabs(fky);
228 if (eta<fabs(w0arr)) eta=fabs(w0arr);
238 if (w0arr<0.0) sknorm=-sknorm;
245 double temp=w0arr/(sknorm*w0arr);
251 double temp2=fky/w0arr;
252 if (h*fabs(temp2)>delta)
253 temp2=(temp2>=0.0) ? fabs(delta/h) : -fabs(delta/h);
262 if (xnorm<fabs(w1arr)) xnorm=fabs(w1arr);
263 if (difit<fabs(ux-w1arr)) difit=fabs(ux-w1arr);
268 if(delta<scale*xnorm) delta=scale*xnorm;
272 bool lcv=(fnorm<fnorm1 && difit<difit1 && nsing==0);
277 if (fnorm<fnorm1 || difit<difit1) nier7=0;
278 if (difit>eps*xnorm) nier8=0;
291 if (fnorm<=this->tol_rel &&
info==2)
info=3;
293 if (!std::isfinite(ux)) {
311 "root_cern::solve().",
326 std::string s2=
"Variable tol_abs too small, J singular, ";
327 s2+=
"or bad scaling in cerm_mroot_root::solve().";
337 if (!std::isfinite(ux)) {
345 #ifndef DOXYGEN_INTERNAL iterative process is out of control
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
#define O2SCL_CONV_RET(d, n, b)
Set a "convergence" error and return the error value.
double tol_abs
The minimum allowable stepsize (default )
invalid argument supplied by user
apparent singularity detected
exceeded max number of iterations
#define O2SCL_CONV2_RET(d, d2, n, b)
Set an error and return the error value, two-string version.
int maxf
Maximum number of function evaluations.
double scale
The original scale parameter from CERNLIB (default 10.0)
double tol_rel
The maximum value of the functions for success (default )
bool err_nonconv
If true, call the error handler if the solver does not converge (default true)
virtual const char * type()
Return the type, "root_cern".
One-dimensional version of cern_mroot.
One-dimensional solver [abstract base].
virtual int print_iter(double x, double y, int iter, double value=0.0, double limit=0.0, std::string comment="")
Print out iteration information.
iteration is not making progress toward solution
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
int info
Internal storage for the value of info.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
#define O2SCL_CONV(d, n, b)
Set a "convergence" error.
output range error, e.g. exp(1e100)
double eps
The smallest floating point number (default )
int get_info()
Get the value of INFO from the last call to solve() (default 0)
int verbose
Output control (default 0)
virtual int solve(double &ux, func_t &func)
Solve func using x as an initial guess, returning x.