Exemple #1
0
    //****************************************************************************80

    private static void triangle01_monomial_integral_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRIANGLE01_MONOMIAL_INTEGRAL_TEST estimates integrals over the unit triangle.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 April 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int d;

        Console.WriteLine("");
        Console.WriteLine("TRIANGLE01_MONOMIAL_INTEGRAL_TEST");
        Console.WriteLine("  TRIANGLE01_MONOMIAL_INTEGRAL returns the integral Q of");
        Console.WriteLine("  a monomial X^I Y^J over the interior of the unit triangle.");

        Console.WriteLine("");
        Console.WriteLine("   I   J         Q(I,J)");

        for (d = 0; d <= 5; d++)
        {
            Console.WriteLine("");
            int i;
            for (i = 0; i <= d; i++)
            {
                int    j = d - i;
                double q = Integrals.triangle01_monomial_integral(i, j);
                Console.WriteLine("  " + i.ToString(InvariantCulture).PadLeft(2)
                                  + "  " + j.ToString(InvariantCulture).PadLeft(2)
                                  + "  " + q + "");
            }
        }
    }
Exemple #2
0
    private static void triangle_poly_integral_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRIANGLE_POLY_INTEGRAL_TEST estimates integrals over a triangle.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 April 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int d1 = 1;
        int d2 = 2;
        int d3 = 2;
        int d4 = 2;

        double[] p1 =
        {
            0.0, 1.0, 0.0
        }

        ;
        double[] p2 =
        {
            0.0, 0.0, 0.0, 0.0, 1.0, 0.0
        }

        ;
        double[] p3 =
        {
            2.0, -3.0, 0.0, 0.0, 1.0, 0.0
        }

        ;
        double[] p4 =
        {
            0.0, 0.0, -40.0, 6.0, 0.0, 0.0
        }

        ;
        double[] t1 =
        {
            0.0, 0.0,
            1.0, 0.0,
            0.0, 1.0
        }

        ;
        double[] t2 =
        {
            0.0, 0.0,
            1.0, 0.0,
            1.0, 2.0
        }

        ;
        double[] t3 =
        {
            0.0, 0.0,
            1.0, 0.0,
            1.0, 3.0
        }

        ;
        double[] t4 =
        {
            0.0, 3.0,
            1.0, 1.0,
            5.0, 3.0
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("TRIANGLE_POLY_INTEGRAL_TEST");
        Console.WriteLine("  TRIANGLE_POLY_INTEGRAL returns the integral Q of");
        Console.WriteLine("  a polynomial over the interior of a triangle.");
        //
        //  Test 1:
        //  Integrate x over reference triangle.
        //
        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t1[0 + 0 * 2] + "," + t1[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t1[0 + 1 * 2] + "," + t1[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t1[0 + 2 * 2] + "," + t1[1 + 2 * 2] + ")");

        typeMethods.poly_print(d1, ref p1, "  Integrand p1(x,y)");

        double q  = Integrals.triangle_poly_integral(d1, p1, t1);
        double q2 = 1.0 / 6.0;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
        //
        //  Test 2:
        //  Integrate xy over a general triangle.
        //
        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t2[0 + 0 * 2] + "," + t2[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t2[0 + 1 * 2] + "," + t2[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t2[0 + 2 * 2] + "," + t2[1 + 2 * 2] + ")");

        typeMethods.poly_print(d2, ref p2, "  Integrand p2(x,y)");

        q  = Integrals.triangle_poly_integral(d2, p2, t2);
        q2 = 0.5;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
        //
        //  Test 3:
        //  Integrate 2-3x+xy over a general triangle.
        //
        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t3[0 + 0 * 2] + "," + t3[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t3[0 + 1 * 2] + "," + t3[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t3[0 + 2 * 2] + "," + t3[1 + 2 * 2] + ")");

        typeMethods.poly_print(d3, ref p3, "  Integrand p3(x,y)");

        q  = Integrals.triangle_poly_integral(d3, p3, t3);
        q2 = 9.0 / 8.0;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
        //
        //  Test 4:
        //  Integrate -40y + 6x^2 over a general triangle.
        //
        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t4[0 + 0 * 2] + "," + t4[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t4[0 + 1 * 2] + "," + t4[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t4[0 + 2 * 2] + "," + t4[1 + 2 * 2] + ")");

        typeMethods.poly_print(d4, ref p4, "  Integrand p4(x,y)");

        q  = Integrals.triangle_poly_integral(d4, p4, t4);
        q2 = -935.0 / 3.0;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
    }
Exemple #3
0
    private static void triangle_monomial_integral_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRIANGLE_MONOMIAL_INTEGRAL_TEST estimates integrals over a triangle.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 April 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double[] t1 =
        {
            0.0, 0.0,
            1.0, 0.0,
            0.0, 1.0
        }

        ;
        double[] t2 =
        {
            0.0, 0.0,
            1.0, 0.0,
            1.0, 2.0
        }

        ;
        double[] t3 =
        {
            -3.0, 0.0,
            6.0,  0.0,
            0.0, 3.0
        }

        ;
        double[] t4 =
        {
            0.0, 0.0,
            4.0, 0.0,
            0.0, 1.0
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("TRIANGLE_MONOMIAL_INTEGRAL_TEST");
        Console.WriteLine("  TRIANGLE_MONOMIAL_INTEGRAL returns the integral Q of");
        Console.WriteLine("  a monomial X^I Y^J over the interior of a triangle.");
        //
        //  Test 1:
        //
        int i = 1;
        int j = 0;

        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t1[0 + 0 * 2] + "," + t1[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t1[0 + 1 * 2] + "," + t1[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t1[0 + 2 * 2] + "," + t1[1 + 2 * 2] + ")");
        Console.WriteLine("  Integrand = x^" + i + " * y^" + j + "");

        double q  = Integrals.triangle_monomial_integral(i, j, t1);
        double q2 = 1.0 / 6.0;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
        //
        //  Test 2:
        //
        i = 1;
        j = 1;

        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t2[0 + 0 * 2] + "," + t2[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t2[0 + 1 * 2] + "," + t2[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t2[0 + 2 * 2] + "," + t2[1 + 2 * 2] + ")");
        Console.WriteLine("  Integrand = x^" + i + " * y^" + j + "");

        q  = Integrals.triangle_monomial_integral(i, j, t2);
        q2 = 0.5;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
        //
        //  Test 3:
        //
        i = 1;
        j = 0;

        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t3[0 + 0 * 2] + "," + t3[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t3[0 + 1 * 2] + "," + t3[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t3[0 + 2 * 2] + "," + t3[1 + 2 * 2] + ")");
        Console.WriteLine("  Integrand = x^" + i + " * y^" + j + "");

        q  = Integrals.triangle_monomial_integral(i, j, t3);
        q2 = 13.5;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
        //
        //  Test 4:
        //
        i = 1;
        j = 1;

        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices:");
        Console.WriteLine("    (" + t4[0 + 0 * 2] + "," + t4[1 + 0 * 2] + ")");
        Console.WriteLine("    (" + t4[0 + 1 * 2] + "," + t4[1 + 1 * 2] + ")");
        Console.WriteLine("    (" + t4[0 + 2 * 2] + "," + t4[1 + 2 * 2] + ")");
        Console.WriteLine("  Integrand = x^" + i + " * y^" + j + "");

        q  = Integrals.triangle_monomial_integral(i, j, t4);
        q2 = 2.0 / 3.0;

        Console.WriteLine("  Computed Q = " + q + "");
        Console.WriteLine("  Exact Q =    " + q2 + "");
    }
Exemple #4
0
    private static void triangle_area_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRIANGLE_AREA_TEST tests TRIANGLE_AREA_MAP.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 April 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int          i;
        const double r8_pi = 3.141592653589793;

        double[] t =
        {
            0.0, 0.0,
            2.0, 0.0,
            0.0, 1.0
        }

        ;

        Console.WriteLine("");
        Console.WriteLine("TRIANGLE_AREA_TEST:");
        Console.WriteLine("  TRIANGLE_AREA determines the (signed) area of a triangle.");

        Console.WriteLine("");
        Console.WriteLine("  Triangle vertices are:");
        Console.WriteLine("    (X1,Y1) = (0,0)");
        Console.WriteLine("    (X2,Y2) = 2*(cos(angle),sin(angle))");
        Console.WriteLine("    (X3,Y3) = (0,1)");
        Console.WriteLine("  where angle will sweep from 0 to 360 degrees.");

        double r = 2.0;

        Console.WriteLine("");
        Console.WriteLine("   I      Angle         X2          Y2          Area");
        Console.WriteLine("        (degrees)");
        Console.WriteLine("");
        for (i = 0; i <= 24; i++)
        {
            double angled = i * 180.0 / 12.0;
            double angler = i * r8_pi / 12.0;
            t[0 + 1 * 2] = r * Math.Cos(angler);
            t[1 + 1 * 2] = r * Math.Sin(angler);
            double area = Integrals.triangle_area(t);
            Console.WriteLine("  " + i.ToString(InvariantCulture).PadLeft(2)
                              + "  " + angled.ToString(InvariantCulture).PadLeft(10)
                              + "  " + t[0 + 1 * 2].ToString(InvariantCulture).PadLeft(10)
                              + "  " + t[1 + 1 * 2].ToString(InvariantCulture).PadLeft(10)
                              + "  " + area.ToString(InvariantCulture).PadLeft(10) + "");
        }
    }
Exemple #5
0
    private static void triangle_xy_integral_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRIANGLE_XY_INTEGRAL_TEST tests TRIANGLE_XY_INTEGRAL.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 April 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        Console.WriteLine("");
        Console.WriteLine("TRIANGLE_XY_INTEGRAL_TEST");
        Console.WriteLine("  TRIANGLE_XY_INTEGRAL determines Q, the integral of the");
        Console.WriteLine("  monomial X*Y over a triangle (X1,Y1), (X2,Y2), (X3,Y3).");

        double x1 = 0.0;
        double y1 = 0.0;

        double x2 = 1.0;
        double y2 = 0.0;

        double x3 = 1.0;
        double y3 = 2.0;

        double q = Integrals.triangle_xy_integral(x1, y1, x2, y2, x3, y3);

        Console.WriteLine("");
        Console.WriteLine("  (X1,Y1) = (" + x1 + "," + y1 + ")");
        Console.WriteLine("  (X2,Y2) = (" + x2 + "," + y2 + ")");
        Console.WriteLine("  (X3,Y3) = (" + x3 + "," + y3 + ")");
        Console.WriteLine("  Q = " + q + "");
        Console.WriteLine("  (Expecting answer 1/2.");

        x1 = 0.0;
        y1 = 0.0;

        x2 = 4.0;
        y2 = 0.0;

        x3 = 0.0;
        y3 = 1.0;

        q = Integrals.triangle_xy_integral(x1, y1, x2, y2, x3, y3);

        Console.WriteLine("");
        Console.WriteLine("  (X1,Y1) = (" + x1 + "," + y1 + ")");
        Console.WriteLine("  (X2,Y2) = (" + x2 + "," + y2 + ")");
        Console.WriteLine("  (X3,Y3) = (" + x3 + "," + y3 + ")");
        Console.WriteLine("  Q = " + q + "");
        Console.WriteLine("  (Expecting answer 2/3.");
    }
Exemple #6
0
    private static void triangle01_poly_integral_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TRIANGLE01_POLY_INTEGRAL_TEST: polynomial integrals over the unit triangle.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    21 April 2015
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int d_max = 6;
        int d1    = 1;
        int d2    = 2;
        int d3    = 2;

        int i = 0;
        int j = 0;
        int k;
        int m_max = (d_max + 1) * (d_max + 2) / 2;
        int m1    = (d1 + 1) * (d1 + 2) / 2;
        int m2    = (d2 + 1) * (d2 + 2) / 2;
        int m3    = (d3 + 1) * (d3 + 2) / 2;

        double[] p1 =
        {
            1.0, 2.0, 3.0
        }

        ;
        double[] p2 =
        {
            0.0, 0.0, 0.0, 0.0, 1.0, 0.0
        }

        ;
        double[] p3 =
        {
            1.0, -2.0, 3.0, -4.0, 5.0, -6.0
        }

        ;
        double[] qm = new double[28];

        for (k = 1; k <= m_max; k++)
        {
            typeMethods.i4_to_pascal(k, ref i, ref j);
            int km1 = k - 1;
            qm[km1] = Integrals.triangle01_monomial_integral(i, j);
        }

        Console.WriteLine("");
        Console.WriteLine("TRIANGLE01_POLY_INTEGRAL_TEST");
        Console.WriteLine("  TRIANGLE01_POLY_INTEGRAL returns the integral Q of");
        Console.WriteLine("  a polynomial P(X,Y) over the interior of the unit triangle.");

        Console.WriteLine("");
        typeMethods.poly_print(d1, ref p1, "  p(x,y)");
        double q = Integrals.triangle01_poly_integral(d1, p1);

        Console.WriteLine("");
        Console.WriteLine("  Q =         " + q + "");
        double q2 = typeMethods.r8vec_dot_product(m1, p1, qm);

        Console.WriteLine("  Q (exact) = " + q2 + "");

        Console.WriteLine("");
        typeMethods.poly_print(d2, ref p2, "  p(x,y)");
        q = Integrals.triangle01_poly_integral(d2, p2);
        Console.WriteLine("");
        Console.WriteLine("  Q =         " + q + "");
        q2 = typeMethods.r8vec_dot_product(m2, p2, qm);
        Console.WriteLine("  Q (exact) = " + q2 + "");

        Console.WriteLine("");
        typeMethods.poly_print(d3, ref p3, "  p(x,y)");
        q = Integrals.triangle01_poly_integral(d3, p3);
        Console.WriteLine("");
        Console.WriteLine("  Q =         " + q + "");
        q2 = typeMethods.r8vec_dot_product(m3, p3, qm);
        Console.WriteLine("  Q (exact) = " + q2 + "");
    }