User defined FitFunc with Constants

I thought I could do this (many years ago) but I cannot find it now, and searching the manuals and forums has drawn a blank.

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])

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,
You can't do it just like the built-in functions. The easiest way is to do as you said- just hold the constants. If you are patient, and willing to put in extra effort, you can write a structure-based fit function.

John Weeks
WaveMetrics, Inc.
In: displayhelptopic "curvefit"

WaveMetrics say:
/K={constants} Sets values of constants (not fit coefficients) in certain fitting functions. For instance, the exp_XOffset function contains an X offset constant. Built-in functions will set the constant automatically, but the automatic value can be overridden using this flag.

constants is a list of constant values, e.g., /K={1,2,3}. The length of the list must match the number of constants used by the chosen fit function.

This flag is not currently supported by the Curve Fit dialog. Use the To Cmd button and add the flag on the command line.

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.

Yes- I forgot to mention the possibility of using a global variable for the constants. But I don't really like that option as it hides the constants. A held coefficient is included in the coefficient wave and printed in the history report.

John Weeks
WaveMetrics, Inc.
Thank you both for your answers. I shall continue with using the constant as a parameter that is held.