예제 #1
0
    private static void test05()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST05 tests P00_GAUSS_HERMITE against the polynomials.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 May 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int m;

        Problem00.p00Data data = new();

        Console.WriteLine("");
        Console.WriteLine("TEST05");
        Console.WriteLine("  P00_GAUSS_HERMITE applies a Gauss-Hermite rule to");
        Console.WriteLine("  estimate the integral x^m exp(-x*x) over (-oo,+oo).");

        const int problem = 6;

        Console.WriteLine("");
        Console.WriteLine("         M     Order      Estimate        Exact           Error");

        for (m = 0; m <= 6; m++)
        {
            Problem06.p06_param(ref data.p6data, 'S', 'M', ref m);

            double exact = Problem00.p00_exact(ref data, problem);

            Console.WriteLine("");

            int order;
            for (order = 1; order <= 3 + m / 2; order++)
            {
                double estimate = Problem00.p00_gauss_hermite(ref data, problem, order);

                double error = Math.Abs(exact - estimate);

                Console.WriteLine("  " + m.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                  + "  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                  + "  " + estimate.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                                  + "  " + exact.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                                  + "  " + error.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
            }
        }
    }
예제 #2
0
    private static void test02()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST02 tests P00_EXACT.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 May 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int problem;

        Problem00.p00Data data = new();

        Console.WriteLine("");
        Console.WriteLine("TEST02");
        Console.WriteLine("  P00_EXACT returns the \"exact\" integral.");

        int problem_num = Problem00.p00_problem_num();

        int m = 4;

        Problem06.p06_param(ref data.p6data, 'S', 'M', ref m);

        Console.WriteLine("");
        Console.WriteLine("   Problem       EXACT");
        Console.WriteLine("");

        for (problem = 1; problem <= problem_num; problem++)
        {
            double exact = Problem00.p00_exact(ref data, problem);

            Console.WriteLine("  " + problem.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                              + "  " + exact.ToString("0.################").PadLeft(24) + "");
        }
    }
        public void Problem06_Return_Result_25164150()
        {
            double act = Problem06.SumSquareDifference();

            Assert.True(act.Equals(25164150));
        }
예제 #4
0
    private static void test06()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST06 tests P00_MONTE_CARLO.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    17 May 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int problem;

        Problem00.p00Data data = new();

        Console.WriteLine("");
        Console.WriteLine("TEST06");
        Console.WriteLine("  P00_MONTE_CARLO uses a weighted form of the Monte Carlo method");
        Console.WriteLine("  to estimate a Hermite integral on (-oo,+oo).");

        int problem_num = Problem00.p00_problem_num();

        int m = 4;

        Problem06.p06_param(ref data.p6data, 'S', 'M', ref m);

        Console.WriteLine("");
        Console.WriteLine("   Problem     Order          Estimate        Exact          Error");

        for (problem = 1; problem <= problem_num; problem++)
        {
            double exact = Problem00.p00_exact(ref data, problem);

            int order = 128;

            Console.WriteLine("");

            int order_log;
            for (order_log = 0; order_log <= 6; order_log++)
            {
                double estimate = Problem00.p00_monte_carlo(ref data, problem, order);

                double error = Math.Abs(exact - estimate);

                Console.WriteLine("  " + problem.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                  + "  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                  + "  " + estimate.ToString("0.######").PadLeft(14)
                                  + "  " + exact.ToString("0.######").PadLeft(14)
                                  + "  " + error.ToString("0.######").PadLeft(14) + "");

                order *= 4;
            }
        }
    }
예제 #5
0
    private static void test04()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST04 tests P00_TURING.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 May 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int    n = 0;
        int    test;
        double tol = 0;

        Problem00.p00Data data = new();

        Console.WriteLine("");
        Console.WriteLine("TEST04");
        Console.WriteLine("  P00_TURING applies a Turing procedure");
        Console.WriteLine("  to estimate an integral on (-oo,+oo).");

        int problem_num = Problem00.p00_problem_num();

        int m = 4;

        Problem06.p06_param(ref data.p6data, 'S', 'M', ref m);

        for (test = 1; test <= 2; test++)
        {
            tol = test switch
            {
                1 => 1.0E-4,
                2 => 1.0E-07,
                _ => tol
            };

            Console.WriteLine("");
            Console.WriteLine("  Using a tolerance of TOL = " + tol + "");
            Console.WriteLine("");
            Console.WriteLine("   Problem     Order          Estimate        Exact          Error");

            int problem;
            for (problem = 1; problem <= problem_num; problem++)
            {
                double exact = Problem00.p00_exact(ref data, problem);

                double h = 1.0;

                Console.WriteLine("");

                int order_log;
                for (order_log = 0; order_log <= 6; order_log++)
                {
                    double estimate = Problem00.p00_turing(ref data, problem, h, tol, ref n);

                    double error = Math.Abs(exact - estimate);

                    Console.WriteLine("  " + problem.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                      + "  " + h.ToString(CultureInfo.InvariantCulture).PadLeft(10)
                                      + "  " + n.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                      + "  " + estimate.ToString("0.######").PadLeft(14)
                                      + "  " + exact.ToString("0.######").PadLeft(14)
                                      + "  " + error.ToString("0.######").PadLeft(14) + "");

                    h /= 2.0;
                }
            }
        }
    }
