Ejemplo n.º 1
0
    public static void scqf(int nt, double[] t, int[] mlt, double[] wts, int nwts, int[] ndx,
                            ref double[] swts, ref double[] st, int kind, double alpha, double beta, double a,
                            double b)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    SCQF scales a quadrature formula to a nonstandard interval.
    //
    //  Discussion:
    //
    //    The arrays WTS and SWTS may coincide.
    //
    //    The arrays T and ST may coincide.
    //
    //  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, double T[NT], the original knots.
    //
    //    Input, int MLT[NT], the multiplicity of the knots.
    //
    //    Input, double WTS[NWTS], the weights.
    //
    //    Input, int NWTS, the number of weights.
    //
    //    Input, int NDX[NT], used to index the array WTS.
    //    For more details see the comments in CAWIQ.
    //
    //    Output, double SWTS[NWTS], the scaled weights.
    //
    //    Output, double ST[NT], the scaled 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.
    //
    {
        double al   = 0;
        double be   = 0;
        double shft = 0;
        double slp  = 0;

        double temp = typeMethods.r8_epsilon();

        PARCHK.parchk(kind, 1, alpha, beta);

        switch (kind)
        {
        case 1:
        {
            al = 0.0;
            be = 0.0;
            if (Math.Abs(b - a) <= temp)
            {
                Console.WriteLine("");
                Console.WriteLine("SCQF - Fatal error!");
                Console.WriteLine("  |B - A| too small.");
                return;
            }

            shft = (a + b) / 2.0;
            slp  = (b - a) / 2.0;
            break;
        }

        case 2:
        {
            al = -0.5;
            be = -0.5;
            if (Math.Abs(b - a) <= temp)
            {
                Console.WriteLine("");
                Console.WriteLine("SCQF - Fatal error!");
                Console.WriteLine("  |B - A| too small.");
                return;
            }

            shft = (a + b) / 2.0;
            slp  = (b - a) / 2.0;
            break;
        }

        case 3:
        {
            al = alpha;
            be = alpha;
            if (Math.Abs(b - a) <= temp)
            {
                Console.WriteLine("");
                Console.WriteLine("SCQF - Fatal error!");
                Console.WriteLine("  |B - A| too small.");
                return;
            }

            shft = (a + b) / 2.0;
            slp  = (b - a) / 2.0;
            break;
        }

        case 4:
        {
            al = alpha;
            be = beta;

            if (Math.Abs(b - a) <= temp)
            {
                Console.WriteLine("");
                Console.WriteLine("SCQF - Fatal error!");
                Console.WriteLine("  |B - A| too small.");
                return;
            }

            shft = (a + b) / 2.0;
            slp  = (b - a) / 2.0;
            break;
        }

        case 5 when b <= 0.0:
            Console.WriteLine("");
            Console.WriteLine("SCQF - Fatal error!");
            Console.WriteLine("  B <= 0");
            return;

        case 5:
            shft = a;
            slp  = 1.0 / b;
            al   = alpha;
            be   = 0.0;
            break;

        case 6 when b <= 0.0:
            Console.WriteLine("");
            Console.WriteLine("SCQF - Fatal error!");
            Console.WriteLine("  B <= 0.");
            return;

        case 6:
            shft = a;
            slp  = 1.0 / Math.Sqrt(b);
            al   = alpha;
            be   = 0.0;
            break;

        case 7:
        {
            al = alpha;
            be = 0.0;
            if (Math.Abs(b - a) <= temp)
            {
                Console.WriteLine("");
                Console.WriteLine("SCQF - Fatal error!");
                Console.WriteLine("  |B - A| too small.");
                return;
            }

            shft = (a + b) / 2.0;
            slp  = (b - a) / 2.0;
            break;
        }

        case 8 when a + b <= 0.0:
            Console.WriteLine("");
            Console.WriteLine("SCQF - Fatal error!");
            Console.WriteLine("  A + B <= 0.");
            return;

        case 8:
            shft = a;
            slp  = a + b;
            al   = alpha;
            be   = beta;
            break;

        case 9:
        {
            al = 0.5;
            be = 0.5;
            if (Math.Abs(b - a) <= temp)
            {
                Console.WriteLine("");
                Console.WriteLine("SCQF - Fatal error!");
                Console.WriteLine("  |B - A| too small.");
                return;
            }

            shft = (a + b) / 2.0;
            slp  = (b - a) / 2.0;
            break;
        }
        }

        double p = Math.Pow(slp, al + be + 1.0);

        for (int k = 0; k < nt; k++)
        {
            st[k] = shft + slp * t[k];
            int l = Math.Abs(ndx[k]);

            if (l == 0)
            {
                continue;
            }

            double tmp = p;
            for (int i = l - 1; i <= l - 1 + mlt[k] - 1; i++)
            {
                swts[i] = wts[i] * tmp;
                tmp    *= slp;
            }
        }
    }
