31 #include <o2scl/err_hnd.h>
32 #include <o2scl/funct.h>
34 #ifndef DOXYGEN_NO_O2NS
46 template<
class func_t=funct11,
class dfunc_t=func_t>
class root {
86 virtual const char *
type() {
return "root"; }
98 virtual int print_iter(
double x,
double y,
int iter,
double value=0.0,
99 double limit=0.0, std::string comment=
"") {
104 std::cout << comment <<
" Iteration: " << iter << std::endl;
105 if (x<0) std::cout << x <<
" ";
106 else std::cout <<
" " << x <<
" ";
107 if (y<0) std::cout << y <<
" ";
108 else std::cout <<
" " << y <<
" ";
109 if (value<0) std::cout << value <<
" ";
110 else std::cout <<
" " << value <<
" ";
111 if (limit<0) std::cout << limit << std::endl;
112 else std::cout <<
" " << limit << std::endl;
114 std::cout <<
"Press a key and type enter to continue. ";
123 virtual int solve(
double &x, func_t &func)=0;
129 return solve(x1,func);
135 virtual int solve_de(
double &x, func_t &func, dfunc_t &df) {
136 return solve(x,func);
144 template<
class func_t=funct11,
class dfunc_t=func_t>
class root_bkt :
145 public root<func_t,dfunc_t> {
168 virtual const char *
type() {
return "root_bkt"; }
173 virtual int solve_bkt(
double &
x1,
double x2, func_t &func)=0;
177 virtual int solve(
double &x, func_t &func) {
181 double x2=0.0, dx, fx, fx2;
204 O2SCL_ERR(
"Failed to bracket function in root_bkt::solve().",
215 virtual int solve_de(
double &x, func_t &func, dfunc_t &df) {
217 double x2=0.0, dx, fx, fx2;
222 while(done==
false && i<10) {
240 O2SCL_ERR(
"Failed to bracket function in root_bkt::solve_de().",
255 template<
class func_t=funct11,
class dfunc_t=func_t>
266 virtual const char *
type() {
return "root_de"; }
278 virtual int solve(
double &x, func_t &func) {
286 virtual int solve_de(
double &x, func_t &func, dfunc_t &df)=0;
290 #ifndef DOXYGEN_NO_O2NS
virtual int solve(double &x, func_t &func)
Solve func using x as an initial guess.
int ntrial
Maximum number of iterations (default 100)
virtual int solve_bkt(double &x1, double x2, func_t &func)=0
Solve func in region returning .
virtual const char * type()
Return the type, "root_de".
double tol_abs
The minimum allowable stepsize (default )
virtual int solve(double &x, func_t &func)=0
Solve func using x as an initial guess.
exceeded max number of iterations
One-dimensional with solver with derivatives [abstract base].
One-dimensional bracketing solver [abstract base].
virtual int solve_bkt(double &x1, double x2, func_t &func)
Solve func in region returning .
requested feature not (yet) implemented
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 int solve_de(double &x, func_t &func, dfunc_t &df)
Solve func using x as an initial guess using derivatives df.
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.
virtual int solve_de(double &x, func_t &func, dfunc_t &df)=0
Solve func using x as an initial guess using derivatives df.
virtual const char * type()
Return the type, "root".
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
size_t bracket_iters
The number of iterations in attempt to bracket root (default 10)
virtual int solve(double &x, func_t &func)
Solve func using x as an initial guess.
virtual int solve_de(double &x, func_t &func, dfunc_t &df)
Solve func using x as an initial guess using derivatives df.
virtual int solve_bkt(double &x1, double x2, func_t &func)
Solve func in region returning .
int last_ntrial
The number of iterations used in the most recent solve.
double bracket_step
The stepsize for automatic bracketing (default )
virtual const char * type()
Return the type, "root_bkt".
static const double x2[5]
static const double x1[5]
int verbose
Output control (default 0)