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

ConstructorTest6_1() private method

private ConstructorTest6_1 ( ) : void
return void
        public void ConstructorTest6_1()
        {
            /// This problem is taken from Fletcher's book Practical Methods of
            /// Optimization and has the equation number (9.1.15).
            var function = new NonlinearObjectiveFunction(2, x => -x[0] - x[1]);

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

            Cobyla cobyla = new Cobyla(function, constraints);

            Assert.IsTrue(cobyla.Minimize());
            double minimum = cobyla.Value;
            double[] solution = cobyla.Solution;

            double sqrthalf = Math.Sqrt(0.5);
            Assert.AreEqual(-sqrthalf * 2, minimum, 1e-10);
            Assert.AreEqual(sqrthalf, solution[0], 1e-5);
            Assert.AreEqual(sqrthalf, solution[1], 1e-5);

            double expectedMinimum = function.Function(cobyla.Solution);
            Assert.AreEqual(expectedMinimum, minimum);
        }