# How to use Simplex method if I fit data via TGrapherrors?

Hello!

I have some data and I want to fit them via TGrapherrors.
Simple working example:

``````Double_t fitFunction(Double_t *x,Double_t *par)
{
return pow((x[0] - par[2])*par[0], 2.0) + par[1] ;
}

void Fit()
{
double noise_amp = 300;

vector<double> xv;
vector<double> yv;

vector<double> xverr;
vector<double> yverr;

//fill vectors ...
for(int i = -10; i < 20; i++)
{
xv.push_back(i);
yv.push_back( (pow((i - 3.5)*5, 2.0) + 3) + noise_amp*gRandom->Uniform(-1, 1) );

xverr.push_back(0);
yverr.push_back(noise_amp);
}

TGraphErrors * gr = new TGraphErrors(xv.size(), &xv[0], &yv[0], &xverr[0], &yverr[0]);
TF1 *fitFcn = new TF1("fitFcn", fitFunction, -10, 20, 3);

gr->SetMarkerColor(4);
gr->SetMarkerStyle(kFullCircle);

fitFcn->SetParameter(0, 1);
fitFcn->SetParLimits(0, 0, 10);

fitFcn->SetParameter(1, 1);
fitFcn->SetParLimits(1, -100, 100);

fitFcn->SetParameter(2, 1);
fitFcn->SetParLimits(2, -10, 10);

gr->Fit("fitFcn", "R");
gr->Draw("AP");
}``````

Fit output:

FCN=11.0093 FROM MIGRAD STATUS=CONVERGED 151 CALLS 152 TOTAL
EDM=5.29839e-009 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 4.98654e+000 8.20970e-002 1.81640e-005 -7.58911e-003
2 p1 4.75633e+000 7.30459e+001 9.28010e-004 4.10195e-005
3 p2 3.57784e+000 1.30813e-001 2.29281e-005 -1.90659e-004

As I know, TGraphErrors use Minuit in order to find miminum.
There are a lot of methods to find miminum in Minuit and MIGRAD is default method.
I want to use Simplex method. How to do this?

If I have TMinuit object “minuit”, I can use minuit.mnsimp(), but I don’t know how to get minuit object.
Moreover, I want to change number of iteration, but I must have TMinuit object too.

``root[] ROOT::Math::MinimizerOptions::SetDefaultMinimizer("Minuit", "Simplex")``