Ejemplo n.º 2
0
    public static void cdgqf(int nt, int kind, double alpha, double beta, ref double[] t,
                             ref double[] wts)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CDGQF computes a Gauss quadrature formula with default A, B and simple knots.
    //
    //  Discussion:
    //
    //    This routine computes all the knots and weights of a Gauss quadrature
    //    formula with a classical weight function with default values for A and B,
    //    and only simple knots.
    //
    //    There are no moments checks and no printing is done.
    //
    //    Use routine EIQFS to evaluate a quadrature computed by CGQFS.
    //
    //  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,inf)     (x-a)^alpha*exp(-b*(x-a))
    //    6, Generalized Hermite,  (-inf,inf)  |x-a|^alpha*exp(-b*(x-a)^2)
    //    7, Exponential,          (a,b)       |x-(a+b)/2.0|^alpha
    //    8, Rational,             (a,inf)     (x-a)^alpha*(x+b)^beta
    //
    //    Input, double ALPHA, the value of Alpha, if needed.
    //
    //    Input, double BETA, the value of Beta, if needed.
    //
    //    Output, double T[NT], the knots.
    //
    //    Output, double WTS[NT], the weights.
    //
    {
        PARCHK.parchk(kind, 2 * nt, alpha, beta);
        //
        //  Get the Jacobi matrix and zero-th moment.
        //
        double[] aj = new double[nt];
        double[] bj = new double[nt];

        double zemu = Matrix.class_matrix(kind, nt, alpha, beta, ref aj, ref bj);

        //
        //  Compute the knots and weights.
        //
        SGQF.sgqf(nt, aj, ref bj, zemu, ref t, ref wts);
    }
