Ejemplo n.º 1
0
    private static void test10(int nt, int kind, double alpha, double beta)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST10 calls CDGQF to compute a quadrature formula.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    08 January 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int i;

        Console.WriteLine("");
        Console.WriteLine("TEST10");
        Console.WriteLine("  Call CDGQF to compute a quadrature formula.");
        Console.WriteLine("");
        Console.WriteLine("  KIND = " + kind + "");
        Console.WriteLine("  ALPHA = " + alpha + "");
        Console.WriteLine("  BETA  = " + beta + "");

        double[] t   = new double[nt];
        double[] wts = new double[nt];

        CDGQF.cdgqf(nt, kind, alpha, beta, 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) + "");
        }
    }
Ejemplo n.º 2
0
    public static void cgqfs(int nt, int kind, double alpha, double beta, int lo, ref double[] t,
                             ref double[] wts)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CGQFS computes knots and weights of a Gauss quadrature formula.
    //
    //  Discussion:
    //
    //    This routine computes the knots and weights of a Gauss quadrature
    //    formula with:
    //
    //    * a classical weight function with default values for A and B;
    //    * only simple knots
    //    * optionally print knots and weights and a check of the moments
    //
    //    Use routine EIQFS to evaluate a quadrature formula computed by
    //    this routine.
    //
    //  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, 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, int LO, selects the action.
    //    > 0, compute and print knots and weights.  Print moments check.
    //    = 0, compute knots and weights.
    //    < 0, compute and print knots and weights.
    //
    //    Output, double T[NT], the knots.
    //
    //    Output, double WTS[NT], the weights.
    //
    {
        //
        //  Check there is enough workfield and assign workfield
        //
        const int key  = 1;
        int       mop  = 2 * nt;
        int       m    = mop + 1;
        int       mex  = m + 2;
        int       mmex = Math.Max(mex, 1);

        //
        //  Compute the Gauss quadrature formula for default values of A and B.
        //
        CDGQF.cdgqf(nt, kind, alpha, beta, ref t, ref wts);
        //
        //  Exit if no print required.
        //
        if (lo == 0)
        {
            return;
        }

        int[] mlt = new int[nt];
        int   i;

        for (i = 0; i < nt; i++)
        {
            mlt[i] = 1;
        }

        int[] ndx = new int[nt];
        for (i = 0; i < nt; i++)
        {
            ndx[i] = i + 1;
        }

        double[] w = new double[mmex];

        CHKQFS.chkqfs(t, wts, mlt, nt, nt, ndx, key, ref w, mop, mmex, kind, alpha,
                      beta, lo);
    }
Ejemplo n.º 3
0
    public static void cgqf(int nt, int kind, double alpha, double beta, double a, double b,
                            int lo, ref double[] t, ref double[] wts)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CGQF computes knots and weights of a Gauss quadrature formula.
    //
    //  Discussion:
    //
    //    The user may specify the interval (A,B).
    //
    //    Only simple knots are produced.
    //
    //    Use routine EIQFS to evaluate this quadrature formula.
    //
    //  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, or
    //    other parameters.
    //
    //    Input, int LO, defines the actions:
    //    < 0, compute knots and weights, and print.
    //    = 0, compute knots and weights.
    //    > 0, compute knots and weights, print, and do moment check.
    //
    //    Output, double T[NT], the knots.
    //
    //    Output, double WTS[NT], the weights.
    //
    {
        int i;
        //
        //  Check that there is enough workspace and assign it.
        //
        const int key  = 1;
        int       mop  = 2 * nt;
        int       m    = mop + 1;
        int       mex  = m + 2;
        int       mmex = Math.Max(mex, 1);

        //
        //  Compute the Gauss quadrature formula for default values of A and B.
        //
        CDGQF.cdgqf(nt, kind, alpha, beta, ref t, ref wts);
        //
        //  Prepare to scale the quadrature formula to other weight function with
        //  valid A and B.
        //
        int[] mlt = new int[nt];
        for (i = 0; i < nt; i++)
        {
            mlt[i] = 1;
        }

        int[] ndx = new int[nt];
        for (i = 0; i < nt; i++)
        {
            ndx[i] = i + 1;
        }

        SCQF.scqf(nt, t, mlt, wts, nt, ndx, ref wts, ref t, kind, alpha, beta, a, b);
        //
        //  Exit if no print required.
        //
        if (lo != 0)
        {
            CHKQF.chkqf(t, wts, mlt, nt, nt, ndx, key, mop, mmex,
                        kind, alpha, beta, lo, a, b);
        }
    }