#ifndef SUPERNEWTON_H_INCLUDED
#define SUPERNEWTON_H_INCLUDED 1
namespace libpetey {
//root-finding function which brackets the root
//and then approximates root by fitting a third-
//order polynomial
template <class real>
real supernewton(void (*funcd) (real, void *, real *, real *),
void *params, //function parameters
real x1, //first bracket
real x2, //second bracket
real xtol, //desired (absolute) tolerance
real ytol,
long maxiter, //maximum number of iterations
long &err, //returns number of iterations;
//returns 0 or less for failure
real &y1, //to avoid redundant calculation
real &dydx1, //returns final values in these two
real y2,
real dydx2);
template <class real>
inline real supernewton(void (*funcd) (real, void *, real *, real *),
void *params, //function parameters
real x1, //first bracket
real x2, //second bracket
real xtol, //desired (absolute) tolerance
real ytol,
long maxiter, //maximum number of iterations
long &err) //number of iterations/error code
{
real 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