Curve Fitting
Kramer51
One problem I was just confronted with was fitting a curve to a custom fit.
Instead of any of the Igor provided fits, I would like to make one.
Specifically, my data follows the heating and cooling of a sample.
I tried fitting the cooling part of the curve to an exponential, but that did not fit well.
I was then told to try to fit it to an "error function". I do not know how to make a fit though.
I attached the formula for the error function.
Any advice?
Wave w
variable x
//w[0] = background
//w[1] = direction and magnitude of function
//w[2] = position of centre
//w[3] = width of erf
if(abs(w[3])<1e-40)
w[3] = 1e-40
endif
return w[0]+w[1]*erf((w[2]-x)/(abs(w[3])*sqrt(2)))
End
August 22, 2008 at 02:43 pm - Permalink
Wave w
Variable x
//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Equation:
//CurveFitDialog/ //w[0] = background
//CurveFitDialog/ //w[1] = direction and magnitude of function
//CurveFitDialog/ //w[2] = position of centre
//CurveFitDialog/ //w[3] = width of erf
//CurveFitDialog/ if(abs(w)<1e-40)
//CurveFitDialog/ w = 1e-40
//CurveFitDialog/ endif
//CurveFitDialog/
//CurveFitDialog/ f(x) = y0+a*erf((x0-x)/(abs(w)*sqrt(2)))
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ x
//CurveFitDialog/ Coefficients 4
//CurveFitDialog/ w[0] = y0
//CurveFitDialog/ w[1] = A
//CurveFitDialog/ w[2] = x0
//CurveFitDialog/ w[3] = w
//w[3][0] = background
//w[3][1] = direction and magnitude of function
//w[3][2] = position of centre
//w[3][3] = width of erf
if(abs(w[3])<1e-40)
w[3] = 1e-40
endif
return w[0]+w[1]*erf((w[2]-x)/(abs(w[3])*sqrt(2)))
End
Execute this command on Igor's command line to read all about curve fitting using the dialog:
DisplayHelpTopic "Curve Fitting Using the Curve Fitting Dialog"
That includes a section on doing user-defined fits:
DisplayHelpTopic "Fitting to a User-Defined Function"
Of course, part of your problem is that you have the fundamental defining equation for the error function, which doesn't tell you that Igor includes a built-in function that saves you having to figure out how to do that integration yourself.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
August 26, 2008 at 10:59 am - Permalink
In the command window?
I tried using the Edit Fit Function, but that button was not enabled, only New Fit Function was.
August 27, 2008 at 02:22 pm - Permalink
If you get a compile error after copying from your browser and pasting into the procedure window, this is because the browser (Safari on Macintosh I think) uses non-breaking spaces instead of regular spaces. When this happens, Igor will select the offending character in the procedure window. Merely replace it with a space.
August 27, 2008 at 07:42 pm - Permalink
Just out of curiosity, where did you get that formula for the error function?
That looks quite a bit different from the error function I posted earlier.
Actually, I need the complimentary error function (erfc),
but that is simply:
erfc(x) = 1 - erf(x)
August 29, 2008 at 12:56 pm - Permalink
August 29, 2008 at 05:16 pm - Permalink
The integral you posted is the fundamental definition of the error function. Igor has a built-in function that returns values of the integral, but without actually having to do any integration.
The "extra" stuff added to the fitting function modifies the standard error function so that the fit can change vertical offset (w[0]), the amplitude (w[1]), the X position (w[2]) and the width (w[3]). My version of the function simply adds some comments to the function that Igor's curve fitting code will interpret so that it can use mnemonic names for the fitting coefficients. That is, Y0 for vertical offset, A for amplitude, x0 for X position, and w for width.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
September 2, 2008 at 11:13 am - Permalink