I am trying to use the Minuit2Minimizer example code in this page :
#include "Minuit2/Minuit2Minimizer.h"
#include "Math/Functor.h"
double RosenBrock(const double *xx )
{
const Double_t x = xx[0];
const Double_t y = xx[1];
const Double_t tmp1 = y-x*x;
const Double_t tmp2 = 1-x;
return 100*tmp1*tmp1+tmp2*tmp2;
}
int NumericalMinimization()
{
// Choose method upon creation between:
// kMigrad, kSimplex, kCombined,
// kScan, kFumili
ROOT::Minuit2::Minuit2Minimizer min ( ROOT::Minuit2::kMigrad );
min.SetMaxFunctionCalls(1000000);
min.SetMaxIterations(100000);
min.SetTolerance(0.001);
ROOT::Math::Functor f(&RosenBrock,2);
double step[2] = {0.01,0.01};
double variable[2] = { -1.,1.2};
min.SetFunction(f);
// Set the free variables to be minimized!
min.SetVariable(0,"x",variable[0], step[0]);
min.SetVariable(1,"y",variable[1], step[1]);
min.Minimize();
const double *xs = min.X();
cout << "Minimum: f(" << xs[0] << "," << xs[1] << "): "
<< RosenBrock(xs) << endl;
return 0;
}
This code is used to calculate the global minimum of the Rosenbrock function:
In this example code, it explicitly assigned a to be equal to 1 and b to be equal 100.
I would like to modify this code and include into a main program that asks the user for input a and b instead of pre-assigning them.
I first tried to modify the arguments of the RosenBrock function:
double RosenBrock(const double *xx, int user_input_a, int user_input_b)
without changing any other part of the example code.
When I tried to compile, I get the error s
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/include/Math/Functor.h:120:21: error: too few arguments to function call, expected 3, have 1
return fFunc(x);
~~~~~ ^
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/include/Math/Functor.h:90:4: note: in instantiation of member function
'ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (*)(const double
*, int, int)>::DoEval' requested here
FunctorHandler(unsigned int dim, const Func & fun ) :
^
/cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/include/Math/Functor.h:422:17: note: in instantiation of member function
'ROOT::Math::FunctorHandler<ROOT::Math::Functor, double (*)(const double
*, int, int)>::FunctorHandler' requested here
fImpl(new FunctorHandler<Functor,Func>(dim,f) )
^
/afs/hep.man.ac.uk/u/taeny/NumericalMinimization.C:24:24: note: in instantiation of function template specialization
'ROOT::Math::Functor::Functor<double (*)(const double *, int, int)>'
requested here
ROOT::Math::Functor f(&RosenBrock,2);
What is the correct way to modify the example code so that I can define the variables a and b when the program is running instead of defining them at compile time?