Defining variable in curve fitting
rubindg
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.
June 4, 2017 at 06:28 pm - Permalink
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)
June 5, 2017 at 01:57 am - Permalink
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
June 5, 2017 at 05:31 am - Permalink
Thank you for the examples. But, I am not sure how to use it in the curve fitting procedure?
June 5, 2017 at 08:45 am - Permalink
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
June 5, 2017 at 09:37 am - Permalink
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
June 5, 2017 at 09:42 am - Permalink
June 5, 2017 at 10:37 am - Permalink