public static void pyramid_handle(int legendre_order, int jacobi_order, string filename) //****************************************************************************80 // // Purpose: // // PYRAMID_HANDLE computes the requested pyramid rule and outputs it. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 July 2009 // // Author: // // John Burkardt // // Parameters: // // Input, int LEGENDRE_ORDER, JACOBI_ORDER, the orders // of the component Legendre and Jacobi rules. // // Input, string FILENAME, the rootname for the files, // write files 'file_w.txt' and 'file_x.txt', and 'file_r.txt', weights, // abscissas, and region. // { const int DIM_NUM = 3; int k; double[] pyramid_r = { -1.0, -1.0, 0.0, +1.0, -1.0, 0.0, -1.0, +1.0, 0.0, +1.0, +1.0, 0.0, 0.0, 0.0, 1.0 }; // // Compute the factor rules. // double[] legendre_w = new double[legendre_order]; double[] legendre_x = new double[legendre_order]; Legendre.QuadratureRule.legendre_compute(legendre_order, ref legendre_x, ref legendre_w); double[] jacobi_w = new double[jacobi_order]; double[] jacobi_x = new double[jacobi_order]; const double jacobi_alpha = 2.0; const double jacobi_beta = 0.0; JacobiQuadrature.jacobi_compute(jacobi_order, jacobi_alpha, jacobi_beta, ref jacobi_x, ref jacobi_w); // // Compute the pyramid rule. // int pyramid_order = legendre_order * legendre_order * jacobi_order; double[] pyramid_w = new double[pyramid_order]; double[] pyramid_x = new double[DIM_NUM * pyramid_order]; const double volume = 4.0 / 3.0; int l = 0; for (k = 0; k < jacobi_order; k++) { double xk = (jacobi_x[k] + 1.0) / 2.0; double wk = jacobi_w[k] / 2.0; int j; for (j = 0; j < legendre_order; j++) { double xj = legendre_x[j]; double wj = legendre_w[j]; int i; for (i = 0; i < legendre_order; i++) { double xi = legendre_x[i]; double wi = legendre_w[i]; pyramid_w[l] = wi * wj * wk / 4.0 / volume; pyramid_x[0 + l * 3] = xi * (1.0 - xk); pyramid_x[1 + l * 3] = xj * (1.0 - xk); pyramid_x[2 + l * 3] = xk; l += 1; } } } // // Write the rule to files. // string filename_w = filename + "_w.txt"; string filename_x = filename + "_x.txt"; string filename_r = filename + "_r.txt"; Console.WriteLine(""); Console.WriteLine(" Creating quadrature files."); Console.WriteLine(""); Console.WriteLine(" \"Root\" file name is \"" + filename + "\"."); Console.WriteLine(""); Console.WriteLine(" Weight file will be \"" + filename_w + "\"."); Console.WriteLine(" Abscissa file will be \"" + filename_x + "\"."); Console.WriteLine(" Region file will be \"" + filename_r + "\"."); typeMethods.r8mat_write(filename_w, 1, pyramid_order, pyramid_w); typeMethods.r8mat_write(filename_x, DIM_NUM, pyramid_order, pyramid_x); typeMethods.r8mat_write(filename_r, DIM_NUM, 5, pyramid_r); }
private static void test185() //****************************************************************************80 // // Purpose: // // TEST185 tests JACOBI_POINTS and JACOBI_WEIGHTS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 02 April 2010 // // Author: // // John Burkardt // { const int TEST_NUM = 3; double[] alpha_test = { 0.5, 1.0, 2.5 }; double[] beta_test = { 0.5, 1.0, 2.5 }; const int order_max = 10; int test1; JacobiQuadrature.ParameterData data = new(); Console.WriteLine(""); Console.WriteLine("TEST185"); Console.WriteLine(" JACOBI_POINTS and JACOBI_WEIGHTS compute a Gauss-Jacobi rule"); Console.WriteLine(" which is appropriate for integrands of the form"); Console.WriteLine(""); Console.WriteLine(" Integral ( -1 <= x <= +1 ) f(x) (1-x)^alpha (1+x)^beta dx."); Console.WriteLine(""); Console.WriteLine(" For technical reasons, the parameters ALPHA and BETA are to"); Console.WriteLine(" supplied by a function called PARAMETER."); Console.WriteLine(""); Console.WriteLine(" Order ALPHA BETA ||X1-X2|| ||W1-W2||"); Console.WriteLine(""); for (test1 = 0; test1 < TEST_NUM; test1++) { double alpha = alpha_test[test1]; int test2; for (test2 = 0; test2 < TEST_NUM; test2++) { double beta = beta_test[test2]; const int dim = 0; data.NP = new int[1]; data.NP[0] = 2; data.P = new double[2]; data.P[0] = alpha; data.P[1] = beta; int order; for (order = 1; order <= order_max; order++) { double[] w1 = new double[order]; double[] w2 = new double[order]; double[] x1 = new double[order]; double[] x2 = new double[order]; JacobiQuadrature.jacobi_compute(order, alpha, beta, ref x1, ref w1); data = JacobiQuadrature.jacobi_points(parameter, data, order, dim, ref x2); data = JacobiQuadrature.jacobi_weights(parameter, data, order, dim, ref w2); double x_diff = typeMethods.r8vec_diff_norm_li(order, x1, x2); double w_diff = typeMethods.r8vec_diff_norm_li(order, w1, w2); Console.WriteLine(" " + order.ToString().PadLeft(6) + " " + alpha.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + beta.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + x_diff.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + w_diff.ToString(CultureInfo.InvariantCulture).PadLeft(10) + ""); } } } }