44 #ifndef O2SCL_ROOT_STEF_H 45 #define O2SCL_ROOT_STEF_H 53 #include <o2scl/misc.h> 54 #include <o2scl/root.h> 56 #ifndef DOXYGEN_NO_O2NS 109 template<
class func_t=funct11,
class dfunc_t=func_t>
class root_stef :
110 public root_de<func_t,dfunc_t> {
143 virtual const char *
type() {
return "root_stef"; }
160 double x_new, f_new, df_new;
175 df_new=(*dfp)(x_new);
184 if (!std::isfinite(f_new)) {
185 std::string str=
"Function not finite (returned "+
dtos(f_new)+
186 ") in root_stef::iterate().";
198 double v=(x_new-2*xt+x_1t);
209 if (!std::isfinite(df_new)) {
210 std::string str=
"Derivative not finite (returned "+
dtos(df_new)+
211 ") in root_stef::iterate().";
221 virtual int solve_de(
double &xx, func_t &fun, dfunc_t &dfun) {
234 status2=gsl_root_test_delta(root,xx,this->
tol_abs,tol_rel2);
257 if (iter>=this->ntrial) {
258 std::string str=((std::string)
"Function solve_de() exceeded the ")+
259 "maximum number of iterations, "+
itos(this->ntrial)+
".";
274 void set(func_t &fun, dfunc_t &dfun,
double guess) {
292 #ifndef DOXYGEN_NO_O2NS int count
Number of iterations.
dfunc_t * dfp
The derivative.
double root
The present solution estimate.
int ntrial
Maximum number of iterations (default 100)
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.
err_hnd_type * err_hnd
The global error handler pointer.
double tol_abs
The minimum allowable stepsize (default )
exceeded max number of iterations
iteration has not converged
One-dimensional with solver with derivatives [abstract base].
int iterate()
Perform an iteration.
virtual const char * type()
Return the type, "root_stef".
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)
bool test_residual
True if we should test the residual also (default false)
virtual int solve_de(double &xx, func_t &fun, dfunc_t &dfun)
Solve func using x as an initial guess using derivatives df.
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.
double x_1
Previous value of root.
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
Steffenson equation solver (GSL)
func_t * fp
The function to solve.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
double df
Derivative value.
problem with user-supplied function
int last_ntrial
The number of iterations used in the most recent solve.
double tol_rel2
The relative tolerance for subsequent solutions (default )
virtual int get_errno() const =0
Return the last error number.
std::string itos(int x)
Convert an integer to a string.
int verbose
Output control (default 0)