Пример #1
0
        private void Button_Click_Calc(object sender, RoutedEventArgs e)
        {
            string inputNum_string = Input_TextBox.Text;
            Number inputNum = new Number(inputNum_string, false, 0, 0);
            string inputAccuracy_string = Accuracy_TextBox.Text;
            int accuracy = Convert.ToInt32(inputAccuracy_string);
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

            //进行计算
            RangeAssist rangeAssist = new RangeAssist(inputNum, accuracy);
            //泰勒展开法进行计算
            stopwatch.Start();
            Taylor TaylorCal = new Taylor(rangeAssist.numConverted, accuracy);
            Number resultTaylor = rangeAssist.NumRecover(TaylorCal.TaylorCalculate());
            stopwatch.Stop();
            float taylorTime = (float)stopwatch.ElapsedMilliseconds / 1000;
            //外推加速法进行计算
            stopwatch.Start();
            Romberg RombergCal = new Romberg(rangeAssist.numConverted, accuracy);
            Number resultRomberg = rangeAssist.NumRecover(RombergCal.RombergCalculate());
            stopwatch.Stop();
            float rombergTime = (float)stopwatch.ElapsedMilliseconds / 1000;
            //牛顿法进行计算
            stopwatch.Start();
            Newton NewtonCal = new Newton(rangeAssist.numConverted, accuracy);
            Number resultNewton = rangeAssist.NumRecover(NewtonCal.NewtonCalculate());
            stopwatch.Stop();
            float newtonTime = (float)stopwatch.ElapsedMilliseconds / 1000;

            //显示字符串
            //泰勒法
            string resultTaylor_string = "";
            if (resultTaylor.sign == -1)
            {
                resultTaylor_string += "-";
            }
            for (int i = 0; i < resultTaylor.intLength; i++)
            {
                resultTaylor_string += resultTaylor.intPart[i].ToString();
            }
            resultTaylor_string += ".";
            for (int i = 0; i < resultTaylor.decLength; i++)
            {
                resultTaylor_string += resultTaylor.decPart[i].ToString();
            }
            Taylor_TextBox.Text = resultTaylor_string;
            TaylorTime_TextBox.Text = taylorTime.ToString() + "秒";
            //外推加速法
            string resultRomberg_string = "";
            if (resultRomberg.sign == -1)
            {
                resultRomberg_string += "-";
            }
            for (int i = 0; i < resultRomberg.intLength; i++)
            {
                resultRomberg_string += resultRomberg.intPart[i].ToString();
            }
            resultRomberg_string += ".";
            for (int i = 0; i < resultRomberg.decLength; i++)
            {
                resultRomberg_string += resultRomberg.decPart[i].ToString();
            }
            Romberg_TextBox.Text = resultRomberg_string;
            RombergTime_TextBox.Text = rombergTime.ToString() + "秒";
            //牛顿法
            string resultNewton_string = "";
            if (resultNewton.sign == -1)
            {
                resultNewton_string += "-";
            }
            for (int i = 0; i < resultNewton.intLength; i++)
            {
                resultNewton_string += resultNewton.intPart[i].ToString();
            }
            resultNewton_string += ".";
            for (int i = 0; i < resultNewton.decLength; i++)
            {
                resultNewton_string += resultNewton.decPart[i].ToString();
            }
            Newton_TextBox.Text = resultNewton_string;
            NewtonTime_TextBox.Text = newtonTime.ToString() + "秒";
        }
        private void Button_Click_Calc(object sender, RoutedEventArgs e)
        {
            string inputNum_string      = Input_TextBox.Text;
            Number inputNum             = new Number(inputNum_string, false, 0, 0);
            string inputAccuracy_string = Accuracy_TextBox.Text;
            int    accuracy             = Convert.ToInt32(inputAccuracy_string);

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

            //进行计算
            RangeAssist rangeAssist = new RangeAssist(inputNum, accuracy);

            //泰勒展开法进行计算
            stopwatch.Start();
            Taylor TaylorCal    = new Taylor(rangeAssist.numConverted, accuracy);
            Number resultTaylor = rangeAssist.NumRecover(TaylorCal.TaylorCalculate());

            stopwatch.Stop();
            float taylorTime = (float)stopwatch.ElapsedMilliseconds / 1000;

            //外推加速法进行计算
            stopwatch.Start();
            Romberg RombergCal    = new Romberg(rangeAssist.numConverted, accuracy);
            Number  resultRomberg = rangeAssist.NumRecover(RombergCal.RombergCalculate());

            stopwatch.Stop();
            float rombergTime = (float)stopwatch.ElapsedMilliseconds / 1000;

            //牛顿法进行计算
            stopwatch.Start();
            Newton NewtonCal    = new Newton(rangeAssist.numConverted, accuracy);
            Number resultNewton = rangeAssist.NumRecover(NewtonCal.NewtonCalculate());

            stopwatch.Stop();
            float newtonTime = (float)stopwatch.ElapsedMilliseconds / 1000;

            //显示字符串
            //泰勒法
            string resultTaylor_string = "";

            if (resultTaylor.sign == -1)
            {
                resultTaylor_string += "-";
            }
            for (int i = 0; i < resultTaylor.intLength; i++)
            {
                resultTaylor_string += resultTaylor.intPart[i].ToString();
            }
            resultTaylor_string += ".";
            for (int i = 0; i < resultTaylor.decLength; i++)
            {
                resultTaylor_string += resultTaylor.decPart[i].ToString();
            }
            Taylor_TextBox.Text     = resultTaylor_string;
            TaylorTime_TextBox.Text = taylorTime.ToString() + "秒";
            //外推加速法
            string resultRomberg_string = "";

            if (resultRomberg.sign == -1)
            {
                resultRomberg_string += "-";
            }
            for (int i = 0; i < resultRomberg.intLength; i++)
            {
                resultRomberg_string += resultRomberg.intPart[i].ToString();
            }
            resultRomberg_string += ".";
            for (int i = 0; i < resultRomberg.decLength; i++)
            {
                resultRomberg_string += resultRomberg.decPart[i].ToString();
            }
            Romberg_TextBox.Text     = resultRomberg_string;
            RombergTime_TextBox.Text = rombergTime.ToString() + "秒";
            //牛顿法
            string resultNewton_string = "";

            if (resultNewton.sign == -1)
            {
                resultNewton_string += "-";
            }
            for (int i = 0; i < resultNewton.intLength; i++)
            {
                resultNewton_string += resultNewton.intPart[i].ToString();
            }
            resultNewton_string += ".";
            for (int i = 0; i < resultNewton.decLength; i++)
            {
                resultNewton_string += resultNewton.decPart[i].ToString();
            }
            Newton_TextBox.Text     = resultNewton_string;
            NewtonTime_TextBox.Text = newtonTime.ToString() + "秒";
        }
Пример #3
0
    private static void test03(int dim_num, Func <int, double[], double> func)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests ROMBERG_ND.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 February 2007
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int DIM_NUM, the spatial dimension.
    //
    //    Input, double FUNC ( int dim_num, double x[] ), evaluates the function
    //    to be integrated.
    //
    {
        int       dim;
        int       eval_num = 0;
        int       ind      = 0;
        const int it_max   = 3;

        //
        //  Set the integration limits.
        //
        double[] a       = new double[dim_num];
        double[] b       = new double[dim_num];
        int[]    sub_num = new int[dim_num];

        for (dim = 0; dim < dim_num; dim++)
        {
            a[dim] = 0.0;
        }

        for (dim = 0; dim < dim_num; dim++)
        {
            b[dim] = 1.0;
        }

        double tol = 0.001;

        for (dim = 0; dim < dim_num; dim++)
        {
            sub_num[dim] = 10;
        }

        double result = Romberg.romberg_nd(func, a, b, dim_num, sub_num, it_max, tol,
                                           ref ind, ref eval_num);

        Console.WriteLine("  ROMBERG_ND:     "
                          + result.ToString("0.############").PadLeft(20)
                          + "  " + eval_num.ToString().PadLeft(8) + "");
    }