TF3 variable constraint during minimisation

Hello!

I have TF3 function with variables x,y and z. I have set the ranges of these variables when I define and initialise TF3.

Now I am using GetMinimumXYZ(minX ,minY, minZ) . I want to minimize with a constraint such that minX+minY==1.78 . Is there a way to enforce this during the minimization? If not for TF3 is it possible for TF2 or TF1s?


ROOT Version: 6.14.04
Platform: Ubuntu 18.04
Compiler: 7.3.0


I think you need to create a new 2D function from your 3D one and minimize this new 2D function:

double My2D(double x, double z) { return My3D(x, 1.78 - x, z); }

So would this work something like this (just taking a rough example to understand how to execute it):

Please note that here I have used an example 3D function as my actual function is very complicated.

Double_t My3D(Double_t x, Double_t y, Double_t z, Double_t *par){
return par[0]*x+par[1]*y+par[2]*z;
}

Double_t My2D(Double_t x, Double_t z, Double_t *para) { return My3D(x, 1.78 - x, z, para); }

TF2 *ftest=new TF2(“ftest”,My2D, 0,2,0,2, 3);
ftest->SetParameters(1,1,1);

Double_t minX;
Double_t minY;
ftest->GetMinimumXY(minX,minY);

Double_t My3D(const Double_t *x, const Double_t *par) {
  return par[0] * x[0] + par[1] * x[1] + par[2] * x[2] - 2.78;
}

Double_t My2D(const Double_t *x, const Double_t *par) {
  Double_t xx[] = {x[0], 1.78 - x[0], x[1]};
  return My3D(xx, par);
}

void trial(void) {
  TF3 *f3D = new TF3("f3D", My3D, 0., 2., 0., 2., 0., 2., 3);
  f3D->SetParameters(1., 1., 1.);
  new TCanvas("c3D"); f3D->Draw();
  TF2 *f2D = new TF2("f2D", My2D, 0., 2., 0., 2., 3);
  f2D->SetParameters(1., 1., 1.);
  new TCanvas("c2D"); f2D->Draw("surf2z");
}

Thank you that solved the problem!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.