Example 1: Nonlinear least-squares problem

A nonlinear least-squares problem is solved using a finite-difference Jacobian.
using System;
using Imsl.Math;

public class NonlinLeastSquaresEx1 : NonlinLeastSquares.IFunction
{
    public void F(double[] x, double[] f)
    {
        f[0] = 10.0 * (x[1] - x[0] * x[0]);
        f[1] = 1.0 - x[0];
    }


    public static void  Main(String[] args)
    {
        int m = 2;
        int n = 2;
        double[] x = new double[m];
        NonlinLeastSquares zs = new NonlinLeastSquares(m, n);
        zs.SetGuess(new double[]{- 1.2, 1.0});
        zs.SetXscale(new double[]{1.0, 1.0});
        zs.SetFscale(new double[]{1.0, 1.0});
        x = zs.Solve(new NonlinLeastSquaresEx1());
        
        for (int k = 0; k < n; k++)
        {
            Console.Out.WriteLine("x[" + k + "] = " + x[k]);
        }
    }
}

Output

x[0] = 1
x[1] = 1

Link to C# source.