How to: Use Constrained NonLinear Programming Using the NelderMead Solver
You can use the NelderMead solver (NelderMeadSolver) for some types of constrained nonlinear programming. For example, the NelderMead solver can find the local optimum of a general variable constrained objective function.
One example of this technique is to use the NelderMead (NM) solver to find the global minimum of the boxconstrained twodimensional Rosenbrock function created by mathematician Howard Rosenbrock in 1960. The following example uses a variant of the NelderMead method to search for a local optimum by iteratively changing variable values over a range of possible solutions. The solver stops computation when the difference in objective values is less than ToleranceDifference.
To solve a 2D Rosenbrock function using the NelderMead solver

Create a Console Application named Rosenbrock.

Add a reference to Microsoft Solver Foundation on the .NET tab.

Add the following Imports or using statements to the top of the Program code file.
using Microsoft.SolverFoundation.Common; using Microsoft.SolverFoundation.Solvers;

In the Main method, define initial values, lower bounds and upper bounds for the output variables by typing the following code:
double[] xInitial = new double[] { 1, 1 }; double[] xLower = new double[] { 1, 1 }; double[] xUpper = new double[] { 1, 1 };

Call the NelderMeadSolver and supply the Rosenbrock function, initial values, and bounds by typing the following code:
var solution = NelderMeadSolver.Solve( x => (100 * Math.Pow(x[1]  Math.Pow(x[0], 2), 2)) + Math.Pow(1  x[0], 2), xInitial, xLower, xUpper);

Print the results by typing the following code.
Console.WriteLine(solution.Result); Console.WriteLine("solution = {0}", solution.GetSolutionValue(0)); Console.WriteLine("x = {0}", solution.GetValue(1)); Console.WriteLine("y = {0}", solution.GetValue(2));

Press F5 to build and run the code.
The command window shows the following results.
LocalOptimal
solution = 0
x = 1
y = 1