Exemplo n.º 1
0
    public static void p_polynomial_value_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P_POLYNOMIAL_VALUE_TEST tests P_POLYNOMIAL_VALUE.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 March 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        double fx1 = 0;
        int    n   = 0;
        double x   = 0;

        double[] x_vec = new double[1];

        Console.WriteLine("");
        Console.WriteLine("P_POLYNOMIAL_VALUE_TEST:");
        Console.WriteLine("  P_POLYNOMIAL_VALUE evaluates the Legendre polynomial P(n,x).");
        Console.WriteLine("");
        Console.WriteLine("                        Tabulated                 Computed");
        Console.WriteLine("     N        X           P(N,X)                    P(N,X)                     Error");
        Console.WriteLine("");

        int n_data = 0;

        for (;;)
        {
            Burkardt.Values.Legendre.p_polynomial_values(ref n_data, ref n, ref x, ref fx1);

            if (n_data == 0)
            {
                break;
            }

            x_vec[0] = x;
            double[] fx2_vec = Legendre.p_polynomial_value(1, n, x_vec);
            double   fx2     = fx2_vec[n];

            double e = fx1 - fx2;

            Console.WriteLine("  " + n.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + x.ToString(CultureInfo.InvariantCulture).PadLeft(12)
                              + "  " + fx1.ToString("0.################").PadLeft(24)
                              + "  " + fx2.ToString("0.################").PadLeft(24)
                              + "  " + e.ToString(CultureInfo.InvariantCulture).PadLeft(8) + "");
        }
    }
Exemplo n.º 2
0
    public static void p_polynomial_zeros_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    P_POLYNOMIAL_ZEROS_TEST tests P_POLYNOMIAL_ZEROS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    14 March 2012
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int degree;

        Console.WriteLine("");
        Console.WriteLine("P_POLYNOMIAL_ZEROS_TEST:");
        Console.WriteLine("  P_POLYNOMIAL_ZEROS computes the zeros of P(n,x)");
        Console.WriteLine("  Check by calling P_POLYNOMIAL_VALUE there.");

        for (degree = 1; degree <= 5; degree++)
        {
            double[] z     = Legendre.p_polynomial_zeros(degree);
            string   title = "  Computed zeros for P(" + degree + ",z):";
            typeMethods.r8vec_print(degree, z, title);

            double[] hz = Legendre.p_polynomial_value(degree, degree, z);
            title = "  Evaluate P(" + degree + ",z):";
            typeMethods.r8vec_print(degree, hz, title, +degree * degree);
        }
    }