Beispiel #1
0
void test10 ( int nt, int kind, double alpha, double beta )

/******************************************************************************/
/*
  Purpose:

    TEST10 calls CDGQF to compute a quadrature formula.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    11 January 2010

  Author:

    John Burkardt
*/
{
  int i;
  double *t;
  double *wts;

  printf ( "\n" );
  printf ( "TEST10\n" );
  printf ( "  Call CDGQF to compute a quadrature formula.\n" );
  printf ( "\n" );
  printf ( "  KIND = %d\n", kind );
  printf ( "  ALPHA = %f\n", alpha );
  printf ( "  BETA  = %f\n", beta );

  t = ( double * ) malloc ( nt * sizeof ( double ) );
  wts = ( double * ) malloc ( nt * sizeof ( double ) );

  cdgqf ( nt, kind, alpha, beta, t, wts );

  printf ( "\n" );
  printf ( " Index     Abscissas                 Weights\n" );
  printf ( "\n" );
  for ( i = 0; i < nt; i++ )
  {
    printf ( "  %4d  %24.16g  %24.16g\n", i, t[i], wts[i] );
  }

  free ( t );
  free ( wts );

  return;
}
Beispiel #2
0
int main()
{
  int nt = 4;

  std::vector<double> nds(nt);
  std::vector<double> wts(nt);

  cdgqf ( nt, 1, 1., 1., &nds[0], &wts[0] );

  for( int k = 0; k < nt; k++ )
  {
    std::cout << "nd = " << std::setprecision(16) << nds[k] << "\t"
              << "wt = " << std::setprecision(16) << wts[k] << std::endl;
  }

  return 0;
}
Beispiel #3
0
void cgqf ( int nt, int kind, double alpha, double beta, double a, double b, 
  double t[], double wts[] )

/******************************************************************************/
/*
  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:

    17 September 2013

  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.

    Input, double A, B, the interval endpoints.

    Output, double T[NT], the knots.

    Output, double WTS[NT], the weights.
*/
{
  int i;
  int *mlt;
  int *ndx;
/*
  Compute the Gauss quadrature formula for default values of A and B.
*/
  cdgqf ( nt, kind, alpha, beta, t, wts );
/*
  Prepare to scale the quadrature formula to other weight function with 
  valid A and B.
*/
  mlt = ( int * ) malloc ( nt * sizeof ( int ) );
  for ( i = 0; i < nt; i++ )
  {
    mlt[i] = 1;
  }
  ndx = ( int * ) malloc ( nt * sizeof ( int ) );
  for ( i = 0; i < nt; i++ )
  {
    ndx[i] = i + 1;
  }
  scqf ( nt, t, mlt, wts, nt, ndx, wts, t, kind, alpha, beta, a, b );

  free ( mlt );
  free ( ndx );

  return;
}