Nonlinear Curve Fit VI
- Updated2025-03-14
- 2 minute(s) read
Uses the Levenberg-Marquardt algorithm to determine the set of parameters that best fit the set of input data points (X, Y) as expressed by a nonlinear function y = f(x,a), where a is the set of parameters. You must manually select the polymorphic instance to use.

This VI uses the Levenberg-Marquardt method to calculate the best fit parameters that minimize the weighted mean square error between the observations in Y and the best nonlinear fit. The following equation defines the curve model:
y[i] = f(x[i], a0, a1, a2, …)where a0, a1, a2, … are the Parameters.
The Levenberg-Marquardt method does not require y to have a linear relationship with the Parameters.
The Hessian matrix is a common matrix in numerical optimization methods, such as the Newton method. To avoid the weakness of the singular Hessian matrix, the Levenberg-Marquardt method adds a positive definite diagonal matrix to the Hessian matrix. This positive definite diagonal matrix is the main difference between the Levenberg-Marquardt method and the Gauss-Newton method. Refer to Numerical Optimization in the Mathematics Related Documentation topic for more information about the Levenberg-Marquardt method.
You can use the nonlinear Levenberg-Marquardt method to fit linear or nonlinear curves. However, when you fit a linear curve, the General Linear Fit VI is more efficient than this VI. You must verify the results you obtain with the Levenberg-Marquardt method because the method does not always guarantee a correct result.
Examples
Refer to the following example files included with LabVIEW.
- labview\examples\Mathematics\Fitting\Ellipse fit.vi
- labview\examples\Mathematics\Fitting\Sum of 3 Gaussians with offset fit.vi
- labview\examples\Mathematics\Fitting\Gaussian surface with offset fit.vi