OriginLab Corporation - Data Analysis and Graphing Software - 2D graphs, 3D graphs, Contour Plots, Statistical Charts, Data Exploration, Statistics, Curve Fitting, Signal Processing, and Peak Analysis     
 
Skip Navigation Links
All BooksExpand All Books
TutorialsExpand Tutorials
Data AnalysisExpand Data Analysis
Curve FittingExpand Curve Fitting
Nonlinear FittingExpand Nonlinear Fitting

4.2.2.6 User Defined Fitting Function

Summary

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.

Steps

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:

y=A\exp(2.303kx-k_{m})\sqrt{2.303+\frac{C}{(x-C_{0})}}

in which

y is the dependent variable

x is the independent variable

and A, k_{m}, k, C, C_{0} 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).

  1. Launch Origin and choose Tools:Fitting Function Builder (or press F8) to open the Fitting Function Builder.
  2. In the Goal page, select Create a New Function and click Next.
  3. In the Name and Type page, change the setting as the following image and then click Next:
    Tutorial UserDefFitFunc 001.png
  4. In the Variables and Parameters page, enter the variable and parameter names as the image below and then click Next:
    Tutorial UserDefFitFunc 002.png
    In the Parameters box, use comma (",") as delimiter.
  5. In the Expression Function page, enter the equation below in Function Body:
    A*exp(R0*k*x-km)*sqrt(R0+c/(x-c0))
  6. Go to the Constant tab, set the value of R0 to 2.303.
  7. Give estimated initial values to the parameters according to this particular data and function.
    Tutorial UserDefFitFunc 003.png
    Note:You can also give different initial values each time before you actually carry out the fitting.
  8. Can click the Evaluate button Button Evaluate.png 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.
  9. Click the Next button three times until it goes to Derived Parameters page.
  10. In this page, we will define the derived parameter A0, enter its equation in the Derived Parameters Equations box:
    A0=-A*exp(km)*1E-4
  11. 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

  1. Create a new workbook.Click the Button Import Single ASCII.png button to import the ConcentrationCurve.dat file under <Origin EXE Folder>\Samples\Curve Fitting\ path.
  2. Highlight column B and click the Button Scatter.png button to generate a scatter plot.
  3. Keep the graph activated, select Analysis:Fitting:Nonlinear Curve Fit to open the NLFit dialog.
  4. In the Function Selection page, set Category as User Defined and then set Function as MyFitFunc(User).
  5. Click the Button Fit Untill Converged.png button to fit the data.
  6. An error message returns in the Message tab of the lower panel, indicates the fit did not converge because of overparameterization.
    Tutorial UserDefFitFunc 004.png
  7. The parameters A and km have mutual dependence, so fixing either one will solve the problem. We will fix A this time.
  8. Go to the Parameters tab, click the Button Initialize Parameters.png to restore the initial value setting, check the Fixed box of parameter A:
    Tutorial UserDefFitFunc 005.png
  9. Click the Fit button to carry out the fit.
  10. The fitted curve will be added to the original data plot,
    Tutorial UserDefFitFunc 006.png
  11. 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:
    Tutorial UserDefFitFunc 007.png

    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.

     

    © OriginLab Corporation. All rights reserved.