Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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///
6/// Find the root of Rosenbrock system of equations:
7/// \f[
8/// f1(x,y) = a(1-x)
9/// \f]
10/// \f[
11/// f2(x,y) = b(y-x^2)
12/// \f]
13/// with:
14/// \f[
15/// a = 1, b=10
16/// \f]
17///
18/// The MultiRootFinder is based on GSL and it requires the MathMore library
19/// installed.
20///
21/// Usage:
22///
23/// ~~~{.cpp}
24/// >.x exampleMultiRoot.C()
25/// ~~~
26///
27/// or
28///
29/// ~~~{.cpp}
30/// >.x exampleMultiRoot(algoname,printlevel)
31/// ~~~
32///
33/// where algoname is for an algorithm not using the derivatives:
34/// hybridS (default) , hybrid, dnewton, broyden
35///
36/// \macro_output
37/// \macro_code
38///
39/// \author Lorenzo Moneta
40
41#include "RConfigure.h"
42
43#ifdef R__HAS_MATHMORE
45#else
46#error libMathMore is not available - cannot run this tutorial
47#endif
49#include "TF2.h"
50#include "TError.h"
51
52// example of using multi root finder based on GSL
53// need to use an algorithm not requiring the derivative
54//like hybrids (default), hybrid, dnewton, broyden
55
56using namespace ROOT::Math;
57void exampleMultiRoot(const char * algo = nullptr, int printlevel = 1) {
59 //defining the function
60 // use Rosenbrock functions
61 TF2 * f1 = new TF2("f1","[0]*(1-x)+[1]*y");
62 TF2 * f2 = new TF2("f2","[0]*(y-x*x)");
63 f1->SetParameters(1,0);
64 f2->SetParameter(0,10);
65 // wrap the functions
68 r.AddFunction(g1);
69 r.AddFunction(g2);
70 r.SetPrintLevel(printlevel);
71
72 // starting point
73 double x0[2]={-1,-1};
74 r.Solve(x0);
75}
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Class for Multidimensional root finding algorithms bassed on GSL.
virtual void SetParameters(const Double_t *params)
Definition TF1.h:685
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:675
A 2-Dim function with parameters.
Definition TF2.h:29
TF1 * f1
Definition legend1.C:11