Include data in a user-defined fitting function

I am trying to fit some photoluminescence data to a model, with a user defined fitting function.

The intensity is a function of frequency, with some fitting parameters. I also have data for refractive index as a function of frequency, and would like this data to be included in the fitting function (so the fitting function has independent variable frequency, dependent variable intensity, and includes a parameter that depends on frequency).

I have tried including refractive index as another independent variable, but unsurprisingly this doesn't work as it depends on frequency.

Any assistance much appreciated,
I am not sure whether you want to use data (e.g., in a wave) or an analytic expression for the refractive index. Both can be done, as it is possible to call another function or reference a wave for fitting. You need to modify the fitting function for that (most probably directly inside the procedure window). Just write the wave statement or the function for calculating the index into the fitting function and use it with the frequency parameter as a variable. It would help if you would post a simple example here to work with directly.
Thanks for your quick reply

I would like to use another wave for the refractive index.

Originally I used the curve fitting GUI to input my functions, ignoring the refractive index entirely. This gave the procedure window below.

What I want to do is to insert the data for the refractive index wave for each value of frequency into the expression

(k*(a*frequency)^2*exp(-(b*frequency)) (this is a simplified version)

to give something like

k*refractive_wave*(a*frequency)^2*exp(-(b*frequency))

I have attached the experiment file as well.

Thanks again

____________________________________________________

#pragma rtGlobals=3 // Use modern global access method and strict wave access.

Function simple_example(w,frequency) : FitFunc
Wave w
Variable frequency

//CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
//CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
//CurveFitDialog/ Equation:
//CurveFitDialog/ f(frequency) = k*(a*frequency)^2*exp(-(b*frequency))
//CurveFitDialog/ End of Equation
//CurveFitDialog/ Independent Variables 1
//CurveFitDialog/ frequency
//CurveFitDialog/ Coefficients 3
//CurveFitDialog/ w[0] = k
//CurveFitDialog/ w[1] = a
//CurveFitDialog/ w[2] = b

return w[0]*(w[1]*frequency)^2*exp(-(w[2]*frequency))
End

____________________________
Simple_Example.pxp (53.74 KB)
The simple answer is to include a WAVE statement in your fitting function that looks up the refractive index wave so that it can be used in your fitting function:
Function simple_example(w,frequency) : FitFunc
    Wave w
    Variable frequency

    //CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
    //CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
    //CurveFitDialog/ Equation:
    //CurveFitDialog/ f(frequency) = k*(a*frequency)^2*exp(-(b*frequency))
    //CurveFitDialog/ End of Equation
    //CurveFitDialog/ Independent Variables 1
    //CurveFitDialog/ frequency
    //CurveFitDialog/ Coefficients 3
    //CurveFitDialog/ w[0] = k
    //CurveFitDialog/ w[1] = a
    //CurveFitDialog/ w[2] = b

    WAVE refractive_index
    return w[0]*refractive_index(frequency)*(w[1]*frequency)^2*exp(-(w[2]*frequency))
End

But what I have written here is certainly wrong, because I don't know how the values in the wave should be indexed. The way I have written it, using parentheses, assumes that the wave has the X scaling set so that the values can be looked up directly using the input frequency. The value returned by refractive_index(frequency) will be interpolated between the actual values if the frequency falls between values that exist in your wave.

If this is puzzling to you, please read:
DisplayHelpTopic "Waves"

and especially
DisplayHelpTopic "The Waveform Model of Data"
DisplayHelpTopic "Waveform Arithmetic and Assignment"

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com