,Q7V,7mHH(Fg(HH(dh 9 9$Normal
<
BHHHH$$23zZ/4F.7lBlVlVlVlVlVlVlVlV "Writing your own fitting function
@This model function example works with the SANS Analysis package. It contains everything necessary for you to author, plot, and fit a model function to SANS or USANS data. It also includes procedures to easily calculate (and then fit) a resolution-smeared version of the model function.
@
*@The procedure file that does the work is:
@ My_Model.ipf
@
@This can be found under the Windows->Procedure Windows menu. It is simply a text file that contains Igor code that is compiled and executed. My_Model.ipf contains two functions, one for the perfect (unsmeared) model function, and one for the resolution smeared version of the model function. There are also two "Macros" that define the parameters of the model and set up a graph of the model function that updates as the parameters are changed in a table.
@
i@As-is, the model example "MyModel" calculates the scattering from monodisperse, non-interacting spheres.
@
@
O$To write your own function, you need to do FIVE steps to change this template:
M
$@1) Identify the variables from the equation for the intensity. These are the coefficients that will be free to vary during the model fitting.
&For the case of a spherical particle:
o6@The scattered intensity is the product of the number density of spheres, n, and the form factor, P(q), which is the square of the particle scattering amplitude, f(q). For a sphere, this can be written as in the second line, noting that the number density is equal to f/V. Volume fraction of particles is a much more natural experimental variable than number density.
@
ETherefore the coefficients [and units] for the fitting function are:
- the radius of the sphere [A]
T6- the scattering contrast (the difference between the sphere and the solvent) [A-2]
PR9- a scaling factor (the volume fraction) [dimensionless]
#6- the incoherent background [cm-1]
!
$2) Change the Macro PlotMyModel() to set up the coefficients and parameter names that you need for your model. Change coef_MyModel to have the variables that are the "unknowns" in your function. In this example, there are four variables
/@ - this change is one line, search for "CH#1"
$3) Still in the macro PlotMyModel(), change the parameter names to give nice names to the variables, so that when you change values in the table, you'll know what you're changing, and what the units are.
0 - this change is one line, search for "CH#2"
5$4) Scroll down in the file to the Function MyModel()
- this is "CH#3"
MHere you write the code to calculate the model function given the set of function parameters and a single q-value. The parameters are passed in as the wave "w" (it's really an array). For the spherical particle example that is calculated, there are four elements in the array [0-3]. Give your variables nice names so that you can keep track of them. Be sure to declare them as variables. The single q-value is passed in as the variable "x". Renaming it as "qval" is purely to make the function more readable. The intensity is calculated for a the scattering from a sphere as the equation above, and returned. Be sure that the intensity is returned from the function. Do not change the name of this function - or else you will need to change it everywhere - in both the calling macro and in the quadrature function call in the smeared function.
_**Now, all you need to do is plot your function MyModel() using the macro from the Macros menu
QNote that your model function should be written to calculate the intensity for only a single q-value. The macro from steps 1&2 actually loops through all of the q-values for you. The q-values are in "xwave_MyModel", and the calculation of the intensity at all of the q-values is done by a single line of code in the PlotMyModel() macro:
Ag_MyModel := MyModel(coef_MyModel, ywave_MyModel, xwave_MyModel)
@
@Your intensity is "ywave_MyModel", and the corresponding q-values are "xwave_MyModel". This is what is plotted. You may, of course, need to debug your calculations a bit to be sure that they're really calculating your model correctly.
o$5) To write the resolution smeared version of the model, repeat steps 1 and 2, changing the right hand sides of the lines that define the coefficient and parameter names in the PlotSmearedMyModel() macro to be the same as in the PlotMyModel() macro that you just wrote. Don't change the names of the waves in the smeared macro. Keep the "smear_" prefix on the names.
:@ - There are two lines to change here - search for "CH#4"
@ - There is one more instance of "CH#4", at the smeared model function. You don't need to change anything here. It's just for you to see that there is a function named SmearedMyModel() that calls your function named "MyModel" to do the resolution smearing.
m@**Now, all you need to do is plot your model with PlotSmearedMyModel() using the macro from the Macros menu.
w@Your intensity is "smeared_MyModel", and the corresponding q-values are "smeared_qvals". You will, of course need to have previously loaded a SANS data set - or else you will see an error that "6-column blah blah blah are missing". Why? Because the SANS data files contain not only the intensity vs. Q, but also the resolution function for the conditions that the data was acquired. This extra information is loaded in with the data (but not plotted) and is used to perform the smeared model calculations. If there's no experimental SANS data loaded in, there's no information on which to base any resolution smearing calculation.
]$6) SAVE YOUR WORK. Nothing ruins your day like throwing all your hard work into the garbage.
,*******************************************
3Some additional details about programming in Igor
,*******************************************
@Adding a Model Function to IGOR
@
@A basic template for adding model functions to IGOR is provided that uses the specific example of scattering from a sphere. More details are included with the experiment template (.pxt). There are two basic requirements for adding a model fitting function:
@
@1) A Function written to perform the numerical calculations of the model. The function has two input parameters: a wave (an array) of the fitting variables, and the single q-value where the function is to be calculated. Igor will take care of looping over all q-values automatically.
"@2) A Macro to make the function user-friendly. This allows the user to choose the q-range and number of points. It also displays a table of the input parameters, and sets a dependency so that whenever a new parameter value is entered, the model is automatically recalculated and displayed.
@
@It is also very helpful to generate documentation for new model functions, so that others can use them and understand what is being calculated. A sample "SphereForm.ifn" is provided as an example for the sphere form factor calculation.
@
@The Function
@
@The IGOR function is like a typical function in a program, calculating a value based on inputs, and returning this value to the calling procedure.
@
@ To be used as a fitting function, the function must have the form: func(w,x). Two parameters, - no more, no less (you can use more descriptive names than w and x). This is the form of the function My_Model(w,x) that is provided.
4@ w = a wave (an array) containing fitting variables
>@ x = a variable containing the independent variable (q-value)
@
@ IGOR syntax is slightly different than FORTRAN or C. A few common differences are listed. See the user manuals for specifics, or IGORs on-line help (which is quite good).
@
@1) Comments start with //
@2) Variables must be explicitly declared, as variable (all numeric types), or string. In Igor's notation, arrays are declared as a wave.
4@3) An exponentiation operator, ^, is used (not **).
.@4) C-type assignments +=, *=, etc are allowed
7@5) There is different syntax for Boolean conditionals.
!@6) Syntax is not case sensitive.
G@7) i,j,q,r,s,t,y,z are IGOR functions and cannot be used as variables.
@8) x and p are also IGOR functions, but behave as normal variables in user functions. Get into the habit of using ii,jj,kketc.
Q@9) Waves are assigned rather than indexing of arrays the loop is done for you.
D@10) Dynamic dependencies can be created, using the := assignment.
F@11) Many mathematical functions are built-in. Check the on-line help.
@
@
@
@The Macro
@
>@ The Macro is a set of IGOR-specific commands that performs the routine setup steps before the function can be called, calls the function, and generates graphs and tables. The example shown is a very basic and functional user interface, but can be made quite elaborate (see the IGOR demos provided by WaveMetrics).
@
'@ The macro should have a descriptive name, as this name will appear under the Macros menu once the procedure is compiled. It should also have the same three parameters as in the example, which are prompts to the user for information about the model calculation. Here, we use "Plot_MyModel()"
@
q@ The commands used in the macro are described in the programming manual, but can also be recorded by performing the desired steps manually from the menu bar and dialogs. The command for each step is echoed in the command window at the bottom of the screen, and these lines can be cut and pasted into a macro. That's how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