Curve Fitting
| Kramer51 | August 22, 2008 - 14:00 | ||
|---|---|---|---|
|
I am relatively new to Igor. I figured out how to graph, and fit very basic curves. Specifically, my data follows the heating and cooling of a sample. I was then told to try to fit it to an "error function". I do not know how to make a fit though. Any advice? |
|||

Joined: 2007-09-12
Location: Australia
This should do it.
Joined: 2007-06-29
Location: United States
And running Andy's code through the Edit Fit Function dialog, you can get the following code with comments that will cause curve fits to be labelled with nice mnemonic coefficient names:
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
Joined: 2008-05-13
Location: United States
Now where do I use this code?
In the command window?
I tried using the Edit Fit Function, but that button was not enabled, only New Fit Function was.
Joined: 2007-06-21
Location: United States
I believe that if you paste it into the procedure window (select Windows->Procedure Windows->Procedure Window), then the Curve Fitting dialog will recognize it. The Curve Fitting dialog looks in the procedure window for functions declared as fit functions.
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.
Joined: 2008-05-13
Location: United States
Thanks, you guys were a lot of help.
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)
Joined: 2007-09-12
Location: Australia
THe function posted above should fit both situations, it converts erf to erfc via the magnitude parameter w[1]
Joined: 2007-06-29
Location: United States
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)
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