Defining variable in curve fitting

I am new to IGOR programming and I want to fit a long equation to my data. I want to define the equation in parts like:

a: exp((s-v*x)/k)/k;
w: ln(1+a)*(1-(ln(1+ln(1+a))/(2+ln(1+a))));
p: s-k*w;

where p is the final equation and s,k and v are the parameters to be tuned while fitting. Can it be done in IGOR pro so that the return command can be directly written as p?

Thank you,
Rubin.

What is your independent variable and which are your parameters? For example in y = f(p, x) x is the independent variable, and p are the parameters you'd like to fit.
Dear andy,

x is the independent variable and P is the dependent variable to be fit. s, k and v are the parameters that i have to obtain form the fit. Briefly, f(x) = p(x) = s-k*w (s,k and v are constants that has to be determined)
Here is an example of the code.

Function MyFitFunction(ww,xx)
    wave ww
    variable xx
   
    // s = ww[0]
    // v = ww[1]
    // k = ww[2]
   
    // dummy variables
   
    variable a, b, c, rtn
   
    // intermediate steps

    a = exp((ww[0] - ww[1]*xx)/ww[2]) / ww[2]
    b = ln(1 + a)
    c = b*(1 - ln(1 + b))/(2 + b)
   
    // final equation

    rtn = ww[0] - ww[2]*c
   
    return rtn
end


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
Dear JJ Weimer,

Thank you for the examples. But, I am not sure how to use it in the curve fitting procedure?
Copy the code and paste it into the Procedure window. If you modify his code to add the FitFunc procedure subtype, it will also appear in the menu in the Curve Fit dialog:
Function MyFitFunction(ww,xx) : FitFunc
    wave ww
    variable xx
 
    // s = ww[0]
    // v = ww[1]
    // k = ww[2]
 
    // dummy variables
 
    variable a, b, c, rtn
 
    // intermediate steps
 
    a = exp((ww[0] - ww[1]*xx)/ww[2]) / ww[2]
    b = ln(1 + a)
    c = b*(1 - ln(1 + b))/(2 + b)
 
    // final equation
 
    rtn = ww[0] - ww[2]*c
 
    return rtn
end

This is a small correction. I give Dr. Weimer extra points for naming the independent variable "xx" instead of "x", which avoids any possible conflict with Igor's wave assignment function "x".

This could be entered in the New Fit Function dialog by putting the cursor in front of the f(x)= line and hitting Enter to add blank lines. You can then put all that extra code in those blank lines. But I find it easier when a fit function has more than one line to simply do the work in the Procedure window.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
... I give Dr. Weimer extra points for naming the independent variable "xx" instead of "x", which avoids any possible conflict with Igor's wave assignment function "x".


Thanks! We faculty do like to get (and award) bonus points. :-)

Admittedly, I'd forgotten about the FitFunc suffix as the trick to have the function show in the curve fit dialog (mostly because I roll my own routines and control panels anymore).

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH