188.8.131.52 Non-linear Fitting
Non-linear fitting in LabTalk is X-function based and proceeds in three steps, each calling (at least) one X-function:
- nlbegin: Begin the fitting process. Define input data, type of fitting function, and input parameters.
- nlfit: Perform the fit calculations
- nlend Choose which parameters to output and in what format
Besides nlbegin, you can also start a fitting process according to your fitting model or data by the following X-Functions:
- nlbeginr: Fitting multiple dependnet/independent variables' model
- nlbeginm: Fitting a matrix
- nlbeginz: Fitting XYZ worksheet data
Here is a script example of the steps outlined above:
// Begin non-linear fitting, taking input data from Column 1 (X) and
// Column 2 (Y) of the active worksheet,
// specifying the fitting function as Gaussian,
// and creating the input parameter tree named ParamTree:
nlbegin iy:=(1,2) func:=gauss nltree:=ParamTree;
// Optional: let the peak center be fixed at X = 5
ParamTree.xc = 5; // Assign the peak center an X-value of 5.
ParamTree.f_xc = 1; // Fix the peak center (f_xc = 0 is unfixed).
// Perform the fit calculations:
// Optional: report results to the Script Window.
type Baseline y0 is $(ParamTree.y0),;
type Peak Center is $(ParamTree.xc), and;
type Peak width (FWHM) is $(ParamTree.w);
// end the fitting session without a Report Sheet
Notes on the Parameter Tree
The data tree that stores the fit parameters has many options besides the few mentioned in the example above. The following script command allows you to see all of the tree nodes (names and values) at one time, displaying them in the Script Window.
// To see the entire tree structure with values:
Note: since the non-linear fitting procedure is iterative, parameter values for the fit that are not fixed (by setting the fix option to zero in the parameter tree) can and will change from their initial values. Initial parameters can be set manually, as illustrated in the example above by accessing individual nodes of the parameter tree, or can be set automatically by Origin (see the nlfn X-function in the table below).
Table of X-functions Supporting Non-Linear Fitting
In addition to the three given above, there are a few other X-functions that facilitate non-linear fitting. The following table summarizes the X-functions used to control non-linear fitting:
|| Brief Description
Start a LabTalk nlfit session on XY data from worksheet or graph.
This X-Function fits one independent/dependent model only. For multiple dependent/independent functions, use nlbeginr instead.
|| Start a LabTalk nlfit session on worksheet data. It is used for fitting multiple dependent/independent variables functions.
Start a LabTalk nlfit session on matrix data from matrix object or graph
Start a LabTalk nlfit session on XYZ data from worksheet or graph
Set Automatic Parameter Initialization option
Open the Parameter dialog for GUI editing of parameter values and bounds
Perform iterations to fit the data
End the fitting session and optionally create a report
For a full description of each of these X-functions and its inputs and outputs, please see the X-function Reference.
Qualitative Differences from Linear Fitting
Unlike linear fitting, a non-linear fit involves solving equations to which there is no analytical solution, thus requiring an iterative approach. But the idea---calling X-functions to perform the analysis---is the same. Whereas a linear fit can be performed in just one line of script with just one X-function call (see the Linear Fitting section), a non-linear fit requires calling at least three X-functions.