Logo ROOT  
Reference Guide
exampleMultiRoot.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_math
3/// \notebook -nodraw
4/// Example of using multiroot finder based on GSL algorithm.
5/// Find the root of Rosenbrock system of equations:
6/// \f[
7/// f1(x,y) = a(1-x)
8/// \f]
9/// \f[
10/// f2(x,y) = b(y-x^2)
11/// \f]
12/// with:
13/// \f[
14/// a = 1, b=10
15/// \f]
16///
17/// The MultiRootFinder is based on GSL and it requires the MathMore library
18/// installed
19///
20/// Usage:
21///
22/// ~~~{.cpp}
23/// >.x exampleMultiRoot.C()
24/// ~~~
25///
26/// or
27///
28/// ~~~{.cpp}
29/// >.x exampleMultiRoot(algoname,printlevel)
30/// ~~~
31///
32/// where algoname is for an algorithm not using the derivatives:
33/// hybridS (default) , hybrid, dnewton, broyden
34///
35/// \macro_output
36/// \macro_code
37///
38/// \author Lorenzo Moneta
39
40#include "RConfigure.h"
41
42#ifdef R__HAS_MATHMORE
44#else
45#error libMathMore is not available - cannot run this tutorial
46#endif
48#include "TF2.h"
49#include "TError.h"
50
51// example of using multi root finder based on GSL
52// need to use an algorithm not requiring the derivative
53//like hybrids (default), hybrid, dnewton, broyden
54
55using namespace ROOT::Math;
56void exampleMultiRoot(const char * algo = 0, int printlevel = 1) {
58 //defining the function
59 // use Rosenbrock functions
60 TF2 * f1 = new TF2("f1","[0]*(1-x)+[1]*y");
61 TF2 * f2 = new TF2("f2","[0]*(y-x*x)");
62 f1->SetParameters(1,0);
63 f2->SetParameter(0,10);
64 // wrap the functions
67 r.AddFunction(g1);
68 r.AddFunction(g2);
69 r.SetPrintLevel(printlevel);
70
71 // starting point
72 double x0[2]={-1,-1};
73 r.Solve(x0);
74}
ROOT::R::TRInterface & r
Definition: Object.C:4
Class for Multidimensional root finding algorithms bassed on GSL.
Class to Wrap a ROOT Function class (like TF1) in a IParamMultiFunction interface of multi-dimensions...
virtual void SetParameters(const Double_t *params)
Definition: TF1.h:638
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:628
A 2-Dim function with parameters.
Definition: TF2.h:29
TF1 * f1
Definition: legend1.C:11