fitting data to a numerical integral

Hello,
I have data that is modeled by a function that involves an integral with no closed form, i.e.

f(x)=\int_0^\infty a(x,t)b(t)dt

there are a few parameters in a(x,t) and b(t) that I want to find by fitting data, but I don't know how to get igor to fit to a function that requires numerical integration. I have done a lot with fitting to user defined functions that are of a closed form, but have not done any igor fitting with numerical functions.
Is the integral to be computed once for each data point? If so, then you can write a normal fit function that calls Integrate1D. The tricky part is that Integrate1D doesn't take a coefficient wave, so you need to pass the coefficients to the integrand via globals or a wave that the integrand function can look up, as it were, behind Integrate1D's back.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote:
The tricky part is that Integrate1D doesn't take a coefficient wave, so you need to pass the coefficients to the integrand via globals or a wave that the integrand function can look up, as it were, behind Integrate1D's back.



can you elaborate on this? I've never used the Integrate 1D before so not sure exactly what you mean.
There are some examples of the use of Integrate1D:

DisplayHelpTopic "Integrating a User Function"

The examples will show you the basic use of Integrate1D. The point I was making is that if your integrand has variable coefficients:

a(x,t;a,b,c)

and you are integrating with respect to t, then the only variable that can be passed to the integrand function is t. So you would write a function something like:
Function aIntegrand(tt)
    Variable tt
   
    NVAR a, b, c, xx
   
    return <some expression containing a, b, c, xx and tt>
end


In order to use the function, you will also need to create the global variables a,b,c and xx. You might do that inside the fit function:
Function fitAIntegral(w, inx) : FitFunc
    Wave w
    Variable inx
   
    Variable/G a = w[0]
    Variable/G b = w[1]
    Variable/G c = w[2]
    Variable/G xx = inx
   
    return Integrate1D(aIntegrand, 0, somethinglarge, options)
end

I have left some pretty important details for you to figure out, like what "somethinglarge" should be. Hopefully your integrand is well-behaved and approaches zero at large t. It is really tough to do a numerical integration truly to infinity!

DO NOT try to write the fitting function and do a fit until you have tested the integrand function, and the use of Integrate1D outside of fitting. Going straight to fitting introduces too many layers of new stuff to debug all at the same time.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Hi Sleepingawake86,

This is also something I wanted to do, and posted about a few months back (http://www.igorexchange.com/node/2868). I didn't have time to play around with it too much back then, so went for a simpler, less effective approach using MATLAB. Did you get any code working that does this? If so I would be interested to see how you got it working. Igor and John were a great help, but it still seemed beyond what I can do in IGOR. When I get some more time I will revisit this problem though.

Thanks