Logo ROOT  
Reference Guide
RootFinder.cxx
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: David Gonzalez Maline 01/2008
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 , LCG ROOT MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11#include "Math/RootFinder.h"
14
15#include "RConfigure.h"
16
17#ifndef MATH_NO_PLUGIN_MANAGER
18
19#include "TROOT.h"
20#include "TPluginManager.h"
21
22#else // case no plugin manager is available
23#ifdef R__HAS_MATHMORE
25#endif
26
27#endif
28
29#include <cassert>
30
31#include "Math/Error.h"
32
33namespace ROOT {
34namespace Math {
35
36
38 fSolver(0)
39{
40 // constructor passing type (default is kBRENT)
42}
43
45{
46 // set method - Use the plug-in manager if method is implemented in MathMore
47 if ( type == RootFinder::kBRENT )
48 {
50 return true;
51 }
52
53#ifdef MATH_NO_PLUGIN_MANAGER // no PM available
54#ifdef R__HAS_MATHMORE
55
56 switch(type) {
57
58 case kGSL_BISECTION:
60 break;
61 case kGSL_FALSE_POS:
63 break;
64 case kGSL_BRENT:
66 break;
67 case kGSL_NEWTON:
69 break;
70 case kGSL_SECANT:
72 break;
73 case kGSL_STEFFENSON:
75 break;
76 default:
77 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
78 fSolver = 0;
79 return false;
80 break;
81 };
82
83#else
84 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
85 return false;
86#endif
87
88#else // case of using Plugin Manager
90 std::string stype;
91
92 switch(type) {
93
94 case kGSL_BISECTION:
95 stype = "Bisection";
96 break;
97 case kGSL_FALSE_POS:
98 stype = "FalsePos";
99 break;
100 case kGSL_BRENT:
101 stype = "Brent";
102 break;
103 case kGSL_NEWTON:
104 stype = "Newton";
105 break;
106 case kGSL_SECANT:
107 stype = "Secant";
108 break;
109 case kGSL_STEFFENSON:
110 stype = "Steffenson";
111 break;
112 default:
113 MATH_ERROR_MSG("RootFinder::SetMethod","RootFinderMethod type is not available in MathCore");
114 fSolver = 0;
115 return false;
116 break;
117 };
118
119 if ((h = gROOT->GetPluginManager()->FindHandler("ROOT::Math::IRootFinderMethod", stype.c_str() ))) {
120 if (h->LoadPlugin() == -1) {
121 MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
122 return false;
123 }
124
125 fSolver = reinterpret_cast<ROOT::Math::IRootFinderMethod *>( h->ExecPlugin(0) );
126 assert(fSolver != 0);
127 }
128 else {
129 MATH_ERROR_MSG("RootFinder::SetMethod","Error loading RootFinderMethod");
130 return false;
131 }
132
133#endif
134
135 return true;
136}
137
138
140{
141 // destructor
142 delete fSolver;
143}
144
145
146}
147}
#define MATH_ERROR_MSG(loc, str)
Definition: Error.h:82
#define h(i)
Definition: RSha256.hxx:106
int type
Definition: TGX11.cxx:120
#define gROOT
Definition: TROOT.h:415
Class for finding the root of a one dimensional function using the Brent algorithm.
Interface for finding function roots of one-dimensional functions.
bool SetMethod(RootFinder::EType type=RootFinder::kBRENT)
Definition: RootFinder.cxx:44
RootFinder(RootFinder::EType type=RootFinder::kBRENT)
Construct a Root-Finder algorithm.
Definition: RootFinder.cxx:37
IRootFinderMethod * fSolver
Definition: RootFinder.h:211
Roots::Bisection Bisection algorithm, simplest algorithm for bracketing the roots of a function,...
Brent-Dekker algorithm which combines an interpolation strategy with the bisection algorithm See the ...
False Position algorithm based on linear interpolation.
a Newton algorithm, which computes the derivative at each iteration See the GSL manual for more infor...
Secant algorithm, simplified version of Newton method, which does not require the derivative at every...
Steffenson method, providing the fastes convergence.
Namespace for new Math classes and functions.
VSD Structures.
Definition: StringConv.hxx:21