Пример #1
0
    public static void laguerre_polynomial_test04()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    LAGUERRE_POLYNOMIAL_TEST04 tests L_QUADRATURE_RULE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    11 March 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int e;

        double[] f;
        int      i;
        int      n;
        double   q;
        double   q_exact;

        double[] w;
        double[] x;

        Console.WriteLine("");
        Console.WriteLine("LAGUERRE_POLYNOMIAL_TEST04:");
        Console.WriteLine("  L_QUADRATURE_RULE computes the quadrature rule");
        Console.WriteLine("  associated with L(n,x)");

        n = 7;
        x = new double[n];
        w = new double[n];

        QuadratureRule.l_quadrature_rule(n, ref x, ref w);

        typeMethods.r8vec2_print(n, x, w, "      X            W");

        Console.WriteLine("");
        Console.WriteLine("  Use the quadrature rule to estimate:");
        Console.WriteLine("");
        Console.WriteLine("    Q = Integral ( 0 <= X < +00 ) X^E exp(-X) dx");
        Console.WriteLine("");
        Console.WriteLine("   E       Q_Estimate      Q_Exact");
        Console.WriteLine("");

        f = new double[n];

        for (e = 0; e <= 2 * n - 1; e++)
        {
            switch (e)
            {
            case 0:
            {
                for (i = 0; i < n; i++)
                {
                    f[i] = 1.0;
                }

                break;
            }

            default:
            {
                for (i = 0; i < n; i++)
                {
                    f[i] = Math.Pow(x[i], e);
                }

                break;
            }
            }

            q       = typeMethods.r8vec_dot_product(n, w, f);
            q_exact = Laguerre.l_integral(e);
            Console.WriteLine("  " + e.ToString().PadLeft(2)
                              + "  " + q.ToString().PadLeft(14)
                              + "  " + q_exact.ToString().PadLeft(14) + "");
        }
    }