29 char zerosec_C[] =
"$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Utilities/zerosec.C,v 1.6 2014/10/13 08:53:32 j_novak Exp $" ;
90 double x1,
double x2,
double precis,
int nitermax,
int& niter,
93 double f0_prec, f0, x0, x0_prec, dx, df ;
97 bool warning = false ;
99 f0_prec = f(x1, parf) ;
101 if ( f0*f0_prec > 0.) {
104 "WARNING: zerosec: there does not exist a unique zero of the function" 106 cout <<
" between x1 = " << x1 <<
" ( f(x1)=" << f0_prec <<
" )" << endl ;
107 cout <<
" and x2 = " << x2 <<
" ( f(x2)=" << f0 <<
" )" << endl ;
113 if ( fabs(f0) < fabs(f0_prec) ) {
120 double swap = f0_prec ;
130 assert(df !=
double(0)) ;
131 dx = (x0_prec - x0) * f0 / df ;
137 if (niter > nitermax) {
138 cout <<
"zerosec: Maximum number of iterations has been reached ! " 148 while ( ( fabs(dx) > precis ) && ( fabs(f0) > 1.e-15 ) ) ;
151 cout <<
" A zero may have been found at x0 = " << x0 << endl ;
double zerosec(double(*f)(double, const Param &), const Param &par, double a, double b, double precis, int nitermax, int &niter, bool abort=true)
Finding the zero a function.