Пример #1
0
    private static void squaresym_monomial_integral_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SQUARESYM_MONOMIAL_INTEGRAL_TEST tests SQUARESYM_MONOMIAL_INTEGRAL.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 February 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const int m = 2;
        const int n = 4192;
        int       test;
        const int test_num = 20;

        Console.WriteLine("");
        Console.WriteLine("SQUARESYM_MONOMIAL_INTEGRAL_TEST");
        Console.WriteLine("  SQUARESYM_MONOMIAL_INTEGRAL returns the exact integral");
        Console.WriteLine("  of a monomial over the interior of the symmetric unit square in 2D.");
        Console.WriteLine("  Compare exact and estimated values.");
        //
        //  Get sample points.
        //
        int seed = 123456789;

        double[] x = Integrals.squaresym_sample(n, ref seed);
        Console.WriteLine("");
        Console.WriteLine("  Number of sample points is " + n + "");
        //
        //  Randomly choose exponents.
        //
        Console.WriteLine("");
        Console.WriteLine("  Ex  Ey     MC-Estimate           Exact      Error");
        Console.WriteLine("");

        for (test = 1; test <= test_num; test++)
        {
            int[] e = UniformRNG.i4vec_uniform_ab_new(m, 0, 7, ref seed);

            double[] value = Monomial.monomial_value(m, n, e, x);

            double result = Integrals.squaresym_area() * typeMethods.r8vec_sum(n, value) / n;
            double exact  = Integrals.squaresym_monomial_integral(e);
            double error  = Math.Abs(result - exact);

            Console.WriteLine("  " + e[0].ToString().PadLeft(2)
                              + "  " + e[1].ToString().PadLeft(2)
                              + "  " + result.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + exact.ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + error.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }
    }
Пример #2
0
    private static void square_minimal_rule_print_test(int degree)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SQUARE_MINIMAL_RULE_PRINT_TEST tests SQUARE_MINIMAL_RULE_PRINT.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    22 February 2018
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int j;

        Console.WriteLine("");
        Console.WriteLine("SQUARE_MINIMAL_RULE_PRINT_TEST");
        Console.WriteLine("  SQUARE_MINIMAL_RULE_PRINT prints a quadrature rule");
        Console.WriteLine("  for the symmetric unit square.");
        Console.WriteLine("  Minimal quadrature rule for a square.");
        Console.WriteLine("  Polynomial exactness degree DEGREE = " + degree + "");
        //
        //  Retrieve and print a symmetric quadrature rule.
        //
        double[] xyw = MinimalRule.square_minimal_rule(degree);

        int order = MinimalRule.square_minimal_rule_order(degree);

        Console.WriteLine("");
        Console.WriteLine("  Number of nodes N = " + order + "");

        Console.WriteLine("");
        Console.WriteLine("     J          X               Y               W");
        Console.WriteLine("");
        for (j = 0; j < order; j++)
        {
            Console.WriteLine("  " + j.ToString().PadLeft(4)
                              + "  " + xyw[0 + j * 3].ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + xyw[1 + j * 3].ToString(CultureInfo.InvariantCulture).PadLeft(14)
                              + "  " + xyw[2 + j * 3].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        double d = 0.0;

        for (j = 0; j < order; j++)
        {
            d += xyw[2 + j * 3];
        }

        Console.WriteLine("");
        Console.WriteLine("   Sum  " + d.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        double area = Integrals.squaresym_area();

        Console.WriteLine("  Area  " + area.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
    }