Custom Fit Functions

I was wondering how to go about entering custom curve-fitting equations.

For example I'd like to try the equation: power = 1/distance^2 + C (I know there is already an existing function for this, I am choosing a simple example as I am more interested in how to go about creating the function).

I tried creating two waves (1. Power, 2. Distance) --> 'Analysis' --> 'Curve fitting' --> 'exp_Xoffset' --> 'New Fit Function'.. but this is where I get lost.

Any suggestions?

Thanks
You are almost there...

After clicking new fit function, a dialog would pop up. (1) type in a desired function name. (2) type "c" in fit coefficient (3) distance in independent variables (4) click "test compile" (5) if successful, click "save fit function now". Now the custom fit function is available for your fitting.
YHLien wrote:
You are almost there...

After clicking new fit function, a dialog would pop up. (1) type in a desired function name. (2) type "c" in fit coefficient (3) distance in independent variables (4) click "test compile" (5) if successful, click "save fit function now". Now the custom fit function is available for your fitting.


And don't forget to enter the expression

f(x) = 1/distance^2 + C

in the expression window. And you may want to read the Curve Fitting chapter in the manual, or in the online help. To read the help, copy this command, paste it into Igor's command line, and press Enter:

DisplayHelpTopic "Curve Fitting"

To read specifically about user-defined fit functions:

DisplayHelpTopic "Fitting to a User-Defined Function"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Ok, great that clears things up (I was entering the wave names in the wrong spot.... among other things)
Ok, now I've got a more pragmatic question:

It wants me to provide a first guess as to what my coefficient should be, and then perhaps I manually iterate until I find an arbitrarily decent approximation. When I get to a more complex fit, is there an 'auto-iterate' setting for finding coefficients?
Kramer51 wrote:
Ok, now I've got a more pragmatic question:

It wants me to provide a first guess as to what my coefficient should be, and then perhaps I manually iterate until I find an arbitrarily decent approximation. When I get to a more complex fit, is there an 'auto-iterate' setting for finding coefficients?


Any non-linear curve fit (all user-defined fits are treated as nonlinear since Igor can't tell what you've written) must iterate from some starting guess. Depending on the fit function, the starting guess may have to be pretty close, or it might not be so stringent.

In the Curve Fitting dialog, on the Coefficients tab, enter what you think are reasonable values for the coefficients, then click the Graph Now button. That will add a fit curve to your graph. If it looks like a reasonable approximation to your data, then click the Do It button and Igor will proceed to attempt a fit by iterating on the solution and using derivatives of your fit function to point in the direction of a better solution. The process may or may not converge depending on a variety of things.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Kramer51 wrote:
Ok, now I've got a more pragmatic question:

It wants me to provide a first guess as to what my coefficient should be, and then perhaps I manually iterate until I find an arbitrarily decent approximation. When I get to a more complex fit, is there an 'auto-iterate' setting for finding coefficients?


If you have a hard time finding those starting values, or Curvefit has a hard time fitting, try using the gencurvefit xop (available on igorexchange). It uses genetic optimisation to fit the data. So long as your parameter limits encompass the best fit you should be able to fit in a much more robust manner.