Ejemplo n.º 3
0
    public static double[] wm(int m, int kind, double alpha, double beta)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    WM evaluates the first M moments of classical weight functions.
    //
    //  Discussion:
    //
    //    W(K) = Integral ( A <= X <= B ) X**(K-1) * W(X) dx
    //
    //  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 M, the number of moments to evaluate.
    //
    //    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.
    //
    //    Output, double WM[M], the first M moments.
    //
    {
        double als;
        int    k;

        double rk;

        PARCHK.parchk(kind, m, alpha, beta);

        double[] w = new double[m];

        for (k = 2; k <= m; k += 2)
        {
            w[k - 1] = 0.0;
        }

        switch (kind)
        {
        case 1:
        {
            for (k = 1; k <= m; k += 2)
            {
                rk       = k;
                w[k - 1] = 2.0 / rk;
            }

            break;
        }

        case 2:
        {
            w[0] = Math.PI;
            for (k = 3; k <= m; k += 2)
            {
                rk       = k;
                w[k - 1] = w[k - 3] * (rk - 2.0) / (rk - 1.0);
            }

            break;
        }

        case 3:
        {
            w[0] = Math.Sqrt(Math.PI) * typeMethods.r8_gamma(alpha + 1.0)
                   / typeMethods.r8_gamma(alpha + 3.0 / 2.0);

            for (k = 3; k <= m; k += 2)
            {
                rk       = k;
                w[k - 1] = w[k - 3] * (rk - 2.0) / (2.0 * alpha + rk);
            }

            break;
        }

        case 4:
        {
            als  = alpha + beta + 1.0;
            w[0] = Math.Pow(2.0, als) * typeMethods.r8_gamma(alpha + 1.0)
                   / typeMethods.r8_gamma(als + 1.0) * typeMethods.r8_gamma(beta + 1.0);

            for (k = 2; k <= m; k++)
            {
                double sum = 0.0;
                double trm = 1.0;
                rk = k;

                int i;
                for (i = 0; i <= (k - 2) / 2; i++)
                {
                    double tmpa = trm;
                    int    ja;
                    for (ja = 1; ja <= 2 * i; ja++)
                    {
                        tmpa = tmpa * (alpha + ja) / (als + ja);
                    }

                    int jb;
                    for (jb = 1; jb <= k - 2 * i - 1; jb++)
                    {
                        tmpa = tmpa * (beta + jb) / (als + 2 * i + jb);
                    }

                    tmpa = tmpa / (2 * i + 1.0) *
                           (2 * i * (beta + alpha) + beta - (rk - 1.0) * alpha)
                           / (beta + rk - 2 * i - 1.0);
                    sum += tmpa;

                    trm = trm * (rk - 2 * i - 1.0)
                          / (2 * i + 1.0) * (rk - 2 * i - 2.0) / (2 * i + 2.0);
                }

                if (k % 2 != 0)
                {
                    double tmpb = 1.0;
                    for (i = 1; i <= k - 1; i++)
                    {
                        tmpb = tmpb * (alpha + i) / (als + i);
                    }

                    sum += tmpb;
                }

                w[k - 1] = sum * w[0];
            }

            break;
        }

        case 5:
        {
            w[0] = typeMethods.r8_gamma(alpha + 1.0);

            for (k = 2; k <= m; k++)
            {
                rk       = k;
                w[k - 1] = (alpha + rk - 1.0) * w[k - 2];
            }

            break;
        }

        case 6:
        {
            w[0] = typeMethods.r8_gamma((alpha + 1.0) / 2.0);

            for (k = 3; k <= m; k += 2)
            {
                rk       = k;
                w[k - 1] = w[k - 3] * (alpha + rk - 2.0) / 2.0;
            }

            break;
        }

        case 7:
        {
            als = alpha;
            for (k = 1; k <= m; k += 2)
            {
                rk       = k;
                w[k - 1] = 2.0 / (rk + als);
            }

            break;
        }

        case 8:
        {
            w[0] = typeMethods.r8_gamma(alpha + 1.0)
                   * typeMethods.r8_gamma(-alpha - beta - 1.0)
                   / typeMethods.r8_gamma(-beta);

            for (k = 2; k <= m; k++)
            {
                rk       = k;
                w[k - 1] = -w[k - 2] * (alpha + rk - 1.0) / (alpha + beta + rk);
            }

            break;
        }

        case 9:
        {
            w[0] = Math.PI / 2.0;
            for (k = 3; k <= m; k += 2)
            {
                rk       = k;
                w[k - 1] = w[k - 3] * (rk - 2.0) / (rk + 1.0);
            }

            break;
        }
        }

        return(w);
    }
