# Nonlinear Curve Fitting (Levenberg-Marquardt » Formula) (G Dataflow)

Uses the Levenberg-Marquardt method to determine the set of parameters that best fit the input data set as expressed by a nonlinear function. You define the nonlinear function using a formula.

## stopping criteria

Conditions that terminate the fitting process.

This node terminates the fitting process if this node passes the maximum iterations threshold or reaches the tolerance threshold.

### maximum iterations

Maximum number of iterations that the node runs in the fitting process.

Default: 200

### tolerance

Minimum relative change in the weighted distance between y and the current fit.

Default: 1E-08

## nonlinear function

Components of the nonlinear function for the fitting model.

### formula

Model equation. The equation can contain any number of valid variables.

Variables must start with a letter or an underscore followed by any number of alphanumeric characters or underscores.

### parameters

Names of the unknown parameters in formula.

### x

Name of the independent variable in formula.

## y

Dependent values.

y must be greater in size than initial parameters. y must be the same size as x.

## x

Independent values.

x must be greater in size than initial parameters. x must be the same size as y.

## weight

Weights for the observations.

If weight is unwired, this node sets all elements of weight to 1. If the length of weight does not equal the length of y, this node forces the lengths to be equal by padding the end of weight with 1 or ignoring the extra elements at the end of weight. If an element in weight is less than 0, this node uses the absolute value of the element.

## initial parameters

Initial guess for a solution.

The success of the nonlinear curve fit depends on how close initial parameters is to the solution. Therefore, use any available resources to obtain good initial guess coefficients to the solution before you use this node.

## error in

Error conditions that occur before this node runs.

The node responds to this input according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

Default: No error

## parameter bounds

Upper and lower numeric limits for the parameters being optimized.

### minimum

Smallest allowed values of the parameters being optimized.

The input must be empty or the same size as initial parameters. This input must be the same size as maximum. This input does not allow exceptional values, such as Inf, -Inf, or NaN.

Each element in minimum must be less than or equal to the corresponding element in maximum. If an element in minimum is equal to the corresponding element in maximum, this node uses the value of the element as the constant value of that variable throughout the curve fitting.

### maximum

Greatest allowed values of the parameters being optimized.

The input must be empty or the same size as initial parameters. This input must be the same size as minimum. This input does not allow exceptional values, such as Inf, -Inf, or NaN.

Each element in maximum must be greater than or equal to the corresponding element in minimum. If an element in maximum is equal to the corresponding element in minimum, this node uses the value of the element as the constant value of that variable throughout the curve fitting.

## method

Fitting method.

Name Value Description
Least Square 0 Uses the least square method.
Least Absolute Residual 1 Uses the least absolute residual method.
Bisquare 2 Uses the bisquare method.

Default: Least Square

## best nonlinear fit

Values of the nonlinear function that correspond to the independent values.

## best fit parameters

Parameters that minimize the weighted mean square error between the solution vector and the observed dependent values.

## covariance

Matrix of covariances.

The element in the jth row and kth column c j k is the covariance between a i and a k , where a i and a k are the jth and kth element in best fit parameters, respectively. c j j is the variance of a j .

Algorithm for Calculating covariance

This node computes the covariance matrix C using the following equation: $\mathbf{C}={\frac{1}{2}D}^{-1}$, where D is the Hessian of the function with respect to the values in best fit parameters.

## number of function calls

Number of times that this node called the nonlinear function in the fitting process.

## error out

Error information.

The node produces this output according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

## residue

Weighted mean square error between best nonlinear fit and y.

## Nonlinear Curve Fitting Model

The following equation defines the nonlinear curve fitting model for this node: y[i] = f(x[i], a 0, a 1, a 2, ...), where a 0, a 1, a 2 , ... are the parameters.

## Caveats of the Levenberg-Marquardt Method

The Levenberg-Marquardt method does not guarantee a correct fitting result. The accuracy of the result depends on the compatibility between the data you provide and the curve fitting model you define in nonlinear function. You must always verify the fitting results.

Where This Node Can Run:

Desktop OS: Windows

FPGA: Not supported

Web Server: Not supported in VIs that run in a web application