184.108.40.206 User Defined Fitting Function
Besides the 200+ built-in fitting functions, you can also create your own fitting functions in Origin. Origin provides three tools for fitting with user defined function:
- Simple Fit App
- Simple Fit App provides a much more convenient way to fit simple functions that can be expressed in the form y = f(x), you only need to type your formula, specify the initial values and then generate fitting reports immediately. You can learn how to use this App in the linked File Exchange page.
- Qucik Fit Gadget
- Quick Fit gadget is another easy way to do both linear and nonlinear fitting without open the Linear Fit or NLFit dialog which might look a little bit complicated but with many advanced controls. Start a fitting process with this gadget, you need first add your own function into the Function List.
- NLFit tool.
- NLFit tool is a powerful fitting wizard which allows you to define more complex fitting functions and control the fitting process in every possible way. For fitting user defined function in NLFit tool, you will need to create it in Fitting Function Builder first.
In this tutorial, we will mainly illustrate how to create a user-defined fitting function in Fitting Function Builder, carry out nonlinear curve fit with it and also show how to fix a parameter for curve fitting using NLFit tool.
Minimum Origin Version Required: Origin 2016 SR0
What You Will Learn
This tutorial will show you how to:
- Create a user-defined fitting function using the Fitting Function Builder.
- Carry out nonlinear curve fit with user-defined fitting function.
- Fix a parameter for nonlinear curve fit.
The data we are going to fit is the file ConcentrationCurve.dat under the <Origin EXE Folder>\Samples\Curve Fitting\ path.
The fitting function to be created and used is shown below:
is the dependent variable
is the independent variable
and are all fitting parameters.
Create a Fitting Function
In this section, we will show how to create a user defined fitting function in the Fitting Function Builder. But there is an alternative tool Fitting Function Organizer which also can be used to create user defined fitting functions(open it by selecting Tools:Fitting Function Organizer or pressing F9).
- Launch Origin and choose Tools:Fitting Function Builder (or press F8) to open the Fitting Function Builder.
- In the Goal page, select Create a New Function and click Next.
- In the Name and Type page, change the setting as the following image and then click Next:
- In the Variables and Parameters page, enter the variable and parameter names as the image below and then click Next:
In the Parameters box, use comma (",") as delimiter.
- In the Expression Function page, enter the equation below in Function Body:
- Go to the Constant tab, set the value of R0 to 2.303.
- Give estimated initial values to the parameters according to this particular data and function.
Note:You can also give different initial values each time before you actually carry out the fitting.
- Can click the Evaluate button to quick check whether the function is valid(if it is valid, an actual value will be returned for y).
Note:If you used Origin C as Function Type at the beginning, you can also compile the function at this stage to check if there is any error, this is especially useful for brackets matching.
- Click the Next button three times until it goes to Derived Parameters page.
- In this page, we will define the derived parameter A0, enter its equation in the Derived Parameters Equations box:
- Click Finish to create this user defined fitting function. The .FDF file for it will be stored in the User Files Folder.
You can always modify the user defined fitting function later, either in the Fitting Function Builder(choose Edit a User-defined Function in Goal page), or in the Fitting Function Organizer.
Carry Out Curve Fitting
- Create a new workbook.Click the button to import the ConcentrationCurve.dat file under <Origin EXE Folder>\Samples\Curve Fitting\ path.
- Highlight column B and click the button to generate a scatter plot.
- Keep the graph activated, select Analysis:Fitting:Nonlinear Curve Fit to open the NLFit dialog.
- In the Function Selection page, set Category as User Defined and then set Function as MyFitFunc(User).
- Click the button to fit the data.
- An error message returns in the Message tab of the lower panel, indicates the fit did not converge because of overparameterization.
- The parameters A and km have mutual dependence, so fixing either one will solve the problem. We will fix A this time.
- Go to the Parameters tab, click the to restore the initial value setting, check the Fixed box of parameter A:
- Click the Fit button to carry out the fit.
- The fitted curve will be added to the original data plot,
- A report sheet will be generated as well, in which the fitted value of all parameters(including the derived parameter A0) are reported in the parameters table:
In the case of overparameterization, you can fix different parameters to get multiple fit results and then compare the fit models statistically by Analysis:Fitting:Compare Models tool.