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[0]
//CurveFitDialog/ r2 = ww[1]
//CurveFitDialog/ k1 = ww[2]
//CurveFitDialog/ k2 = ww[3]
//CurveFitDialog/ Keq = ww[4]
// Dummy variables
variable a11, a12, a22, a21, l1, l2, rtn1, rtn2, rtn3, rtn4, frtn

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

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.

Thank you in advance.

Rubin.

Instead of using r1, r2, k1 and k2 as fit coefficients, use r1, r2, k1, and keq. Inside your fitting function (assuming keq is at ww[3]) you would use

Variable k2 = ww[2]*ww[3]

When you do the fit, you must remember to hold that coefficient. In the Curve Fit dialog, you can simply turn on the Hold checkbox in the coefficients list in the Coefficients tab. On the command line, or in Igor code you would use /H="0001" to hold that coefficient.

It can be hard to abandon a function parameter!

The main flaw is that it is too easy to forget to hold the ratio coefficient.