Numerical Integration Curve Fitting
SteveHatcher
I am quite new to IGOR but I have figured out how to make a custom least squares fitting routine using the inbuilt tool and the code that it generates. Before IGOR all my curve fitting was done with MATLAB but IGOR considerably speeds things up.
One thing I don’t know how to do, and haven’t found much information on, is curve fitting functions that require numerical integration. For instance fitting int(sin(x*t)/x*t,x = 0..20), where t would be the x wave.
I can do this in MATLAB with a heap of custom code using the quad() function or my own coded Simpson’s rule (for more accuracy), but I am guessing that IGOR can do it too and would like to move all my curve fitting to IGOR. My inexperience with IGOR probably doesn’t help but I am quite fast to learn. So if someone could explain how it would work in the above example that would be great.
Thanks
Area when you want to integrate a curve and the wave has x scaling (trapezoidal)
AreaXY when you want to integrate a curve and you have an associated Xwave (trapezoidal)
Integrate when you want to integrate a curve with different methods (rectangular and trapezoidal).
I also have some code for Gaussian Quadrature, originally from the NIST SANS package.
In the function you listed there don't appear to be any fit coefficients though.
March 7, 2012 at 12:20 am - Permalink
You got a fairly extensive list of suggestions from Andy. I should point out though that the particular function that you show, sin(x*t)/(x*t) should be treated with some caution if using Integrate1d because of the removable singularity at the origin. Also, the method of integration should be sensitive to the magnitude of the parameter t; when t is large you can skip the integration completely and use a FT trick, otherwise you may have to tweak your sampling or use adaptive methods to get accurate results.
A.G.
WaveMetrics, Inc.
March 7, 2012 at 08:47 am - Permalink
The sinc function returns sin(num)/num. The sinc function returns 1.0 when num is zero. num must be real.
March 8, 2012 at 10:08 am - Permalink
Yes, I added the sinc() function to IGOR specifically to get around the removable singularity at the origin. Still, I would recommend the OP to inspect the range of t-values to determine how to handle the integration.
AG
March 9, 2012 at 10:58 am - Permalink
Igor - Thanks, the actual equation is longer than that, so I will probably have to use Integrate1D. There are about 256 t values logarithmically spaces from 1e-9 to 1e4, so its over a huuuge range. Its actually for fitting light-scattering auto correlation functions. So it starts at 1 and goes down to 0.
Thanks again - still getting my head around the power of igor pro.
March 10, 2012 at 06:09 am - Permalink
March 10, 2012 at 01:52 pm - Permalink
Most of my stuff is custom models but I would be interested in having a look, thanks.
March 11, 2012 at 08:45 pm - Permalink
March 12, 2012 at 08:13 pm - Permalink
DisplayHelpTopic "Integrate1D"
You first have to define a user function which generates your values and then you can apply Integrate1D on this function. Like so:
Variable inX
NVAR globalT = ... path to globalT...
return sinc(globalT*inX)
End
The tricky part is to sneak you fitting parameter into the user function via a global variable. You need a fitting function where you put the 't' parameter into a global, do the integration, and feed the result back to you fitting function. Depending on how your integration turns out, an all-at-once fitting may be good, I guess (
DisplayHelpTopic "All-At-Once Fitting Functions"
).March 13, 2012 at 03:43 am - Permalink
If you need further help, you can contact us at support@wavemetrics.com.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 13, 2012 at 08:53 am - Permalink
Bear in mind that this was from ~8 years ago so it could do with some TLC.
March 14, 2012 at 02:15 am - Permalink
thanks andy! I haven't used it on any of my data yet but looking over the code has taught me a few things!
March 17, 2012 at 02:30 am - Permalink
March 17, 2012 at 04:19 pm - Permalink
Hi andy... please excuse this question, but how do you actually run the program? All igor files coded by someone else I have had experience in the past have a compile button which I click first...
Thanks
March 18, 2012 at 12:56 am - Permalink
To see those graphs select Windows->Graphs.
March 18, 2012 at 01:53 am - Permalink