#include "Math/IFunction.h"
#include "Math/GSLRootFinder.h"
#include "Math/GSLRootHelper.h"
#include "GSLRootFSolver.h"
#include "GSLFunctionWrapper.h"
#include "gsl/gsl_roots.h"
#include "gsl/gsl_errno.h"
namespace ROOT {
namespace Math {
GSLRootFinder::GSLRootFinder()
{
fFunction = new GSLFunctionWrapper();
}
GSLRootFinder::~GSLRootFinder()
{
if (fFunction) delete fFunction;
}
GSLRootFinder::GSLRootFinder(const GSLRootFinder &)
{
}
GSLRootFinder & GSLRootFinder::operator = (const GSLRootFinder &rhs)
{
if (this == &rhs) return *this;
return *this;
}
void GSLRootFinder::SetFunction( GSLFuncPointer f, void * p, double xlow, double xup) {
fXlow = xlow;
fXup = xup;
fFunction->SetFuncPointer( f );
fFunction->SetParams( p );
gsl_root_fsolver_set( fS->Solver(), fFunction->GetFunc(), xlow, xup);
}
void GSLRootFinder::SetFunction( const IGenFunction & f, double xlow, double xup) {
fXlow = xlow;
fXup = xup;
fFunction->SetFunction( f );
gsl_root_fsolver_set( fS->Solver(), fFunction->GetFunc(), xlow, xup);
}
void GSLRootFinder::SetSolver(GSLRootFSolver * s ) {
fS = s;
}
void GSLRootFinder::FreeSolver( ) {
if (fS) delete fS;
}
int GSLRootFinder::Iterate() {
if (!fFunction->IsValid() ) {
std::cerr << "GSLRootFinder - Error: Function is not valid" << std::endl;
return -1;
}
int status = gsl_root_fsolver_iterate(fS->Solver());
fRoot = gsl_root_fsolver_root(fS->Solver() );
fXlow = gsl_root_fsolver_x_lower(fS->Solver() );
fXup = gsl_root_fsolver_x_upper(fS->Solver() );
return status;
}
double GSLRootFinder::Root() const {
return fRoot;
}
const char * GSLRootFinder::Name() const {
return gsl_root_fsolver_name(fS->Solver() );
}
int GSLRootFinder::Solve (int maxIter, double absTol, double relTol)
{
int iter = 0;
int status = 0;
do {
iter++;
status = Iterate();
if (status != GSL_SUCCESS) return status;
status = GSLRootHelper::TestInterval(fXlow, fXup, absTol, relTol);
if (status == GSL_SUCCESS) {
fIter = iter;
return status;
}
}
while (status == GSL_CONTINUE && iter < maxIter);
return status;
}
}
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.