# 15.5.8.6 Nonlinear Implicit Curve Fitting (Pro Only)

Origin's NLFit tool supports implicit fitting using the Orthogonal Distance Regression (ODR) algorithm, including fitting with X and/or Y error data.

To fit your data with implicit fitting functions, you may use the built-in functions of nonlinear implicit curve fitting, or create your own implicit fitting functions.

## Fit with the Implicit Functions

To fit with an implicit function,

1. Select from top menu Analysis:Fitting:Nonlinear Implicit Curve Fit to open the dialog.
2. Select a function under the Implicit category.

 Notes: Implicit fit functions use Orthogonal Distance Regression.
 Mini Tutorial:Fit for Ellipse Import the Ellipse.dat file as single ASCII, which can be found under \Samples\Curve Fitting Highlight column A and B, select "Analysis:Fitting:Nonlinear Implicit Curve Fitting" to open the NLFit dialog Choose "Ellipse" as the function type Go to "Data Selection", make sure "Use Each Range's Setting" is chosen for Weight In "Data Selection", expand the "Input" branch, and further expand "Range 1" Under branch "x", choose "Arbitrary Dataset" for Weight, and choose column C(Weight X) as the dataset Do the similar for "y", this time choose column D(Weight Y) as the dataset Click "Fit" to fit the data and generate report sheet

## Implicit Fit with More Than Two Variables

Please note the following when you carry out implicit fit with more than 2 independent variables:

• It is required to have worksheet data as the input data, i.e. you cannot carry out the fitting from a data plot in this case.
• Only the data type Fitted Point for Input Data is supported for all variables. To modify this setting in the NLFit dialog, go to the Settings taband select Fitted Curves. Expand the Fitted Curves Plot branch set Data Type of variable to be Fitted Point for Input Data.
• It is not supported to generate a fitted curve automatically, however you could get the data for fitted curve in the report sheet.

## Create a User-Defined Implicit Function for Fitting

To create your own implicit fitting function, you need to first open the Fitting Function Builder either by:

1. Select Analysis:Fitting:Nonlinear Implicit Curve Fit to open the NLFit dialog.
2. Select <New...> in the drop-down menu of Function.

or

Choose Tools:Fitting Function Builder or press F8.

When the Fitting Function Builder is open,

1. Choose the Create a New Function radio button and click Next.
2. Choose the Implicit radio button for Function Model.

or

1. Select Tools:Fitting Function Organizer or press F9 to open the Fitting Function Organizer
2. Create a new function under the Implicit category.

Note that you can only do implicit fitting with functions in the Implicit category, so you need to move any created implicit functions to the Implicit category in Fitting Function Organizer.

Refer to the Origin help file for how to define a user-defined fitting function.

 This is a short tutorial showing how to create a user-defined implicit fitting function and fit data with it. Choose Tools:Fitting Function Organizer or press F9 to open the Fitting Function Organizer. Choose the Implicit category and click the New Function button. Type Hyperbolic as Function Name, set the Function Model to Implicit and Function Form as Equations. Type x,y in the Variables box, a,b,c,d,e in the Parameters box. In the Function Body, type f=a*x^2+b*x*y+c*y^2+d*x+e*y-1; Note that the value f is estimated as 0. Click Save to save the function and click OK to close the dialog. Prepare some test data following a hyperbolic trend and import into Origin. You can use the Simulate button in the Fitting Function Organizer to generate data with added noise. Set column A as x and column B as y. Select column A and B and choose Analysis:Fitting:Nonlinear Implicit Fitting to open the NLFit dialog. In the Function drop-down menu, choose Hyperbolic(User) and click Fit.
 Note: Fitting with any User Defined function requires parameter initialization. A value of 1 for each parameter should be sufficient for a Hyperbolic function.

## Fit Explicit Functions with ODR

The default iteration algorithm is Levenberg-Marquardt (L-M) for explicit fitting functions. It is also possible to use Orthogonal Distance Regression (ODR) algorithm for explicit functions. To do so:

