I am trying to write a fit function that requires numerical integration of a function with three parameters: one fixed, one fit parameter, and the integration variable. I noticed that Integrate1D can only call user functions with a single local variable, and others need to be passed as global variables. Will it cause problems that one of my fit parameters is a global variable?
Suppose you have a fitting function that has two fitting variables w[0] and w[1]. Suppose further that w[1] is involved in the integration function. Your fitting function will look like this:
Function integrationFitFunction(w,x) : FitFunc Wave w Variablex
return myIntegrationFunction(w,x) End
Function myIntegrationFunction(w,inX) Wave w Variable inX
// assuming you are in root: create the global and set its value. Variable/G param1=w[1] // e.g., integrating from 0 to 1 the integrand shown below. return w[0]+Integrate1D(integrationFunction,0, 1) End
Function integrationFunction(inX) Variable inX
NVAR param1=root:param1 // return the integrand expression using inX and param1, // e.g. for a simple param1*inX return param1*inX End
Suppose you have a fitting function that has two fitting variables w[0] and w[1]. Suppose further that w[1] is involved in the integration function. Your fitting function will look like this:
Wave w
Variable x
return myIntegrationFunction(w,x)
End
Function myIntegrationFunction(w,inX)
Wave w
Variable inX
// assuming you are in root: create the global and set its value.
Variable/G param1=w[1]
// e.g., integrating from 0 to 1 the integrand shown below.
return w[0]+Integrate1D(integrationFunction,0, 1)
End
Function integrationFunction(inX)
Variable inX
NVAR param1=root:param1
// return the integrand expression using inX and param1,
// e.g. for a simple param1*inX
return param1*inX
End
I hope this helps,
A.G.
January 17, 2017 at 03:15 pm - Permalink