Numerical Integration Curve Fitting

Hi Guys,

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
Integrate1D when you have an analytic function you want to integrate
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.
Hello Steve,

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.
Isn't that what Igor's 'sinc' function is for?
sinc(num )
The sinc function returns sin(num)/num. The sinc function returns 1.0 when num is zero. num must be real.
s.r.chinn wrote:
Isn't that what Igor's 'sinc' function is for?
sinc(num )
The sinc function returns sin(num)/num. The sinc function returns 1.0 when num is zero. num must be real.


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
Andy - thanks, I jumped into the help menu once I knew the commands I should be looking for and found some very helpful information.

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.
andyfaff wrote:
I have some code to fit autocorrelation functions, it you'd like it.


Most of my stuff is custom models but I would be interested in having a look, thanks.
Ok, after a bit of a play around im still a bit confused how to implement the function Integrate1d in a curve fit. I using the curve fitting dialog and where I would put something like f() = sin(x*t)/(x*t) where x is the fitting parameter and t is the y wave, I tried f() = Integrate1D(sin(x*t)/(x*t)). Igor doesn't seem to like that. I am guessing I need to make a program in the procedure window that it calls somehow? Any help would be appreciated thanks.
The Integrate1D function does not work that way, as you can see here: 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:

Function MySincFunc(inX)
    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").
Here is some code for fitting a Monomodal distribution to light scattering data. The size distribution is fairly flexible in what it can do.
Bear in mind that this was from ~8 years ago so it could do with some TLC.
LSgex.pxp (217.18 KB)
andyfaff wrote:
Here is some code for fitting a Monomodal distribution to light scattering data. The size distribution is fairly flexible in what it can do.
Bear in mind that this was from ~8 years ago so it could do with some TLC.


thanks andy! I haven't used it on any of my data yet but looking over the code has taught me a few things!
andyfaff wrote:
my coding has improved immeasurably since then.


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
There should be a table containing the wave coef_GEX. Try changing the values in that wave and see how the autocorrelation function and the graph of the size distribution changes.

To see those graphs select Windows->Graphs.