Example #1
0
        internal Vector Do(int size, IFun fun, Vector start)
        {
            Vector X = start.Clone();
            Vector F = new Vector(size);
            Matrix J = new Matrix(size, size);

            do
            {
                for (int i = 0; i < size; i++)
                {
                    F[i] = fun.F(i, X);
                }
                for (int i = 0; i < size; i++)
                {
                    for (int j = 0; j < size; j++)
                    {
                        J[i, j] = fun.df(i, j, X);
                    }
                }
                J.ElimPartial(F);
                X -= F;
                //need weight vector because different coordinates can diffs by order of magnitudes
            } while (F.norm(fun.weights()) > 1e-12);
            return(X);
        }
Example #2
0
 public ControllerWithConstructor(ITest test, IFun fun)
 {
     Test = test;
     Fun  = fun;
 }
Example #3
0
 public Test(IFun fun)
     : this()
 {
     Fun = fun;
 }
Example #4
0
        static void Main(string[] args)
        {
            var head = new ListNode(3);

            head.next = new ListNode(5);
            var ret = ReverseBetween(head, 1, 1);

            while (true)
            {
                Console.WriteLine("输入要计算的文件");
                string file = null;
                while (!string.IsNullOrWhiteSpace(file = Console.ReadLine()))
                {
                    break;
                }
                if (file == "exit")
                {
                    break;
                }
                var lines = System.IO.File.ReadAllLines(file);
                ShortestSubarray(lines[0].Split(',').Select(p => int.Parse(p)).ToArray(), int.Parse(lines[1]));
            }
            return;

            var  cmd  = PrintCmd();
            IFun funx = null;

            while (cmd != "0")
            {
                switch (cmd)
                {
                case "1":
                {
                    funx = new Fun1();
                    break;
                }

                case "2":
                {
                    funx = new Fun2();
                    break;
                }

                case "3":
                {
                    funx = new Fun3();
                    break;
                }

                case "4":
                {
                    funx = new LocalDUnitBTest();

                    break;
                }
                }

                if (funx != null)
                {
                    try
                    {
                        funx.Start();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }

                cmd = PrintCmd();
            }


            return;
        }