184.108.40.206 Fit Surface with User Defined Function
Origin provides a NonLinear Surface Fit tool to fit surface.
Besides the built-in surface fitting functions, you can also create your own fitting functions in Fitting Function Builder.
In this tutorial, we will illustrate how to create a user-defined surface fitting function in Fitting Function Builder, and carry out nonlinear surface fit with it 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 surface fitting function using the Fitting Function Builder.
- Carry out nonlinear surface fit with user-defined fitting function.
For this tutorial, we will define and use the following fitting function:
is the dependent variable
and are the independent variables
and are all fitting parameters.
Create a Surface Fitting Function
In this section, we will show how to create a user defined surface 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 surface 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, select Surface Fitting from Select or create a Category drop-down list since Nonlinear Surface Fit tool lanches functions in the Surface Fitting category only.
- Enter a name "MyPolynomialSurface" in Function Name and select Expression for Function Type. 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:
- Give estimated initial values to the parameters according to this particular data and function.
- You can also give different initial values each time before you actually carry out the fitting.
- You Can click the Evaluate button to quick check whether the function is valid(if it is valid, an actual value will be returned for z).
- 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 Surface Fitting
- With a new workbook active, choose Data: Connect to File: Text/CSV and browse to <Origin Program>\Samples\Curve Fitting and import the file PolynomialSurface.dat (accept defaults in the CSV Import Options dialog).
- Highlight column C(Y) and click the Set as Z button on the Mini Toolbar.
- Keep worksheet C(Z) activated, then select Analysis:Fitting:Nonlinear Surface Fit to open the NLFit dialog.
- In the Function Selection page, you can see that Category is read only and set as Surface. Set Function as MyPolynomialSurface(User).
- Click the Fit button to carry out the fit.
- A report sheet will be generated, in which the fitted value of all parameters are reported in the parameters table. A FitSurfaceCurve worksheet is added to the source workbook as well, in which the data of fitted surface is stored.
- Activate the source worksheet and highlight col(C). Click the button to generate a 3D scatter plot. To add the fitted surface to the source data, double click on the Layer 1 icon. In the Layer Contents dialog that opens, set the drop-down list in the upper-left corner to Worksheets in Folder. Select FitZ of FitSurfaceCurve1 worksheet in the panel below the drop-down, then click the menu button beside "A" in the middle of the dialog and change the plot type to 3D - Surface. Click on the rightward pointing arrow just below it to add the dataset to the right panel.
Click OK to add the surface to the source data graph.
A Polynomial Surface Fit App is available for Origin 2016 and higher. If you want to fit a polynomial surface, it is recommended to try this App first.