#ifndef SUPERNEWTON_H_INCLUDED
#define SUPERNEWTON_H_INCLUDED 1
//minimization function which brackets the root
//and then approximates root by fitting a third-
//order polynomial
double supernewton(void (*funcd) (double, void *, double *, double *),
void *params, //function parameters
double x1, //first bracket
double x2, //second bracket
double xtol, //desired (absolute) tolerance
double ytol,
long maxiter, //maximum number of iterations
long &err, //error code--zero for success
double &y1, //to avoid redundant calculation
double &dydx1, //returns final values in these two
double y2,
double dydx2);
inline double supernewton(void (*funcd) (double, void *, double *, double *),
void *params, //function parameters
double x1, //first bracket
double x2, //second bracket
double xtol, //desired (absolute) tolerance
double ytol,
long maxiter, //maximum number of iterations
long &err) //error code--zero for success
{
double y1, y2, dydx1, dydx2;
(*funcd) (x1, params, &y1, &dydx1);
(*funcd) (x2, params, &y2, &dydx2);
return supernewton(funcd, params, x1, x2, xtol, ytol, maxiter, err,
y1, dydx1, y2, dydx2);
}
#endif