Exemplo n.º 1
0
        public static void test_solve_newton_multi()
        {
            Console.WriteLine("\nTesting solve_newton_multi(fs, x) ...\n");
            MultivariateFunction multi = new MultivariateFunction();
            List<MultivariateFunction> fs = new List<MultivariateFunction>() { new MyFunction7(), new MyFunction8() };
            double[] x = new double[] { 1, 1 };

            Console.WriteLine("\n\tfs =  [ x[0] * x[1] - 2, x[0] - 3.0 * x[1] * x[1] ]");

            Console.WriteLine("\n\tExpecting:\tsolve_newton_multi(fs, x=[1, 1]) = [2.2894284851066793, 0.87358046473632422]" );
            double[] result = multi.solve_newton_multi(fs, x);
            Console.WriteLine("\tResult:\t\tsolve_newton_multi(fs, x=[1, 1]) =  [" + result[0] + ", " + result[1] + "]");

            fs = new List<MultivariateFunction>() { new MyFunction10(), new MyFunction11() };
            x = new double[] { 0, 0 };
            Console.WriteLine("\n\tfs =  [ x[0] + x[1], x[0] + (x[1] * x[1]) - 2 ]");

            Console.WriteLine("\n\tExpecting:\tsolve_newton_multi(fs, x=[0, 0]) = [1.0000000006984919, -1.0000000006984919]");
            result = multi.solve_newton_multi(fs, x);
            Console.WriteLine("\tResult:\t\tsolve_newton_multi(fs, x=[0, 0]) =  [" + result[0] + ", " + result[1] + "]");
        }
Exemplo n.º 2
0
        public static void test_jacobian()
        {
            Console.WriteLine("\nTesting jacobian(fs, x=[1,1,1]) ...\n");
            MultivariateFunction multi = new MultivariateFunction();
            List<MultivariateFunction> fs = new List<MultivariateFunction>() { new MyFunction6(), new MyFunction9() } ;
            double[] x = new double[] { 1, 1, 1 };

            Console.WriteLine("\n\tfs =  [ (2.0 * x[0]) + (3.0 * x[1]) + (5.0 * x[1] * x[2]), 2.0 * x[0] ]");

            Console.WriteLine("\n\tExpecting:\tmulti.jacobian(fs, x) = [[1.9999999..., 7.999999..., 4.9999999...], [1.9999999..., 0.0, 0.0]]");
            Console.WriteLine("\tResult:\t\tmulti.jacobian(fs, x=[1, 1, 1]) = " + multi.jacobian(fs, x) );
        }