User defined FitFunc with Constants
KurtB
I want to write my own fitting function, but where some parameters would need to be Constant. To test this concept I am trying to mimic the built-in exp_XOffset function, where the parameter X0 is a Constant, and can be set in the Curve Fitting GUI. How would I write my user defined function to behave in the same way?
As a starter, here is a user function where all the parameters are coefficients:
Function mySingleExp(w,x) : FitFunc
Wave w
Variable x
//CurveFitDialog/ Equation:
//CurveFitDialog/ f(x) = y0 + A * exp(-(x - x0) / tau)
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ w[0] = y0
//CurveFitDialog/ w[1] = A
//CurveFitDialog/ w[2] = tau
//CurveFitDialog/ w[3] = x0
return w[0] + w[1] * exp(-(x - w[3]) / w[2])
End
Wave w
Variable x
//CurveFitDialog/ Equation:
//CurveFitDialog/ f(x) = y0 + A * exp(-(x - x0) / tau)
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ w[0] = y0
//CurveFitDialog/ w[1] = A
//CurveFitDialog/ w[2] = tau
//CurveFitDialog/ w[3] = x0
return w[0] + w[1] * exp(-(x - w[3]) / w[2])
End
I know I could just set the value in the (predetermined) coefficient wave and then hold it, but this is not the 'elegant' solution I am looking for.
Thanks in advance for any pointers,
Kurt
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 6, 2017 at 09:32 am - Permalink
displayhelptopic "curvefit"
WaveMetrics say:
As I understand it, the above help note applies only to the specific built-in functions which WaveMetrics wrote which support this flag to be passed.
Unfortunately, I don't know of a way to define a parameter as a constant to a user-defined function, and thus all hope is lost. The user-defined fit-function would have to be defined in an XOP, but even then, it is unclear how to trick the
curvefit
dialog into accepting it properly (as in exp_XOffset). I tried a few things without success.If WaveMetrics post the code to
exp_XOffset
it can be done.For now constraining the variable is the most user-friendly choice. You can check what is the performance impact of this, I guess. Next would be wrapping the fit function in another function, emulating the "constant" with a conditionally set variable outside of the
funcfit
operation to avoid slow downs.best,
_sk
October 6, 2017 at 09:37 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
October 6, 2017 at 09:45 am - Permalink
Regards,
Kurt
October 8, 2017 at 11:00 pm - Permalink