public static void p_integral_test() //****************************************************************************80 // // Purpose: // // P_INTEGRAL_TEST tests P_INTEGRAL. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 15 March 2016 // // Author: // // John Burkardt // { int n; Console.WriteLine(""); Console.WriteLine("P_INTEGRAL_TEST:"); Console.WriteLine(" P_INTEGRAL returns the integral of P(n,x) over [-1,+1]."); Console.WriteLine(""); Console.WriteLine(" N Integral"); Console.WriteLine(""); for (n = 0; n <= 10; n++) { double value = Legendre.p_integral(n); Console.WriteLine(" " + n.ToString(CultureInfo.InvariantCulture).PadLeft(4) + " " + value.ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } }
public static void p_quadrature_rule_test() //****************************************************************************80 // // Purpose: // // P_QUADRATURE_RULE_TEST tests P_QUADRATURE_RULE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 14 March 2012 // // Author: // // John Burkardt // { int e; Console.WriteLine(""); Console.WriteLine("P_QUADRATURE_RULE_TEST:"); Console.WriteLine(" P_QUADRATURE_RULE computes the quadrature rule"); Console.WriteLine(" associated with P(n,x)"); const int n = 7; double[] x = new double[n]; double[] w = new double[n]; LegendreQuadrature.p_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 ( -1 <= X <= +1.0 ) X^E dx"); Console.WriteLine(""); Console.WriteLine(" E Q_Estimate Q_Exact"); Console.WriteLine(""); double[] f = new double[n]; for (e = 0; e <= 2 * n - 1; e++) { int i; 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; } } double q = typeMethods.r8vec_dot_product(n, w, f); double q_exact = Legendre.p_integral(e); Console.WriteLine(" " + e.ToString(CultureInfo.InvariantCulture).PadLeft(2) + " " + q.ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + q_exact.ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } }