# NMath User's Guide

32.3 Levenberg-Marquardt Minimization (.NET, C#, CSharp, VB, Visual Basic, F#)

NMath provides class for solving nonlinear least squares problems using the Levenberg-Marquardt method. LevenbergMarquardtMinimizer implements the interface.

Constructing a LevenbergMarquardtMinimizer

Instances of LevenbergMarquardtMinimizer are constructed by specifying a maximum number of iterations, gradient tolerance, and a solution tolerance, or by accepting the defaults for these values. Iteration stops when the infinity norm of the gradient used in calculating the next step falls below the gradient tolerance, or then the L2 norm of the step size falls below the solution tolerance. For example:

Code Example – C# Levenberg-Marquardt minimization

```int maxIterations = 1000;
```
```double gradientTolerance = 1e-14;
```
```double solutionTolerance = 1e-14;
```
```var lm = new LevenbergMarquardtMinimizer(
```
```  maxIterations, gradientTolerance, solutionTolerance );
```

Code Example – VB Levenberg-Marquardt minimization

```Dim MaxIterations As Integer = 1000
```
```Dim GradientTolerance As Double = "1e-14"
```
```Dim SolutionTolerance As Double = "1e-14"
```
```Dim LM As New LevenbergMarquardtMinimizer(MaxIterations,
```
```  GradientTolerance, SolutionTolerance)
```

Minimization

Class LevenbergMarquardtMinimizer provides the Minimize() method for minimizing a given multivariable function, encapsulated as a DoubleMultiVariableFunction, as described in Section 32.1.

Minimization Results

The Minimize() method returns the solution found by the minimization:

Code Example – C# Levenberg-Marquardt minimization

```DoubleVector solution = minimizer.Minimize( f, start );
```

Code Example – VB Levenberg-Marquardt minimization

```Dim Solution As DoubleVector = Minimizer.Minimize(F, Start)
```

Additional information about the last performed fit is available from properties implemented as part of the INonlinearLeastSqMinimizer interface (Section 32.1).

Top

Top