# Conditional curve fitting Dear Users,

I wrote a user defined fitting code for my data with coefficients r1, r2, k1 and k2. Now I want to fit an equation while holding the ratio of k1/k2 to some number. For this I first created an extra coefficient Keq and want to hold that value in the fitting dialog box, however I cannot find any reference of how to put the condition in the fitting procedure so that it will fit my data keeping the Keq constant and give me the best fit value for r1, r2, k1 and k2 respectively.

Function kex_Kay(ww,xx):FitFunc
wave ww
variable xx
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ r1 = ww
//CurveFitDialog/ r2 = ww
//CurveFitDialog/ k1 = ww
//CurveFitDialog/ k2 = ww
//CurveFitDialog/ Keq = ww
// Dummy variables
variable a11, a12, a22, a21, l1, l2, rtn1, rtn2, rtn3, rtn4, frtn

// Intermediate steps
a11 = ww+ww
a12 = -ww
a22 = ww+ww
a21 = -ww
l1 = 0.5*((a11+a22)+sqrt((a11-a22)^2+4*ww*ww))
l2 = 0.5*((a11+a22)-sqrt((a11-a22)^2+4*ww*ww))

rtn1 = (-(l2-a11)*exp(-l1*xx)+(l1-a11)*exp(-l2*xx))/(l1-l2)
rtn2 = (-(l2-a22)*exp(-l1*xx)+(l1-a22)*exp(-l2*xx))/(l1-l2)
rtn3 = (a21*exp(-l1*xx)-a21*exp(-l2*xx))/(l1-l2)
rtn4 = (a12*exp(-l1*xx)-a12*exp(-l2*xx))/(l1-l2)

//Final equation
frtn = (rtn3+rtn4)/(rtn1+rtn2)
return frtn
end

Any help is much appreciated.

`Variable k2 = ww*ww`