Пример #1
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("The problem of the algebraic interpolation.");
            Interpolation i = new Interpolation();
            Function      f = new EFunction();
            double        a = 0;
            double        b = 1;

            int    m = 10;
            int    n = 5;// n <= m
            double h = (b - a) / m;

            System.Console.Write("Function: ");
            f.Print();

            System.Console.WriteLine("Segment: [{0}, {1}]", a, b);
            System.Console.WriteLine("Params: m = {0}, n = {1}", m, n);

            i.Func = f;
            i.Init(m, n, a, b);

            double fx;

            while (true)
            {
                System.Console.WriteLine("Input X in [" + a.ToString() + ", " + h.ToString() + "]" + " [" + (b - h).ToString() + ", " + b.ToString() + "]");
                System.Console.WriteLine("[" + (a + ((int)(n + 1) / 2) * h).ToString() + ", " + (b - ((int)(n + 1) / 2) * h).ToString() + "]");
                double x = Convert.ToSingle(System.Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);

                fx = i.Calc(x);

                System.Console.WriteLine("Pn(x) = {0}", (double)fx);
                System.Console.WriteLine("efn(x) = {0}", Math.Abs((double)f.f(x) - (double)fx));
            }


            System.Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("The problem of the algebraic interpolation.");
            Interpolation i = new Interpolation();
            Function f = new EFunction();
            double a = 0;
            double b = 1;

            int m = 10;
            int n = 5;// n <= m
            double h = (b-a)/m;

            System.Console.Write("Function: ");
            f.Print();

            System.Console.WriteLine("Segment: [{0}, {1}]", a, b);
            System.Console.WriteLine("Params: m = {0}, n = {1}", m, n);

            i.Func = f;
            i.Init(m, n, a, b);

            double fx;
            while (true)
            {
                System.Console.WriteLine("Input X in ["+a.ToString()+", "+h.ToString()+"]" + " ["+(b-h).ToString()+", "+b.ToString()+"]");
                System.Console.WriteLine("[" + (a + ((int)(n + 1) / 2) * h).ToString() + ", " + (b - ((int)(n + 1) / 2) * h).ToString() + "]");
                double x = Convert.ToSingle(System.Console.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);

                fx = i.Calc(x);

                System.Console.WriteLine("Pn(x) = {0}", (double)fx);
                System.Console.WriteLine("efn(x) = {0}", Math.Abs((double)f.f(x) - (double)fx));
            }

            System.Console.ReadKey();
        }