private static void Main(string[] args) //****************************************************************************80 // // Purpose: // // MAIN is the main program for JACOBI_RULE. // // Discussion: // // This program computes a standard Gauss-Jacobi quadrature rule // and writes it to a file. // // The user specifies: // * the ORDER (number of points) in the rule // * ALPHA, the exponent of ( 1 - x ); // * BETA, the exponent of ( 1 + x ); // * A, the left endpoint; // * B, the right endpoint; // * FILENAME, the root name of the output files. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 28 February 2010 // // Author: // // John Burkardt // { double a; double alpha; double b; double beta; string filename; int order; Console.WriteLine(""); Console.WriteLine("JACOBI_RULE"); Console.WriteLine(""); Console.WriteLine(" Compute a Gauss-Jacobi quadrature rule for approximating"); Console.WriteLine(" Integral ( A <= x <= B ) (B-x)^alpha (x-A)^beta f(x) dx"); Console.WriteLine(" of order ORDER."); Console.WriteLine(""); Console.WriteLine(" The user specifies ORDER, ALPHA, BETA, A, B, and FILENAME."); Console.WriteLine(""); Console.WriteLine(" ORDER is the number of points."); Console.WriteLine(" ALPHA is the exponent of ( B - x );"); Console.WriteLine(" BETA is the exponent of ( x - A );"); Console.WriteLine(" A is the left endpoint"); Console.WriteLine(" B is the right endpoint"); Console.WriteLine(" FILENAME is used to generate 3 files:"); Console.WriteLine(" filename_w.txt - the weight file"); Console.WriteLine(" filename_x.txt - the abscissa file."); Console.WriteLine(" filename_r.txt - the region file."); // // Get ORDER. // try { order = Convert.ToInt32(args[0]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of ORDER (1 or greater)"); order = Convert.ToInt32(Console.ReadLine()); } // // Get ALPHA. // try { alpha = Convert.ToDouble(args[1]); } catch { Console.WriteLine(""); Console.WriteLine(" ALPHA is the exponent of (B-x) in the integral:"); Console.WriteLine(" Note that -1.0 < ALPHA is required."); Console.WriteLine(" Enter the value of ALPHA:"); alpha = Convert.ToDouble(Console.ReadLine()); } // // Get BETA. // try { beta = Convert.ToDouble(args[2]); } catch { Console.WriteLine(""); Console.WriteLine(" BETA is the exponent of (x-A) in the integral:"); Console.WriteLine(" Note that -1.0 < BETA is required."); Console.WriteLine(" Enter the value of BETA:"); beta = Convert.ToDouble(Console.ReadLine()); } // // Get A. // try { a = Convert.ToDouble(args[3]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of A:"); a = Convert.ToDouble(Console.ReadLine()); } // // Get B. // try { b = Convert.ToDouble(args[4]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of B:"); b = Convert.ToDouble(Console.ReadLine()); } // // Get FILENAME. // try { filename = args[5]; } catch { Console.WriteLine(""); Console.WriteLine(" Enter FILENAME, the \"root name\" of the quadrature files)."); filename = Console.ReadLine(); } // // Input summary. // Console.WriteLine(""); Console.WriteLine(" ORDER = = " + order + ""); Console.WriteLine(" ALPHA = " + alpha + ""); Console.WriteLine(" BETA = " + beta + ""); Console.WriteLine(" A = " + a + ""); Console.WriteLine(" B = " + b + ""); Console.WriteLine(" FILENAME is \"" + filename + "\"."); // // Construct the rule. // double[] w = new double[order]; double[] x = new double[order]; int kind = 4; CGQF.cgqf(order, kind, alpha, beta, a, b, ref x, ref w); // // Write the rule. // double[] r = new double[2]; r[0] = a; r[1] = b; QuadratureRule.rule_write(order, filename, x, w, r); Console.WriteLine(""); Console.WriteLine("JACOBI_RULE:"); Console.WriteLine(" Normal end of execution."); Console.WriteLine(""); }
private static void Main(string[] args) //****************************************************************************80 // // Purpose: // // MAIN is the main program for CHEBYSHEV1_RULE. // // Discussion: // // This program computes a standard Gauss-Chebyshev type 1 quadrature rule // and writes it to a file. // // The user specifies: // * the ORDER (number of points) in the rule // * A, the left endpoint; // * B, the right endpoint; // * FILENAME, the root name of the output files. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 28 February 2010 // // Author: // // John Burkardt // { double a; double b; string filename; int order; Console.WriteLine(""); Console.WriteLine("CHEBYSHEV1_RULE"); Console.WriteLine(""); Console.WriteLine(" Compute a Gauss-Chebyshev type 1 rule for approximating"); Console.WriteLine(""); Console.WriteLine(" Integral ( A <= x <= B ) f(x) / sqrt ( ( x - A ) * ( B - x ) ) dx"); Console.WriteLine(""); Console.WriteLine(" of order ORDER."); Console.WriteLine(""); Console.WriteLine(" The user specifies ORDER, A, B and FILENAME."); Console.WriteLine(""); Console.WriteLine(" Order is the number of points."); Console.WriteLine(""); Console.WriteLine(" A is the left endpoint."); Console.WriteLine(""); Console.WriteLine(" B is the right endpoint."); Console.WriteLine(""); Console.WriteLine(" FILENAME is used to generate 3 files:"); Console.WriteLine(""); Console.WriteLine(" filename_w.txt - the weight file"); Console.WriteLine(" filename_x.txt - the abscissa file."); Console.WriteLine(" filename_r.txt - the region file."); // // Initialize parameters; // const double alpha = 0.0; const double beta = 0.0; // // Get ORDER. // try { order = Convert.ToInt32(args[0]); } catch (Exception) { Console.WriteLine(""); Console.WriteLine(" Enter the value of ORDER (1 or greater)"); order = Convert.ToInt32(Console.ReadLine()); } // // Get A. // try { a = Convert.ToDouble(args[1]); } catch (Exception) { Console.WriteLine(""); Console.WriteLine(" Enter the value of A:"); a = Convert.ToDouble(Console.ReadLine()); } // // Get B. // try { b = Convert.ToDouble(args[2]); } catch (Exception) { Console.WriteLine(""); Console.WriteLine(" Enter the value of B:"); b = Convert.ToDouble(Console.ReadLine()); } // // Get FILENAME: // try { filename = args[3]; } catch (Exception) { Console.WriteLine(""); Console.WriteLine(" Enter FILENAME, the \"root name\" of the quadrature files)."); filename = Console.ReadLine(); } // // Input summary. // Console.WriteLine(""); Console.WriteLine(" ORDER = " + order + ""); Console.WriteLine(" A = " + a + ""); Console.WriteLine(" B = " + b + ""); Console.WriteLine(" FILENAME = \"" + filename + "\"."); // // Construct the rule. // double[] w = new double[order]; double[] x = new double[order]; const int kind = 2; CGQF.cgqf(order, kind, alpha, beta, a, b, ref x, ref w); // // Write the rule. // double[] r = new double[2]; r[0] = a; r[1] = b; QuadratureRule.rule_write(order, filename, x, w, r); Console.WriteLine(""); Console.WriteLine("CHEBYSHEV1_RULE:"); Console.WriteLine(" Normal end of execution."); Console.WriteLine(""); }
private static void Main(string[] args) //****************************************************************************80 // // Purpose: // // MAIN is the main program for TRUNCATED_NORMAL_RULE. // // Discussion: // // This program computes a truncated normal quadrature rule // and writes it to a file. // // The user specifies: // * option: 0/1/2/3 for none, lower, upper, double truncation. // * N, the number of points in the rule; // * MU, the mean of the original normal distribution; // * SIGMA, the standard deviation of the original normal distribution, // * A, the left endpoint (for options 1 or 3) // * B, the right endpoint (for options 2 or 3); // * FILENAME, the root name of the output files. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 20 September 2013 // // Author: // // John Burkardt // { double a; double b; string filename; double[] moment = new double[1]; double mu; int n; int option; double sigma; Console.WriteLine(""); Console.WriteLine("TRUNCATED_NORMAL_RULE"); Console.WriteLine(""); Console.WriteLine(" For the (truncated) Gaussian probability density function"); Console.WriteLine(" pdf(x) = exp(-0.5*((x-MU)/SIGMA)^2) / SIGMA / sqrt ( 2 * pi )"); Console.WriteLine(" compute an N-point quadrature rule for approximating"); Console.WriteLine(" Integral ( A <= x <= B ) f(x) pdf(x) dx"); Console.WriteLine(""); Console.WriteLine(" The value of OPTION determines the truncation interval [A,B]:"); Console.WriteLine(" 0: (-oo,+oo)"); Console.WriteLine(" 1: [A,+oo)"); Console.WriteLine(" 2: (-oo,B]"); Console.WriteLine(" 3: [A,B]"); Console.WriteLine(""); Console.WriteLine(" The user specifies OPTION, N, MU, SIGMA, A, B and FILENAME."); Console.WriteLine(""); Console.WriteLine(" FILENAME is used to generate 3 files:"); Console.WriteLine(""); Console.WriteLine(" filename_w.txt - the weight file"); Console.WriteLine(" filename_x.txt - the abscissa file."); Console.WriteLine(" filename_r.txt - the region file, listing A and B."); int iarg = 0; // // Get OPTION. // try { option = Convert.ToInt32(args[iarg]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of OPTION 0/1/2/3: "); option = Convert.ToInt32(Console.ReadLine()); } switch (option) { case < 0: case > 3: Console.WriteLine(""); Console.WriteLine("TRUNCATED_NORMAL_RULE - Fatal error!"); Console.WriteLine(" 0 <= OPTION <= 3 was required."); return; } // // Get N. // iarg += 1; try { n = Convert.ToInt32(args[iarg]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of N (1 or greater)"); n = Convert.ToInt32(Console.ReadLine()); } // // Get MU. // iarg += 1; try { mu = Convert.ToDouble(args[iarg]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter MU, the mean value of the normal distribution:"); mu = Convert.ToDouble(Console.ReadLine()); } // // Get SIGMA. // iarg += 1; try { sigma = Convert.ToDouble(args[iarg]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter SIGMA, the standard deviation of the normal distribution:"); sigma = Convert.ToDouble(Console.ReadLine()); } sigma = Math.Abs(sigma); switch (option) { // // Get A. // case 1: case 3: iarg += 1; try { a = Convert.ToDouble(args[iarg]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the left endpoint A:"); a = Convert.ToDouble(Console.ReadLine()); } break; default: a = -typeMethods.r8_huge(); break; } switch (option) { // // Get B. // case 2: case 3: iarg += 1; try { b = Convert.ToDouble(args[iarg]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the right endpoint B:"); b = Convert.ToDouble(Console.ReadLine()); } break; default: b = typeMethods.r8_huge(); break; } if (b <= a) { Console.WriteLine(""); Console.WriteLine("TRUNCATED_NORMAL_RULE - Fatal error!"); Console.WriteLine(" A < B required!"); return; } // // Get FILENAME: // iarg += 1; try { filename = args[iarg]; } catch { Console.WriteLine(""); Console.WriteLine(" Enter FILENAME, the \"root name\" of the quadrature files)."); filename = Console.ReadLine(); } // // Input summary. // Console.WriteLine(""); Console.WriteLine(" OPTION = " + option + ""); Console.WriteLine(" N = " + n + ""); Console.WriteLine(" MU = " + mu + ""); Console.WriteLine(" SIGMA = " + sigma + ""); Console.WriteLine(" A = " + a + ""); Console.WriteLine(" B = " + b + ""); Console.WriteLine(" FILENAME = \"" + filename + "\"."); moment = option switch { // // Compute the moments. // 0 => Moments.moments_normal(2 * n + 1, mu, sigma), 1 => Moments.moments_truncated_normal_a(2 * n + 1, mu, sigma, a), 2 => Moments.moments_truncated_normal_b(2 * n + 1, mu, sigma, b), 3 => Moments.moments_truncated_normal_ab(2 * n + 1, mu, sigma, a, b), _ => moment }; // // Construct the rule from the moments. // double[] w = new double[n]; double[] x = new double[n]; Moments.moment_method(n, moment, ref x, ref w); // // Output the rule. // double[] r = new double[2]; r[0] = a; r[1] = b; QuadratureRule.rule_write(n, filename, x, w, r); Console.WriteLine(""); Console.WriteLine("TRUNCATED_NORMAL_RULE:"); Console.WriteLine(" Normal end of execution."); Console.WriteLine(""); } }
private static void Main(string[] args) //****************************************************************************80 // // Purpose: // // MAIN is the main program for PATTERSON_RULE. // // Discussion: // // This program computes a standard Gauss-Patterson quadrature rule // and writes it to a file. // // Usage: // // patterson_rule order a b output // // where // // * ORDER is the number of points in the rule, and must be // 1, 3, 7, 15, 31, 63, 127, 255 or 511. // * A is the left endpoint; // * B is the right endpoint; // * FILENAME is the "root name" of the output files. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 21 February 2010 // // Author: // // John Burkardt // { double a; double b; string filename; int order; Console.WriteLine(""); Console.WriteLine("PATTERSON_RULE"); Console.WriteLine(""); Console.WriteLine(" Compute a Gauss-Patterson rule for approximating"); Console.WriteLine(" Integral ( -1 <= x <= +1 ) f(x) dx"); Console.WriteLine(" of order ORDER."); Console.WriteLine(""); Console.WriteLine(" The user specifies ORDER, A, B, and FILENAME."); Console.WriteLine(""); Console.WriteLine(" ORDER is 1, 3, 7, 15, 31, 63, 127, 255 or 511."); Console.WriteLine(" A is the left endpoint."); Console.WriteLine(" B is the right endpoint."); Console.WriteLine(" FILENAME is used to generate 3 files:"); Console.WriteLine(" filename_w.txt - the weight file"); Console.WriteLine(" filename_x.txt - the abscissa file."); Console.WriteLine(" filename_r.txt - the region file."); // // Get ORDER. // try { order = Convert.ToInt32(args[0]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of ORDER."); order = Convert.ToInt32(Console.ReadLine()); } if (!Order.order_check(order)) { Console.WriteLine(""); Console.WriteLine("PATTERSON_RULE:"); Console.WriteLine(" ORDER is illegal."); Console.WriteLine(" Abnormal end of execution."); return; } // // Get A. // try { a = Convert.ToDouble(args[1]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the left endpoint A:"); a = Convert.ToDouble(Console.ReadLine()); } // // Get B. // try { b = Convert.ToDouble(args[2]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the right endpoint B:"); b = Convert.ToDouble(Console.ReadLine()); } // // Get FILENAME: // try { filename = args[3]; } catch { Console.WriteLine(""); Console.WriteLine(" Enter FILENAME, the \"root name\" of the quadrature files)."); filename = Console.ReadLine(); } // // Input summary. // Console.WriteLine(""); Console.WriteLine(" ORDER = " + order + ""); Console.WriteLine(" A = " + a + ""); Console.WriteLine(" B = " + b + ""); Console.WriteLine(" FILENAME = \"" + filename + "\"."); // // Construct the rule. // double[] r = new double[2]; double[] w = new double[order]; double[] x = new double[order]; r[0] = a; r[1] = b; PattersonQuadrature.patterson_set(order, ref x, ref w); // // Rescale the rule. // ClenshawCurtis.rescale(a, b, order, ref x, ref w); // // Output the rule. // QuadratureRule.rule_write(order, filename, x, w, r); Console.WriteLine(""); Console.WriteLine("PATTERSON_RULE:"); Console.WriteLine(" Normal end of execution."); Console.WriteLine(""); }
private static void Main(string[] args) //****************************************************************************80 // // Purpose: // // MAIN is the main program for GEN_LAGUERRE_RULE. // // Discussion: // // This program computes a standard or exponentially weighted // Gauss-Laguerre quadrature rule and writes it to a file. // // The user specifies: // * the ORDER (number of points) in the rule; // * ALPHA, the exponent of |X|; // * A, the left endpoint; // * B, the scale factor in the exponential; // * FILENAME, the root name of the output files. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 February 2010 // // Author: // // John Burkardt // { double a; double alpha; double b; string filename; int order; Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("GEN_LAGUERRE_RULE"); Console.WriteLine(""); Console.WriteLine(" Compute a generalized Gauss-Laguerre rule for approximating"); Console.WriteLine(" Integral ( a <= x < +oo ) |x-a|^ALPHA exp(-B*x(x-a)) f(x) dx"); Console.WriteLine(" of order ORDER."); Console.WriteLine(""); Console.WriteLine(" The user specifies ORDER, ALPHA, A, B, and FILENAME."); Console.WriteLine(""); Console.WriteLine(" ORDER is the number of points in the rule:"); Console.WriteLine(" ALPHA is the exponent of |X|:"); Console.WriteLine(" A is the left endpoint (typically 0)."); Console.WriteLine(" B is the exponential scale factor, typically 1:"); Console.WriteLine(" FILENAME is used to generate 3 files:"); Console.WriteLine(" * filename_w.txt - the weight file"); Console.WriteLine(" * filename_x.txt - the abscissa file."); Console.WriteLine(" * filename_r.txt - the region file."); // // Initialize parameters; // double beta = 0.0; // // Get ORDER. // try { order = Convert.ToInt32(args[0]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of ORDER (1 or greater)"); order = Convert.ToInt32(Console.ReadLine()); } // // Get ALPHA. // try { alpha = Convert.ToDouble(args[1]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of ALPHA."); Console.WriteLine(" ( -1.0 < ALPHA is required.)"); alpha = Convert.ToDouble(Console.ReadLine()); } // // Get A. // try { a = Convert.ToDouble(args[2]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the left endpoint A."); a = Convert.ToDouble(Console.ReadLine()); } // // Get B. // try { b = Convert.ToDouble(args[3]); } catch { Console.WriteLine(""); Console.WriteLine(" Enter the value of B"); b = Convert.ToDouble(Console.ReadLine()); } // // Get FILENAME. // try { filename = args[4]; } catch { Console.WriteLine(""); Console.WriteLine(" Enter FILENAME the \"root name\" of the quadrature files)."); filename = Console.ReadLine(); } // // Input summary. // Console.WriteLine(""); Console.WriteLine(" ORDER = " + order + ""); Console.WriteLine(" ALPHA = " + alpha + ""); Console.WriteLine(" A = " + a + ""); Console.WriteLine(" B = " + b + ""); Console.WriteLine(" FILENAME \"" + filename + "\"."); // // Construct the rule. // double[] w = new double[order]; double[] x = new double[order]; int kind = 5; CGQF.cgqf(order, kind, alpha, beta, a, b, ref x, ref w); // // Write the rule. // double[] r = new double[2]; r[0] = a; r[1] = typeMethods.r8_huge(); QuadratureRule.rule_write(order, filename, x, w, r); Console.WriteLine(""); Console.WriteLine("GEN_LAGUERRE_RULE:"); Console.WriteLine(" Normal end of execution."); Console.WriteLine(""); }