Exemplo n.º 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) + "");
        }
    }
Exemplo n.º 2
0
    public static double square_minimal_rule_error_max(int degree)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SQUARE_MINIMAL_RULE_ERROR_MAX returns the maximum error.
    //
    //  Discussion:
    //
    //    The rule of given DEGREE should theoretically have zero error
    //    for all monomials of degrees 0 <= D <= DEGREE.  This function
    //    checks every such monomial and reports the maximum error.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU GPL license.
    //
    //  Modified:
    //
    //    22 February 2018
    //
    //  Author:
    //
    //    John Burkardt.
    //
    //  Reference:
    //
    //    Mattia Festa, Alvise Sommariva,
    //    Computing almost minimal formulas on the square,
    //    Journal of Computational and Applied Mathematics,
    //    Volume 17, Number 236, November 2012, pages 4296-4302.
    //
    //  Parameters:
    //
    //    Input, int DEGREE, the desired total polynomial degree exactness
    //    of the quadrature rule.
    //
    //    Output, double SQUARE_MINIMAL_RULE_ERROR_MAX, the maximum error observed
    //    when using the rule to compute the integrals of all monomials of degree
    //    between 0 and DEGREE.
    //
    {
        int d;

        int[] e = new int[2];

        int order = square_minimal_rule_order(degree);

        double[] xyw = square_minimal_rule(degree);

        double error_max = 0.0;

        for (d = 0; d <= degree; d++)
        {
            int i;
            for (i = 0; i <= d; i++)
            {
                int j = d - i;
                e[0] = i;
                e[1] = j;
                double exact = Integrals.squaresym_monomial_integral(e);
                double s     = 0.0;
                int    k;
                for (k = 0; k < order; k++)
                {
                    s += xyw[2 + k * 3] * Math.Pow(xyw[0 + k * 3], i) * Math.Pow(xyw[1 + k * 3], j);
                }

                double err = Math.Abs(exact - s);
                if (error_max < err)
                {
                    error_max = err;
                }
            }
        }

        return(error_max);
    }