Please advise: Curve-fitting based on the equation obtained by numeric integration

Dear,

My situaion is little complex.
I have a equation as a function of x for curve-fitting.
The problem is that I have to get the equation by numerical integration with respect to y, another variable:

My fitting (x) = Integrate from y=0 to y=Pi; cos(x-y)*exp(cos(y))*dy

I think that the Igor cannot do symbolic integration in my case but there should be a way to get the solution.

Could you please help me out how to solve this problem?
Thanks in advance.

Jongill
You can do the integration numerically using Integrate1D. Integrate1D has no provision for passing the values of coefficients to the function it integrates, so you will have to create a global variable to pass the value of X from the fitting function to the integrand function.

If you run into troubles, you can contact support@wavemetrics.com.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
Dear John.

I really appreiate your quick answer for my post.

Unfortunately, I was so stupid that I realized that I did not ask what I intended to ask. You IntegratedID can certainly solve my problem on the Forum.

Please give me an additional advice on the following problem if you have time. I again really appreciate your valuable time and kindness.

The problem I have is that my fitting parameter w_coef[0] should be located in my "user-defind function1" for the first integration wrt a y variable. When I recall the "user-defind function1," in my curve-fitting function with a variable x, the fitting does not work with the w_coef[0] and w_coef[1]. I defined w_coef[0] as a golbal variable, which seems to be the problem maker.

How can I recall the w_coef[0] in my fitting function for curve-fitting? Please see below the igor procedure that I used, which does not work :-)

Could you please let me know the way to solve this problem?
Thanks again.

Best,

Jongill

Function/D UserDefinedFunction1(yy)
Variable/D yy
Variable/D kk = 1 // constant (actually another fitting coefficient)

NVAR globalX=globalX
NVAR globalW=globalW

return cos(globalX-yy)*(exp(kk*cos(yy-globalW))/2*pi*bessI(0,kk))
End


Function/D MyFtting(w, x)
Wave/D w
Variable/D x

NVAR globalX=globalX
globalX = x
NVAR globalW=globalW
globalW=w[0]

return w[1]*integrate1D(UserDefinedFunction1, 0, 2*pi, 0)
End

Jongill also sent his follow-up to support@wavemetrics.com. For the benefit of others who might read this, I sent him this reply:

>I defined w_coef[0] as a golbal variable, which seems to be the problem maker.
>
>How can I recall the w_coef[0] in my fitting function for curve-fitting? I
>am attaching the igor procedure and the the experiment that I used, which
>does not work :-)

NVAR doesn't create a global variable, it just looks up a pre-existing global variable and makes a local reference to it. One way to make this work would be to change MyFitting() to use Variable/G:
Function/D MyFtting(w, x)
    Wave/D      w
    Variable/x

    Variable/G  globalX=globalX
            globalX = x
    Variable/G  globalW=globalW
            globalW=w[0]
   
    return      w[1]*integrate1D(UserDefinedFunction1, 0, 2*pi, 0)
End

This way, MyFitting() will create the global variables if they don't exist already. Then the NVAR statements in UserDefinedFunction1() will connect with those variables.


Another way to handle this is to have a third function that runs before you start the fit. This function would create any needed global variable or waves. Then the NVAR statements in UserDefinedFunction1() and MyFtting() would work.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com