Ejemplo n.º 4
0
    public static double class_matrix(int kind, int m, double alpha, double beta, ref double[] aj,
                                      ref double[] bj)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CLASS_MATRIX computes the Jacobi matrix for a quadrature rule.
    //
    //  Discussion:
    //
    //    This routine computes the diagonal AJ and sub-diagonal BJ
    //    elements of the order M tridiagonal symmetric Jacobi matrix
    //    associated with the polynomials orthogonal with respect to
    //    the weight function specified by KIND.
    //
    //    For weight functions 1-7, M elements are defined in BJ even
    //    though only M-1 are needed.  For weight function 8, BJ(M) is
    //    set to zero.
    //
    //    The zero-th moment of the weight function is returned in ZEMU.
    //
    //  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 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,inf)     (x-a)^alpha*exp(-b*(x-a))
    //    6, Generalized Hermite,  (-inf,inf)  |x-a|^alpha*exp(-b*(x-a)^2)
    //    7, Exponential,          (a,b)       |x-(a+b)/2.0|^alpha
    //    8, Rational,             (a,inf)     (x-a)^alpha*(x+b)^beta
    //
    //    Input, int M, the order of the Jacobi matrix.
    //
    //    Input, double ALPHA, the value of Alpha, if needed.
    //
    //    Input, double BETA, the value of Beta, if needed.
    //
    //    Output, double AJ[M], BJ[M], the diagonal and subdiagonal
    //    of the Jacobi matrix.
    //
    //    Output, double CLASS_MATRIX, the zero-th moment.
    //
    {
        double ab;
        double abi;
        double abj;
        int    i;

        double zemu = 0;

        double temp = typeMethods.r8_epsilon();

        PARCHK.parchk(kind, 2 * m - 1, alpha, beta);

        const double temp2 = 0.5;

        if (500.0 * temp < Math.Abs(Math.Pow(Helpers.Gamma(temp2), 2) - Math.PI))
        {
            Console.WriteLine("");
            Console.WriteLine("CLASS_MATRIX - Fatal error!");
            Console.WriteLine("  Gamma function does not match machine parameters.");
            return(1);
        }

        switch (kind)
        {
        case 1:
        {
            ab = 0.0;

            zemu = 2.0 / (ab + 1.0);

            for (i = 0; i < m; i++)
            {
                aj[i] = 0.0;
            }

            for (i = 1; i <= m; i++)
            {
                abi       = i + ab * (i % 2);
                abj       = 2 * i + ab;
                bj[i - 1] = Math.Sqrt(abi * abi / (abj * abj - 1.0));
            }

            break;
        }

        case 2:
        {
            zemu = Math.PI;

            for (i = 0; i < m; i++)
            {
                aj[i] = 0.0;
            }

            bj[0] = Math.Sqrt(0.5);
            for (i = 1; i < m; i++)
            {
                bj[i] = 0.5;
            }

            break;
        }

        case 3:
        {
            ab   = alpha * 2.0;
            zemu = Math.Pow(2.0, ab + 1.0) * Math.Pow(Helpers.Gamma(alpha + 1.0), 2)
                   / Helpers.Gamma(ab + 2.0);

            for (i = 0; i < m; i++)
            {
                aj[i] = 0.0;
            }

            bj[0] = Math.Sqrt(1.0 / (2.0 * alpha + 3.0));
            for (i = 2; i <= m; i++)
            {
                bj[i - 1] = Math.Sqrt(i * (i + ab) / (4.0 * Math.Pow(i + alpha, 2) - 1.0));
            }

            break;
        }

        case 4:
        {
            ab   = alpha + beta;
            abi  = 2.0 + ab;
            zemu = Math.Pow(2.0, ab + 1.0) * Helpers.Gamma(alpha + 1.0)
                   * Helpers.Gamma(beta + 1.0) / Helpers.Gamma(abi);
            aj[0] = (beta - alpha) / abi;
            bj[0] = Math.Sqrt(4.0 * (1.0 + alpha) * (1.0 + beta)
                              / ((abi + 1.0) * abi * abi));
            double a2b2 = beta * beta - alpha * alpha;

            for (i = 2; i <= m; i++)
            {
                abi       = 2.0 * i + ab;
                aj[i - 1] = a2b2 / ((abi - 2.0) * abi);
                abi      *= abi;
                bj[i - 1] = Math.Sqrt(4.0 * i * (i + alpha) * (i + beta) * (i + ab)
                                      / ((abi - 1.0) * abi));
            }

            break;
        }

        case 5:
        {
            zemu = Helpers.Gamma(alpha + 1.0);

            for (i = 1; i <= m; i++)
            {
                aj[i - 1] = 2.0 * i - 1.0 + alpha;
                bj[i - 1] = Math.Sqrt(i * (i + alpha));
            }

            break;
        }

        case 6:
        {
            zemu = Helpers.Gamma((alpha + 1.0) / 2.0);

            for (i = 0; i < m; i++)
            {
                aj[i] = 0.0;
            }

            for (i = 1; i <= m; i++)
            {
                bj[i - 1] = Math.Sqrt((i + alpha * (i % 2)) / 2.0);
            }

            break;
        }

        case 7:
        {
            ab   = alpha;
            zemu = 2.0 / (ab + 1.0);

            for (i = 0; i < m; i++)
            {
                aj[i] = 0.0;
            }

            for (i = 1; i <= m; i++)
            {
                abi       = i + ab * (i % 2);
                abj       = 2 * i + ab;
                bj[i - 1] = Math.Sqrt(abi * abi / (abj * abj - 1.0));
            }

            break;
        }

        case 8:
        {
            ab   = alpha + beta;
            zemu = Helpers.Gamma(alpha + 1.0) * Helpers.Gamma(-(ab + 1.0))
                   / Helpers.Gamma(-beta);
            double apone = alpha + 1.0;
            double aba   = ab * apone;
            aj[0] = -apone / (ab + 2.0);
            bj[0] = -aj[0] * (beta + 1.0) / (ab + 2.0) / (ab + 3.0);
            double abti;
            for (i = 2; i <= m; i++)
            {
                abti      = ab + 2.0 * i;
                aj[i - 1] = aba + 2.0 * (ab + i) * (i - 1);
                aj[i - 1] = -aj[i - 1] / abti / (abti - 2.0);
            }

            for (i = 2; i <= m - 1; i++)
            {
                abti      = ab + 2.0 * i;
                bj[i - 1] = i * (alpha + i) / (abti - 1.0) * (beta + i)
                            / (abti * abti) * (ab + i) / (abti + 1.0);
            }

            bj[m - 1] = 0.0;
            for (i = 0; i < m; i++)
            {
                bj[i] = Math.Sqrt(bj[i]);
            }

            break;
        }

        case 9:
        {
            zemu = Math.PI / 2.0;

            for (i = 0; i < m; i++)
            {
                aj[i] = 0.0;
            }

            for (i = 0; i < m; i++)
            {
                bj[i] = 0.5;
            }

            break;
        }
        }

        return(zemu);
    }
