private static void cgqf_test(int nt, int kind, double alpha, double beta, double a, double b) //****************************************************************************80 // // Purpose: // // CGQF_TEST calls CGQF to compute a quadrature formula. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 15 February 2010 // // Author: // // John Burkardt // { int i; Console.WriteLine(""); Console.WriteLine("CGQF_TEST"); Console.WriteLine(" CGQF computes a quadrature formula with nondefault"); Console.WriteLine(" values of parameters A and B."); Console.WriteLine(""); Console.WriteLine(" KIND = " + kind + ""); Console.WriteLine(" ALPHA = " + alpha + ""); Console.WriteLine(" BETA = " + beta + ""); Console.WriteLine(" A = " + a + ""); Console.WriteLine(" B = " + b + ""); const int lo = 0; double[] t = new double[nt]; double[] wts = new double[nt]; CGQF.cgqf(nt, kind, alpha, beta, a, b, lo, ref t, ref wts); Console.WriteLine(""); Console.WriteLine(" Index Abscissas Weights"); Console.WriteLine(""); for (i = 0; i < nt; i++) { Console.WriteLine(" " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4) + " " + t[i].ToString("0.################").PadLeft(24) + " " + wts[i].ToString("0.################").PadLeft(24) + ""); } }
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(""); }
public static double cegqf(int nt, int kind, double alpha, double beta, double a, double b, Func <double, int, double> f) //****************************************************************************80 // // Purpose: // // CEGQF computes a quadrature formula and applies it to a function. // // Discussion: // // The user chooses the quadrature formula to be used, as well as the // interval (A,B) in which it is applied. // // Note that the knots and weights of the quadrature formula are not // returned to the user. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 16 February 2010 // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // // Reference: // // Sylvan Elhay, Jaroslav Kautsky, // Algorithm 655: IQPACK, FORTRAN Subroutines for the Weights of // Interpolatory Quadrature, // ACM Transactions on Mathematical Software, // Volume 13, Number 4, December 1987, pages 399-415. // // Parameters: // // Input, int NT, the number of knots. // // Input, int KIND, the rule. // 1, Legendre, (a,b) 1.0 // 2, Chebyshev Type 1, (a,b) ((b-x)*(x-a))^-0.5) // 3, Gegenbauer, (a,b) ((b-x)*(x-a))^alpha // 4, Jacobi, (a,b) (b-x)^alpha*(x-a)^beta // 5, Generalized Laguerre, (a,+oo) (x-a)^alpha*exp(-b*(x-a)) // 6, Generalized Hermite, (-oo,+oo) |x-a|^alpha*exp(-b*(x-a)^2) // 7, Exponential, (a,b) |x-(a+b)/2.0|^alpha // 8, Rational, (a,+oo) (x-a)^alpha*(x+b)^beta // 9, Chebyshev Type 2, (a,b) ((b-x)*(x-a))^(+0.5) // // Input, double ALPHA, the value of Alpha, if needed. // // Input, double BETA, the value of Beta, if needed. // // Input, double A, B, the interval endpoints. // // Input, double F ( double X, int I ), the name of a routine which // evaluates the function and some of its derivatives. The routine // must return in F the value of the I-th derivative of the function // at X. The value I will always be 0. The value X will always be a knot. // // Output, double CEGQF, the value of the quadrature formula // applied to F. // { const int lo = 0; double[] t = new double[nt]; double[] wts = new double[nt]; CGQF.cgqf(nt, kind, alpha, beta, a, b, lo, ref t, ref wts); // // Evaluate the quadrature sum. // double qfsum = EIQFS.eiqfs(nt, t, wts, f); return(qfsum); }
private static void test02() //****************************************************************************80 // // Purpose: // // TEST02 tests CIQFS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 16 February 2010 // // Author: // // Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky. // C++ version by John Burkardt. // { int kind; Console.WriteLine(" ----------------------------------------"); Console.WriteLine(""); Console.WriteLine("TEST02"); Console.WriteLine(" Test CIQF, CIQFS, CGQF and CGQFS"); Console.WriteLine(" with all classical weight functions."); // // Try all weight functions. // for (kind = 1; kind <= 9; kind++) { // // Number of knots. // const int nt = 5; // // Set parameters ALPHA and BETA. // const double alpha = 0.5; double beta; if (kind != 8) { beta = 2.0; } else { beta = -16.0; } // // Set A and B. // const double a = -0.5; const double b = 2.0; // // Have CGQF compute the knots and weights. // int lu = 6; double[] t = new double[nt]; double[] wts = new double[nt]; Console.WriteLine(""); Console.WriteLine(" Knots and weights of Gauss quadrature formula"); Console.WriteLine(" computed by CGQF."); CGQF.cgqf(nt, kind, alpha, beta, a, b, lu, ref t, ref wts); // // Now compute the weights for the same knots by CIQF. // // Set the knot multiplicities. // int[] mlt = new int[nt]; int i; for (i = 0; i < nt; i++) { mlt[i] = 2; } // // Set the size of the weights array. // int nwts = 0; for (i = 0; i < nt; i++) { nwts += mlt[i]; } // // We need to deallocate and reallocate WTS because it is now of // dimension NWTS rather than NT. // wts = new double[nwts]; // // Because KEY = 1, NDX will be set up for us. // int[] ndx = new int[nt]; // // KEY = 1 indicates that the WTS array should hold the weights // in the usual order. // const int key = 1; // // LU controls printing. // A positive value requests that we compute and print weights, and // conduct a moments check. // lu = 6; Console.WriteLine(""); Console.WriteLine(" Weights of Gauss quadrature formula computed from the"); Console.WriteLine(" knots by CIQF."); wts = CIQF.ciqf(nt, t, mlt, nwts, ref ndx, key, kind, alpha, beta, a, b, lu); } }
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(""); }