39 #include "gsl/gsl_roots.h"
40 #include "gsl/gsl_errno.h"
48 GSLRootFinderDeriv::GSLRootFinderDeriv() :
50 fRoot(0), fPrevRoot(0),
51 fIter(0), fStatus(-1),
55 fFunction =
new GSLFunctionDerivWrapper();
58 GSLRootFinderDeriv::~GSLRootFinderDeriv()
61 if (fFunction)
delete fFunction;
64 GSLRootFinderDeriv::GSLRootFinderDeriv(
const GSLRootFinderDeriv &) : IRootFinderMethod()
68 GSLRootFinderDeriv & GSLRootFinderDeriv::operator = (
const GSLRootFinderDeriv &rhs)
71 if (
this == &rhs)
return *
this;
79 bool GSLRootFinderDeriv::SetFunction( GSLFuncPointer f, GSLFuncPointer df, GSLFdFPointer Fdf,
void * p,
double xstart) {
83 fFunction->SetFuncPointer( f );
84 fFunction->SetDerivPointer( df );
85 fFunction->SetFdfPointer( Fdf );
86 fFunction->SetParams( p );
87 int status = gsl_root_fdfsolver_set( fS->Solver(), fFunction->GetFunc(), fRoot);
88 if (status == GSL_SUCCESS)
97 void GSLRootFinderDeriv::SetSolver(GSLRootFdFSolver * s ) {
102 void GSLRootFinderDeriv::FreeSolver( ) {
107 int GSLRootFinderDeriv::Iterate() {
110 if (!fFunction->IsValid() ) {
111 MATH_ERROR_MSG(
"GSLRootFinderDeriv::Iterate",
" Function is not valid");
115 MATH_ERROR_MSG(
"GSLRootFinderDeriv::Iterate",
" Estimated point is not valid");
120 int status = gsl_root_fdfsolver_iterate(fS->Solver());
123 fRoot = gsl_root_fdfsolver_root(fS->Solver() );
127 double GSLRootFinderDeriv::Root()
const {
132 const char * GSLRootFinderDeriv::Name()
const {
134 return gsl_root_fdfsolver_name(fS->Solver() );
137 bool GSLRootFinderDeriv::Solve (
int maxIter,
double absTol,
double relTol)
147 if (status != GSL_SUCCESS) {
148 MATH_ERROR_MSG(
"GSLRootFinderDeriv::Solve",
"error returned when performing an iteration");
152 status = GSLRootHelper::TestDelta(fRoot, fPrevRoot, absTol, relTol);
153 if (status == GSL_SUCCESS) {
162 while (status == GSL_CONTINUE && iter < maxIter);
164 if (status == GSL_CONTINUE) {
165 double tol = std::abs(fRoot-fPrevRoot);
166 MATH_INFO_MSGVAL(
"GSLRootFinderDeriv::Solve",
"exceeded max iterations, reached tolerance is not sufficient",tol);