## Curve Fitting an integral that has limits that are from a wave

dwillia5
Posts: 4
Joined: 2011-08-16
Location: United States

Hi,
I am trying to fit data to an integral whose limits vary for each point - the Callaway model for thermal conductivity. I have a wave with x data and a wave with y data (Nine points in each wave). I need to fit the data to an integral whose limits go from 0 to a constant/x[i] for each x[i] and y[i] pair. Everything compiles, but IGOR tells me I have a BAD USER FUNCTION FORMAT when I try to fit the data. Below is what I have tried so far. Any help would be appreciated!
Thanks

//This is the user-defined fitting function:

Variable/G Alpha=A, Beta1=B1, Beta2=B2, Length = L //Parameters to be fitted
Variable/G Temp=T //Wave with the independent variable
f(T) = Real(Integrate1d(eqn, .001, 281/Temp)) //This is what I want to do, but ...

//This is the function it calls:
Function eqn(x)
Variable x
NVAR Alpha, Beta1, Beta2, Length
NVAR Temp
// A bunch of variables - The constants are defined at the top of the procedure file as they should be, I just stuck them below for now
Variable Pre = (kB/(2*Pi*Pi*c))*((kB*Temp/hbar)^3)
Variable Tp = Alpha*x^4*Temp^4
Variable Tb = c/Length
Variable Tn = Beta2*(Temp^5)*(x^2)
Variable Tc = (Tp+Tb+Tu+Tn)^-1
// The equation I want to integrate
Return Pre*Tc*((x^4)*exp(x))/((exp(x)-1)^2)
End

//The constants
Constant kB = 1.38e-23
Constant c=2790
Constant a= 1
Constant hbar=1.05459e-34

Posts: 836
Joined: 2007-06-29
Location: United States

Since the FuncFit operation has to be able to assemble data and call your fit function itself, there are strict rules on the inputs to a fitting function. Your function doesn't fit those rules. You can read about the rules by executing this command on Igor's command line:

DisplayHelpTopic "User-Defined Fitting Function: Detailed Description"

FuncFit accepts a variety of different format in order to handle various situations.

Your function lacks an input wave corresponding to the coefficient wave. That wave has the adjustable parameters that are the point of the curve fit. So my next question is- what are the adjustable parameters in your function?

Your subject line says you want to get the limits of integration from a wave, but in fact you have an equation for the limit that depends on X (which I presume is the independent variable in your curve fit). So you don't need to get the limits from a wave, you need to compute it depending on the value of X.

Oh, wait- I just understood your bits of code and commands. You need to wrap up the three lines at the top in a user-defined function of the appropriate format. Something like this:

```Function fitEqn(pw, Temp)
Wave pw		// coefficient wave
Variable Temp

// pw[0] = Alpha
// pw[1] = Beta1
// pw[2] = Beta2
// pw[3] = Length

// Globals are required to transmit the parameters to the integrand function
Variable/G Alpha=pw[0], Beta1=pw[1], Beta2=pw[2], Length = pw[3] //Parameters to be fitted
return Integrate1d(eqn, .001, 281/Temp) //This is what I want to do, but ...
end```

There is still a problem- your command `Real(Integrate1d(eqn...)` suggests that you expect a complex value from Integrate1D, but Integrate1D returns a real value. It only integrates real-valued integrands. So we may not be there yet...

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com

dwillia5
Posts: 4
Joined: 2011-08-16
Location: United States

Thanks!! The problem was in the line f(T) = Real(Integrate1d(eqn, .001, 281/Temp)). To get this fuction, I had edited another fit function that integrated over complex values and missed the "Real" in that line. The program works perfectly now. Thanks again.