예제 #6
0
    private static void test03()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests P00_GAUSS_HERMITE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    26 May 2009
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int problem;

        Problem00.p00Data data = new();

        Console.WriteLine("");
        Console.WriteLine("TEST03");
        Console.WriteLine("  P00_GAUSS_HERMITE applies a Gauss-Hermite rule");
        Console.WriteLine("  to estimate an integral on (-oo,+oo).");

        int problem_num = Problem00.p00_problem_num();

        int m = 4;

        Problem06.p06_param(ref data.p6data, 'S', 'M', ref m);

        Console.WriteLine("");
        Console.WriteLine("   Problem     Order          Estimate        Exact          Error");

        for (problem = 1; problem <= problem_num; problem++)
        {
            double exact = Problem00.p00_exact(ref data, problem);

            int order = 1;

            Console.WriteLine("");

            int order_log;
            for (order_log = 0; order_log <= 6; order_log++)
            {
                double estimate = Problem00.p00_gauss_hermite(ref data, problem, order);

                double error = Math.Abs(exact - estimate);

                Console.WriteLine("  " + problem.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                  + "  " + order.ToString(CultureInfo.InvariantCulture).PadLeft(8)
                                  + "  " + estimate.ToString("0.######").PadLeft(14)
                                  + "  " + exact.ToString("0.######").PadLeft(14)
                                  + "  " + error.ToString("0.######").PadLeft(14) + "");

                order *= 2;
            }
        }
    }
예제 #7
0
    public static void p00_fun(ref p00Data data, int problem, int option, int n, double[] x, ref double[] f)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P00_FUN evaluates the integrand for any problem.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 July 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROBLEM, the index of the problem.
    //
    //    Input, int OPTION:
    //    0, integrand is f(x).
    //    1, integrand is exp(-x*x) * f(x);
    //    2, integrand is exp(-x*x/2) * f(x);
    //
    //    Input, int N, the number of points.
    //
    //    Input, double X[N], the evaluation points.
    //
    //    Output, double F[N], the function values.
    //
    {
        switch (problem)
        {
        case 1:
            Problem01.p01_fun(option, n, x, ref f);
            break;

        case 2:
            Problem02.p02_fun(option, n, x, ref f);
            break;

        case 3:
            Problem03.p03_fun(option, n, x, ref f);
            break;

        case 4:
            Problem04.p04_fun(option, n, x, ref f);
            break;

        case 5:
            Problem05.p05_fun(option, n, x, ref f);
            break;

        case 6:
            Problem06.p06_fun(ref data.p6data, option, n, x, ref f);
            break;

        case 7:
            Problem07.p07_fun(option, n, x, ref f);
            break;

        case 8:
            Problem08.p08_fun(option, n, x, ref f);
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("P00_FUN - Fatal error!");
            Console.WriteLine("  Illegal problem number = " + problem + "");
            break;
        }
    }
예제 #8
0
    public static string p00_title(int problem)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P00_TITLE returns the title for any problem.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    02 February 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROBLEM, the index of the problem.
    //
    //    Output, string P00_TITLE, the title of the problem.
    //
    {
        string title;

        switch (problem)
        {
        case 1:
            title = Problem01.p01_title();
            break;

        case 2:
            title = Problem02.p02_title();
            break;

        case 3:
            title = Problem03.p03_title();
            break;

        case 4:
            title = Problem04.p04_title();
            break;

        case 5:
            title = Problem05.p05_title();
            break;

        case 6:
            title = Problem06.p06_title();
            break;

        case 7:
            title = Problem07.p07_title();
            break;

        case 8:
            title = Problem08.p08_title();
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("P00_TITLE - Fatal error!");
            Console.WriteLine("  Illegal problem number = " + problem + "");
            return("");
        }

        return(title);
    }
예제 #9
0
    public static double p00_exact(ref p00Data data, int problem)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P00_EXACT returns the exact integral for any problem.
    //
    //  Discussion:
    //
    //    This routine provides a "generic" interface to the exact integral
    //    routines for the various problems, and allows a problem to be called
    //    by index (PROBLEM) rather than by name.
    //
    //    In most cases, the "exact" value of the integral is not given;
    //    instead a "respectable" approximation is available.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    31 Julyl 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    //  Parameters:
    //
    //    Input, int PROBLEM, the index of the problem.
    //
    //    Output, double P00_EXACT, the exact value of the integral.
    //
    {
        double exact;

        switch (problem)
        {
        case 1:
            exact = Problem01.p01_exact();
            break;

        case 2:
            exact = Problem02.p02_exact();
            break;

        case 3:
            exact = Problem03.p03_exact();
            break;

        case 4:
            exact = Problem04.p04_exact();
            break;

        case 5:
            exact = Problem05.p05_exact();
            break;

        case 6:
            exact = Problem06.p06_exact(ref data.p6data);
            break;

        case 7:
            exact = Problem07.p07_exact();
            break;

        case 8:
            exact = Problem08.p08_exact();
            break;

        default:
            Console.WriteLine("");
            Console.WriteLine("P00_EXACT - Fatal error!");
            Console.WriteLine("  Illegal problem number = " + problem + "");
            return(1);
        }

        return(exact);
    }