# Setting Fit parameters bounds relative to each other

Good day.

I have the equation

``````double fitrange_low = 75;
double fitrange_hgh = 560;
TF1 *fm3 = new TF1("fm3","(x<)*(-/(x**2)) + (x> && x<)*(-/(**2)) + (x> && x>)*(-/(**2)+(*(x-)**2))",fitrange_low,fitrange_hgh);
``````

that I am fitting to a range of experimental data where the two parameters  and  are being used to the transition between different parts of the equation.

 should always be less than or equal to . Is there a way to enforce that limit when fitting to a graph?

I have used set fm3->SetParLimits() and SetParameter(), but the high and low range can overlap between different data sets so that is not enough as I don’t want to tune 100+ fittings by hand.

I think you should use something like this

[code]Double_t myFunction(Double_t x, Double_t par)
{
Float_t xx =x;
Double_t f = (xx<par)
(par-par/(xx**2)) + (xx>par && x<par)
(par-par/(par**2)) + (xx>par && xx>par)(par-par/(par**2)+(par(xx-par)**2;
if(par>par) return -1000000; // if  is greater than  then, the function takes a crap value in order the fit do not converge for this set of parameters
return f;
}
void myfit()
{
TF1 * f = new TF1(“f”,myFunction,75,560,5); //5 parameters
// you can now use f to fit what you want.

}[/code]

That looks like it solves the problem. Thank you for your help.

To make it compile with te + option on the Root command line I had to change from **2 to square things to TMath::Power( , 2.0) as shown below.

``````Double_t myFunction(Double_t *x, Double_t *par)
{
Float_t xx =x;
Double_t f = (xx<par)*(par-par/(TMath::Power(xx , 2.0)))
+ (xx>par && xx<par)*(par-par/(TMath::Power(par,2.0)))
+ (xx>par && xx>par)*(par-par/(TMath::Power(par,2.0))+(par*TMath::Power((xx-par),2.0)));

if(par>par) return -1000000; // if  is greater than  then, the function takes a crap value in order the fit do not converge for this set of parameters
return f;
}``````