10 Float_t x[5],y[5],z[5];
14 void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
16 const Int_t nbins = 5;
22 for (i=0;i<nbins; i++)
25 delta=(z[i]-func(x[i],y[i],par));
34 Double_t func(
float x,
float y,Double_t *par)
40 Double_t value=(par[0]*x+par[1]*y+par[2]);
45 Double_t ffunc(Double_t *x,Double_t *par)
47 Double_t value=(par[0]*x[0]+par[1]*x[1]+par[2]);
75 TH3F *h3d=
new TH3F(
"h3d",
"h3d",6,0,5,6,0,5,11,0,10);
77 h3d->Fill(x[i],y[i],z[i]);
79 h3d->SetMarkerStyle(22);
82 TMinuit *gMinuit =
new TMinuit(5);
91 gMinuit->mnexcm(
"SET ERR", arglist ,1,ierflg);
95 static Double_t vstart[3] = {1,1,1};
96 static Double_t step[3] = {0.01,0.01,0.01};
97 gMinuit->mnparm(0,
"a1", vstart[0], step[0], 0,0,ierflg);
98 gMinuit->mnparm(1,
"a2", vstart[1], step[1], 0,0,ierflg);
99 gMinuit->mnparm(2,
"a3", vstart[2], step[2], 0,0,ierflg);
105 gMinuit->mnexcm(
"MIGRAD", arglist ,2,ierflg);
108 Double_t amin,edm,errdef;
109 Int_t nvpar,nparx,icstat;
110 gMinuit->mnstat(amin,edm,errdef,nvpar,nparx,icstat);
111 gMinuit->mnprin(3,amin);
116 TF2 *ffunc=
new TF2(
"ffunc",ffunc,0,5,0,5,3);
124 for (
int i=0;i<3;i++)
126 gMinuit->GetParameter(i,v,ev);
127 ffunc->SetParameter(i,v);
128 cout<<v<<
" "<<ev<<endl;
129 cout<<ffunc->GetParameter(i)<<endl;
133 ffunc->DrawCopy(
"lego");
134 h3d->DrawCopy(
"same");