Example 6: Usage With Class MinUnconMultiVar

The minimum of 100(x_2 - x_1^2)^2 + (1-x_1)^2 is found using MinUnconMultiVar . NumericalDerivatives is used to compute the numerical gradients.
using System;
using Imsl.Math;

public class NumericalDerivativesEx6 : MinUnconMultiVar.IGradient
{
    static int m = 1, n = 2;

    class NumericalDerivativesFcn : NumericalDerivatives.IFunction
    {
        public double[] F(int varIndex, double[] y) 
        {
            double[] tmp = new double[m];
            tmp[0] = NumericalDerivativesEx6.FcnEvaluation(y);
            return tmp;
        }
    }

    static public double FcnEvaluation(double[] x) 
    {
        return 100.0 * ((x[1] - x[0] * x[0]) * (x[1] - x[0] * x[0])) + 
            (1.0 - x[0]) * (1.0 - x[0]);
    }

    public double F(double[] x)
    {
        return FcnEvaluation(x);
    }

    public void Gradient(double[] x, double[] gp)
    {
        NumericalDerivatives nderv = 
            new NumericalDerivatives(new NumericalDerivativesFcn());
        double[,] jacobian = nderv.EvaluateJ(x);
            
        gp[0] = jacobian[0, 0];
        gp[1] = jacobian[0, 1];
    }
    

    public static void  Main(String[] args)
    {
        MinUnconMultiVar solver = new MinUnconMultiVar(n);
        solver.SetGuess(new double[]{- 1.2, 1.0});

        double[] x = solver.ComputeMin(new NumericalDerivativesEx6());
        Console.Out.WriteLine
            ("Minimum point is (" + x[0] + ", " + x[1] + ")");
    }
}

Output

Minimum point is (0.999998611858024, 0.999997274648157)

Link to C# source.