4.2.2.1 Nonlinear Curve Fit Tool


Video Image.png Video Text Image.png Website blog icon circle.png Blog Image 33x33px.png

Summary

Nonlinear fitting in Origin is performed using the NonLinear Fitting (NLFit) dialog box. The NLFit tool contains more than 200 built-in fitting functions used in many different disciplines.

To do a quick and simple fit without opening the NLFit dialog, try the Quick Fit Gadget.

Minimum Origin Version Required: 8.5

What you will learn

  • How to fit with a built-in fitting function.
  • How to change NLFit setting using Recalculate.
  • How to define and fit with a user-defined function.

Use a built-in function to fit the data

  1. Click File:Open... to open the Intro_to_Nonlinear Curve Fit Tool.opj from the \Samples\Curve Fitting folder and select the Built-In Function folder from the Project Explorer window.
  2. With the Graph1 active, select the menu item Analysis: Fitting: Nonlinear Curve Fit to bring up the NLFit dialog, and then select Gauss from the Function drop-down list:
    Nonlinear Curve Fit Tool 001.png
  3. In the Parameter tab, initial parameter values are automatically assigned, because the built-in functions have parameter initialization code.
    If you go to the Residual tab, you can see the current residuals and decide whether the current fit results are acceptable.
    Nonlinear Curve Fit Tool 002.png
  4. Note that a fitted curve drawn using the initial parameter values, is shown in the graph.
    Nonlinear Curve Fit Tool 003.png
  5. Click the Fit until converged button Button Fit Untill Converged.png.To see if the fitting operation was successful, click the Messages tab and note the number of iterations, reduced chi-sqr value, R^2 value, etc.
    Nonlinear Curve Fit Tool 004.png
  6. Click the OK button. The FitNL1 report sheet is created with fit results including parameter values and fit statistics.
    Nonlinear Curve Fit Tool 005.png
  7. Reopen the Nonlinear Curve Fitting dialog by clicking on the green lock icon on the upper left corner of the graph and selecting Change Parameters.
    Nonlinear Curve Fit Tool 006.png
  8. Go to the Parameters tab, change the value of xc to 25 (note that by double-clicking in the cell, you can edit the value) and select the Fixed check box.
    Nonlinear Curve Fit Tool 007.png
  9. Once again, click the Fit until converged button Button Fit Untill Converged.png and then OK.
  10. In the report sheet, you can see that fixing the value of xc to 25 results in a Standard Error of 0.
    Nonlinear Curve Fit Tool 008.png

Define and fit with a user-defined function

In this section, we will show you how to define your own fitting function and use it in the Nonlinear Curve Fit tool
Our function is y=y0+a*exp(-b*x)

  1. With the project file used in the first section opened. Select Tools: Fitting Function Builder... menu to bring up the Fitting Function Builder dialog box.
  2. On the Goal page, click Create a New Function, then click the Next button to go to the Name and Type page.
    Nonlinear Curve Fit Tool 009.png
  3. On the Name and Type page, then name the function and select a Function Type. This function will be put to the User Defined category by default.
    • Set MyFunction as the Function Name.
    • Select Expression from the Function Type list. Note that the left panel displays Hints regarding the Function Type you selected.
    • Click the Next button to turn to the Variables and Parameters page.
    Nonlinear Curve Fit Tool 010.png
  4. On the Variables and Parameters page, make sure Independent Variables reads x and Dependent Variables reads y. Then input the comma-separated values y0, a, b into the Parameters text box. Click the Next button.
    Nonlinear Curve Fit Tool 011.png
  5. On the Function Body page, perform the following operations:
    • Set the Initial Values for parameters as shown below.
    • In the Function body edit box, enter y0+a*exp(-b*x).
    • Use Quick Check to check the validity of current function. After entering a value for the independent variables x, click the Evaluate button Button Evaluate.png, you will get a return value of the dependent variable y which can be used to check the validity of this function.
    Nonlinear Curve Fit Tool 012.png
  6. Click the Finish button to finish defining the function.
  7. Open Project Explorer (View: Project Explorer), and select the User-Defined Function folder.
  8. Highlight column A and B in [Book1]Sheet1, select the menu item Analysis: Fitting: Nonlinear Curve Fit to bring up the NLFit dialog. Select the User Defined category and your function MyFunction on the Function Selection page, under the Settings tab:
    Nonlinear Curve Fit Tool 013.png
  9. By successively clicking the 1 iteration button, you can see the change in parameter values as well as the increasing conformance of the fitted curve.
    • Click the "1 Iteration" button Button 1 Iteration.png.
    Nonlinear Curve Fit Tool 014.png
    • Click the "1 Iteration" button Button 1 Iteration.png again.
    Nonlinear Curve Fit Tool 015.png
    • Click the Fit until converged buttonButton Fit Untill Converged.png
    Nonlinear Curve Fit Tool 016.png
  10. Click the OK button and the FitNL1 report sheet of fitting results is created. Here, you will find best-fit parameter values and other fit statistics.