Ejemplo n.º 5
0
    public static void chkqf(double[] t, double[] wts, int[] mlt, int nt, int nwts, int[] ndx,
                             int key, int mop, int mex, int kind, double alpha, double beta, int lo,
                             double a, double b)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    CHKQF computes and prints the moments of a quadrature formula.
    //
    //  Discussion:
    //
    //    The quadrature formula is based on a clasical weight function with
    //    any valid A, B.
    //
    //    No check can be made for non-classical weight functions.
    //
    //  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, double T[NT], the knots.
    //
    //    Input, double WTS[NWTS], the weights.
    //
    //    Input, int MLT[NT], the multiplicity of the knots.
    //
    //    Input, int NT, the number of knots.
    //
    //    Input, int NWTS, the number of weights.
    //
    //    Input, int NDX[NT], used to index the 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 MOP, the expected order of precision of the
    //    quadrature formula.
    //
    //    Input, int MEX, the number of moments required to be
    //    tested.  Set MEX = 1 and LO < 0 for no moments check.
    //
    //    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 to carry out.
    //     > 0, print weights and moment tests.
    //     = 0, print nothing. compute moment test.
    //     < 0, print weights only. don't compute moment tests.
    //
    //    Input, double A, B, the interval endpoints.
    //
    {
        double tmp = 0;

        double[] w = new double[mex];

        PARCHK.parchk(kind, mex, alpha, beta);

        if (lo != 0)
        {
            const int izero = 0;

            Console.WriteLine("");
            Console.WriteLine("  Interpolatory quadrature formula");
            Console.WriteLine("");
            Console.WriteLine("  Type  Interval       Weight function               Name");
            Console.WriteLine("");
            switch (kind)
            {
            case 1:
                Console.WriteLine("    1    (a,b)              1.0                    Legendre");
                break;

            case 2:
                Console.WriteLine("    2    (a,b)      ((b-x)*(x-a))^(-0.5)          Chebyshev Type 1");
                break;

            case 3:
                Console.WriteLine("    3    (a,b)      ((b-x)*(x-a))^alpha           Gegenbauer");
                break;

            case 4:
                Console.WriteLine("    4    (a,b)    (b-x)^alpha*(x-a)^beta          Jacobi");
                break;

            case 5:
                Console.WriteLine("    5   (a,+oo)  (x-a)^alpha*exp(-b*(x-a))      Gen Laguerre");
                break;

            case 6:
                Console.WriteLine("    6  (-oo,+oo) |x-a|^alpha*exp(-b*(x-a)^2)  Gen Hermite");
                break;

            case 7:
                Console.WriteLine("    7    (a,b)      |x-(a+b)/2.0|^alpha        Exponential");
                break;

            case 8:
                Console.WriteLine("    8   (a,+oo)    (x-a)^alpha*(x+b)^beta         Rational");
                break;

            case 9:
                Console.WriteLine("    9   (a,b)     (b-x)*(x-a)^(+0.5)         Chebyshev Type 2");
                break;
            }

            Console.WriteLine("");
            Console.WriteLine("     Parameters   A          " + a + "");
            Console.WriteLine("                  B          " + b + "");
            switch (kind)
            {
            case >= 3 and <= 8:
                Console.WriteLine("                  alpha      " + alpha + "");
                break;
            }

            switch (kind)
            {
            case 4:
            case 8:
                Console.WriteLine("                  beta       " + beta + "");
                break;
            }

            CHKQFS.chkqfs(t, wts, mlt, nt, nwts, ndx, key, ref w, mop, mex, izero,
                          alpha, beta, -Math.Abs(lo));
        }

        switch (lo)
        {
        case >= 0:
        {
            //
            //  Compute the moments in W.
            //
            w = SCMM.scmm(mex, kind, alpha, beta, a, b);

            switch (kind)
            {
            case 1:
            case 2:
            case 3:
            case 4:
            case 7:
            case 9:
                tmp = (b + a) / 2.0;
                break;

            case 5:
            case 6:
            case 8:
                tmp = a;
                break;
            }

            double[] t2 = new double[nt];

            int i;
            for (i = 0; i < nt; i++)
            {
                t2[i] = t[i] - tmp;
            }

            const int neg = -1;
            //
            //  Check moments.
            //
            CHKQFS.chkqfs(t2, wts, mlt, nt, nwts, ndx, key, ref w, mop, mex, neg, alpha, beta,
                          lo);
            break;
        }
        }
    }
