Accord.Tests.Math.CobylaTest.ConstructorTest2_2 C# (CSharp) Method

ConstructorTest2_2() private method

private ConstructorTest2_2 ( ) : void
return void
        public void ConstructorTest2_2()
        {
            var function = new NonlinearObjectiveFunction(2, x => x[0] * x[1]);

            NonlinearConstraint[] constraints = 
            {
                new NonlinearConstraint(2, x =>  x[0] * x[0] + x[1] * x[1] <= 1.0)
            };

            Cobyla cobyla = new Cobyla(function, constraints);

            for (int i = 0; i < cobyla.Solution.Length; i++)
                cobyla.Solution[i] = 1;

            bool success = cobyla.Minimize();
            double minimum = cobyla.Value;
            Assert.IsTrue(success);

            double[] solution = cobyla.Solution;

            double sqrthalf = Math.Sqrt(0.5);

            Assert.AreEqual(-0.5, minimum, 1e-10);
            Assert.AreEqual(sqrthalf, solution[0], 1e-5);
            Assert.AreEqual(-sqrthalf, solution[1], 1e-5);
        }