Esempio n. 1
0
    public static double[] ciqf(int nt, double[] t, int[] mlt, int nwts, ref int[] ndx, int key,
                                int kind, double alpha, double beta, double a, double b, int lo)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CIQF computes weights for a classical weight function and any interval.
    //
    //  Discussion:
    //
    //    This routine compute somes or all the weights of a quadrature formula
    //    for a classical weight function with any valid A, B and a given set of
    //    knots and multiplicities.
    //
    //    The weights may be packed into the output array WTS according to a
    //    user-defined pattern or sequentially.
    //
    //    The routine will also optionally print knots and weights and a check
    //    of the moments.
    //
    //  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 MLT[NT], the multiplicity of the knots.
    //
    //    Input, int NWTS, the number of weights.
    //
    //    Input/output, int NDX[NT], used to index the output
    //    array WTS.  If KEY = 1, then NDX need not be preset.  For more
    //    details see the comments in CAWIQ.
    //
    //    Input, int KEY, indicates the structure of the WTS
    //    array.  It will normally be set to 1.  This will cause the weights to be
    //    packed sequentially in array WTS.  For more details see the comments
    //    in CAWIQ.
    //
    //    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, selects the actions to perform.
    //     > 0, compute and print weights.  Print moments check.
    //     = 0, compute weights.
    //     < 0, compute and print weights.
    //
    //    Output, double CIQF[NWTS], the weights.
    //
    {
        int j;

        int m = 1;
        int l = Math.Abs(key);

        for (j = 0; j < nt; j++)
        {
            if (l == 1 || Math.Abs(ndx[j]) != 0)
            {
                m += mlt[j];
            }
        }

        if (nwts + 1 < m)
        {
            Console.WriteLine("");
            Console.WriteLine("CIQF - Fatal error!");
            Console.WriteLine("  NWTS + 1 < M.");
            return(null);
        }

        int mex = 2 + m;

        //
        //  Scale the knots to default A, B.
        //
        double[] st = SCT.sct(nt, t, kind, a, b);
        //
        //  Compute the weights.
        //
        const int lu = 0;

        double[] wts = CIQFS.ciqfs(nt, st, mlt, nwts, ref ndx, key, kind, alpha, beta, lu);
        //
        //  Don't scale user's knots - only scale weights.
        //
        SCQF.scqf(nt, st, mlt, wts, nwts, ndx, ref wts, ref st, kind, alpha, beta, a, b);

        if (lo == 0)
        {
            return(wts);
        }

        int mop = m - 1;

        CHKQF.chkqf(t, wts, mlt, nt, nwts, ndx, key, mop, mex, kind,
                    alpha, beta, lo, a, b);

        return(wts);
    }
Esempio n. 2
0
    private static void test01()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST01 tests CIQFS.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    05 January 2010
    //
    //  Author:
    //
    //    Original FORTRAN77 version by Sylvan Elhay, Jaroslav Kautsky.
    //    C++ version by John Burkardt.
    //
    {
        int i;

        Console.WriteLine("  ----------------------------------------");
        Console.WriteLine("");
        Console.WriteLine("TEST01");
        Console.WriteLine("  Test CIQFS.");
        //
        //  Number of knots.
        //
        int nt = 5;

        //
        //  Set the knots in the default interval [-1,+1].
        //
        double[] t = new double[nt];

        for (i = 1; i <= nt; i++)
        {
            t[i - 1] = Math.Cos((2 * i - 1) * Math.PI / (2 * nt));
        }

        //
        //  Set the knot multiplicities.
        //
        int[] mlt = new int[nt];
        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];
        }

        //
        //  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;
        //
        //  Request Legendre weight function.
        //
        const int kind = 1;
        //
        //  ALPHA, BETA not used in Legendre weight function but set anyway.
        //
        const double alpha = 0.0;
        const double beta  = 0.0;
        //
        //  LU controls printing.
        //  A positive value requests that we compute and print weights, and
        //  conduct a moments check.
        //
        const int lu = 6;

        //
        //  This call returns the WTS array.
        //
        CIQFS.ciqfs(nt, t, mlt, nwts, ref ndx, key, kind, alpha, beta, lu);
    }
Esempio n. 3
0
    public static double[] cliqfs(int nt, double[] t, int kind, double alpha, double beta,
                                  int lo)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CLIQFS computes the weights of a quadrature formula in the default interval.
    //
    //  Discussion:
    //
    //    This routine computes the weights of an interpolatory quadrature formula
    //    with a classical weight function, in the default interval A, B,
    //    using only simple knots.
    //
    //    It can optionally print knots and weights and a check of the moments.
    //
    //    To evaluate a quadrature computed by CLIQFS, call 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, int LO, chooses the printing option.
    //     > 0, compute weights, print them, print the moment check results.
    //     0, compute weights.
    //     < 0, compute weights and print them.
    //
    //    Output, double CLIQFS[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 = CIQFS.ciqfs(nt, t, mlt, nt, ref ndx, key, kind, alpha, beta, lo);

        return(wts);
    }
Esempio n. 4
0
    public static double ceiqfs(int nt, double[] t, int[] mlt, int kind, double alpha,
                                double beta, Func <double, int, double> f)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CEIQFS computes and applies a quadrature formula based on user knots.
    //
    //  Discussion:
    //
    //    The knots may have multiplicity.  The quadrature interval is over
    //    the standard interval A, B for the classical weight function selected
    //    by the user.
    //
    //  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 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 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 CEIQFS, 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];
        }

        int[]     ndx = new int[nt];
        const int key = 1;

        double[] wts = CIQFS.ciqfs(nt, t, mlt, n, ref ndx, key, kind, alpha, beta, lu);

        double qfsum = EIQF.eiqf(nt, t, mlt, wts, n, ndx, key, f);

        return(qfsum);
    }