Ejemplo n.º 6
0
    public static double[] wtfn(double[] t, int nt, int kind, double alpha, double beta)

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    WTFN evaluates the classical weight functions at given points.
    //
    //  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, double T[NT], the points where the weight function
    //    is to be evaluated.
    //
    //    Input, int NT, the number of evaluation points.
    //
    //    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.
    //
    //    Output, double WTFN[NT], the value of the weight function.
    //
    {
        int i;

        PARCHK.parchk(kind, 1, alpha, beta);

        double[] w = new double[nt];

        switch (kind)
        {
        case 1:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = 1.0;
            }

            break;
        }

        case 2:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = 1.0 / Math.Sqrt((1.0 - t[i]) * (1.0 + t[i]));
            }

            break;
        }

        case 3 when alpha == 0.0:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = 1.0;
            }

            break;
        }

        case 3:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = Math.Pow((1.0 - t[i]) * (1.0 + t[i]), alpha);
            }

            break;
        }

        case 4:
        {
            switch (alpha)
            {
            case 0.0:
            {
                for (i = 0; i < nt; i++)
                {
                    w[i] = 1.0;
                }

                break;
            }

            default:
            {
                for (i = 0; i < nt; i++)
                {
                    w[i] = Math.Pow(1.0 - t[i], alpha);
                }

                break;
            }
            }

            if (beta != 0.0)
            {
                for (i = 0; i < nt; i++)
                {
                    w[i] *= Math.Pow(1.0 + t[i], beta);
                }
            }

            break;
        }

        case 5 when alpha == 0.0:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = Math.Exp(-t[i]);
            }

            break;
        }

        case 5:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = Math.Exp(-t[i]) * Math.Pow(t[i], alpha);
            }

            break;
        }

        case 6 when alpha == 0.0:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = Math.Exp(-t[i] * t[i]);
            }

            break;
        }

        case 6:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = Math.Exp(-t[i] * t[i]) * Math.Pow(Math.Abs(t[i]), alpha);
            }

            break;
        }

        case 7 when alpha != 0.0:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = Math.Pow(Math.Abs(t[i]), alpha);
            }

            break;
        }

        case 7:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = 1.0;
            }

            break;
        }

        case 8:
        {
            switch (alpha)
            {
            case 0.0:
            {
                for (i = 0; i < nt; i++)
                {
                    w[i] = 1.0;
                }

                break;
            }

            default:
            {
                for (i = 0; i < nt; i++)
                {
                    w[i] = Math.Pow(t[i], alpha);
                }

                break;
            }
            }

            if (beta != 0.0)
            {
                for (i = 0; i < nt; i++)
                {
                    w[i] *= Math.Pow(1.0 + t[i], beta);
                }
            }

            break;
        }

        case 9:
        {
            for (i = 0; i < nt; i++)
            {
                w[i] = Math.Sqrt((1.0 - t[i]) * (1.0 + t[i]));
            }

            break;
        }
        }

        return(w);
    }