private static void test04(int degree, int n) //****************************************************************************80 // // Purpose: // // TEST04 gets a rule and tests its accuracy. // // Licensing: // // This code is distributed under the GNU GPL license. // // Modified: // // 09 July 2014 // // Author: // // Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas. // C++ version by John Burkardt. // // Reference: // // Hong Xiao, Zydrunas Gimbutas, // A numerical algorithm for the construction of efficient quadrature // rules in two and higher dimensions, // Computers and Mathematics with Applications, // Volume 59, 2010, pages 663-676. // // Parameters: // // Input, int DEGREE, the desired total polynomial degree exactness // of the quadrature rule. 0 <= DEGREE <= 50. // // Input, int N, the number of nodes to be used by the rule. // { int i; int j; double[] z = new double[3]; Console.WriteLine(""); Console.WriteLine("TEST04"); Console.WriteLine(" Get a quadrature rule for the symmetric cube."); Console.WriteLine(" Test its accuracy."); Console.WriteLine(" Polynomial exactness degree DEGREE = " + degree + ""); // // Retrieve a symmetric quadrature rule. // double[] x = new double[3 * n]; double[] w = new double[n]; QuadratureRule.cube_arbq(degree, n, ref x, ref w); int npols = (degree + 1) * (degree + 2) * (degree + 3) / 6; double[] rints = new double[npols]; for (j = 0; j < npols; j++) { rints[j] = 0.0; } for (i = 0; i < n; i++) { z[0] = x[0 + i * 3]; z[1] = x[1 + i * 3]; z[2] = x[2 + i * 3]; double[] pols = QuadratureRule.lege3eva(degree, z); for (j = 0; j < npols; j++) { rints[j] += w[i] * pols[j]; } } double volume = 8.0; double d = 0.0; d = Math.Pow(rints[0] - Math.Sqrt(volume), 2); for (i = 1; i < npols; i++) { d += Math.Pow(rints[i], 2); } d = Math.Sqrt(d) / npols; Console.WriteLine(""); Console.WriteLine(" RMS error = " + d + ""); }