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); } }
public static double ceiqf(int nt, double[] t, int[] mlt, int kind, double alpha, double beta, double a, double b, Func <double, int, double> f) //****************************************************************************80 // // Purpose: // // CEIQF constructs and applies a quadrature formula based on user knots. // // Discussion: // // The knots may have multiplicity. The quadrature interval is over // any valid A, B. A classical weight function is selected by the user. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 January 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, double T[NT], the knots. // // Input, int MLT[NT], the multiplicity of the 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 highest value of I will be the maximum value in MLT minus // one. The value X will always be a knot. // // Output, double CEIQF, the value of the quadrature formula // applied to F. // { int i; const int lu = 0; int n = 0; for (i = 0; i < nt; i++) { n += mlt[i]; } const int key = 1; int[] ndx = new int[nt]; double[] wts = CIQF.ciqf(nt, t, mlt, n, ref ndx, key, kind, alpha, beta, a, b, lu); double qfsum = EIQF.eiqf(nt, t, mlt, wts, n, ndx, key, f); return(qfsum); }
public static double[] cliqf(int nt, double[] t, int kind, double alpha, double beta, double a, double b, int lo) //****************************************************************************80 // // Purpose: // // CLIQF computes a classical quadrature formula, with optional printing. // // Discussion: // // This routine computes all the weights of an interpolatory // quadrature formula with // 1. only simple knots and // 2. a classical weight function with any valid A and B, and // 3. optionally prints the knots and weights and a check of the moments. // // To evaluate this quadrature formula for a given function F, // call routine EIQFS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 07 January 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, double T[NT], the 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, int LO, indicates what is to be done. // > 0, compute and print weights and moments check. // = 0, compute weights. // < 0, compute and print weights. // // Output, double CLIQF[NT], the weights. // { int i; const int key = 1; int[] mlt = new int[nt]; for (i = 0; i < nt; i++) { mlt[i] = 1; } int[] ndx = new int[nt]; double[] wts = CIQF.ciqf(nt, t, mlt, nt, ref ndx, key, kind, alpha, beta, a, b, lo); return(wts); }