1. Select Analysis:Fitting:Nonlinear Curve Fit or press Ctrl+Y to open the NLFit dialog.
2. After selecting a function, choose Orthogonal Distance Regression (Pro) in the drop-down menu of Iteration Algorithm.

## Iteration Algorithm

### ODR Algorithm

The ODR (Orthogonal Distance Regression) algorithm minimizes the residual sum of squares by adjusting both fitting parameters and values of the independent variable in the iterative process. The residual in ODR is not the difference between the observed value and the predicted value for the dependent variable, but the orthogonal distance from the data to the fitted curve.

Origin uses the ODR algorithm in ODRPACK95. ODR method can be used for both implicit functions and explicit functions.

For a 2D explict function $y=f(x,\beta )$, the ODR algorithm could be expressed as:

$\min\left (\sum_{i=1}^{n}\left (w_{yi}\cdot \epsilon_{i} ^{2}+w_{xi}\cdot \delta_{i}^{2} \right ) \right )$

subject to the constraints:

$y_{i}=f\left ( x_{i} +\delta_{i}; \beta \right )-\epsilon _{i}\ \ \ \ \ \ i=1,...,n$

where $w_{xi}$ and $w_{yi}$ are the user input weights of $x_{i}$ and $y_{i}$, $\delta_{i}$ and $\epsilon_{i}$ are the residual of the corresponding $x_{i}$ and $y_{i}$, and $\beta$ is the fitting parameter.

Origin uses the ODR algorithm in ODRPACK95.

For a 2D implicit function $y=f(x, y, \beta )$, the ODR algorithm could be expressed as:

$\min\left (\sum_{i=1}^{n}\left ( w_{xi}\cdot \delta_{xi}^{2}+w_{yi}\cdot \delta_{yi}^{2} \right ) \right )$

subject to:

$f\left ( x_{i}+\delta_{xi},y_{i}+\delta_{yi},\beta \right )= 0\ \ \ \ \ \ i=1,...,n$

where $w_{xi}$ and $w_{yi}$ are the user input weights of $x_{i}$ and $y_{i}$, $\delta_{xi}$ and $\delta_{yi}$ are the residual of the corresponding $x_{i}$ and $y_{i}$, and $\beta$ is the fitting parameter.

### L-M Algorithm

L-M(Levenberg-Marquardt) algorithm minimizes the residual sum of squares by adjusting fitting parameters in the iterative process. The residual in L-M is the difference between the observed value and the predicted value of the dependent variable. And the algorithm combines the Gauss-Newton method and the steepest descent method. It can be used only in explicit functions.

The L-M algorithm works for most cases based on general Theory of Nonlinear Curve Fitting.

For a 2D explicit function $y=f(x,\beta )$, the L-M algorithm could be expressed as:

$\min\left ( \sum_{i=1}^{n}\left ( w_{i}\cdot \epsilon_{i}^{2} \right ) \right )$

where $w_{i}$ and $\epsilon_{i}$ are the weight and the residual of $y_{i}$, respectively.

And the residual $\epsilon_{i}$ is calculated as:

$\epsilon_{i}=y_{i}-f\left (x_{i},\beta \right )$

### Comparison between ODR and L-M

To choose the ODR or L-M algorithm for your fitting, you may refer to the following table for information:

Orthogonal Distance Regression Levenberg-Marquardt
Application Both implicit and explicit functions Only explicit functions
Weight Support both x weight and y weight Support only y weight
Residual Source The orthogonal distance from the data to the fitted curve The difference between the observed value and the predicted value
Iteration Process Adjusting the values of fitting parameters and independent variables Adjusting the values of fitting parameters

## Reference

"J. W. Zwolak, P.T. Boggs, and L.T. Watson, Algorithm 869: ODRPACK95: A weighted orthogonal distance regression code with bound constraints, ACM Transactions on Mathematical Software Vol. 33, Issue 4, August 2007."