31 #ifndef ROOT_Math_RootFinder
32 #define ROOT_Math_RootFinder
89 kGSL_BISECTION, kGSL_FALSE_POS, kGSL_BRENT,
90 kGSL_NEWTON, kGSL_SECANT, kGSL_STEFFENSON
96 RootFinder(RootFinder::EType type = RootFinder::kBRENT);
97 virtual ~RootFinder();
101 RootFinder(
const RootFinder & ) {}
102 RootFinder & operator = (
const RootFinder & rhs)
104 if (
this == &rhs)
return *
this;
110 bool SetMethod(RootFinder::EType type = RootFinder::kBRENT);
120 bool SetFunction(
const IGenFunction & f,
double xlow,
double xup) {
121 return fSolver->SetFunction( f, xlow, xup);
134 bool SetFunction(
const IGradFunction & f,
double xstart) {
135 return fSolver->SetFunction( f, xstart);
138 template<
class Function,
class Derivative>
139 bool Solve(Function &f, Derivative &d,
double start,
140 int maxIter = 100,
double absTol = 1E-8,
double relTol = 1E-10);
142 template<
class Function>
143 bool Solve(Function &f,
double min,
double max,
144 int maxIter = 100,
double absTol = 1E-8,
double relTol = 1E-10);
150 bool Solve(
int maxIter = 100,
double absTol = 1E-8,
double relTol = 1E-10) {
151 return fSolver->Solve( maxIter, absTol, relTol );
157 int Iterations()
const {
158 return fSolver->Iterations();
165 return fSolver->Iterate();
171 double Root()
const {
172 return fSolver->Root();
180 return fSolver->Status();
201 const char * Name()
const {
202 return fSolver->Name();
211 IRootFinderMethod* fSolver;
224 template<
class Function,
class Derivative>
225 bool ROOT::Math::RootFinder::Solve(Function &f, Derivative &d,
double start,
226 int maxIter,
double absTol,
double relTol)
228 if (!fSolver)
return false;
229 ROOT::Math::GradFunctor1D wf(f, d);
230 bool ret = fSolver->SetFunction(wf, start);
231 if (!ret)
return false;
232 return Solve(maxIter, absTol, relTol);
235 template<
class Function>
236 bool ROOT::Math::RootFinder::Solve(Function &f,
double min,
double max,
237 int maxIter,
double absTol,
double relTol)
239 if (!fSolver)
return false;
240 ROOT::Math::WrappedFunction<Function &> wf(f);
241 bool ret = fSolver->SetFunction(wf, min, max);
242 if (!ret)
return false;
243 return Solve(maxIter, absTol, relTol);