int main ( int argc, char *argv[] )

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

    MAIN is the main program for CLENSHAW_CURTIS_RULE.

  Discussion:

    This program computes a standard Clenshaw Curtis quadrature rule
    and writes it to a file.

    The user specifies:
    * the ORDER (number of points) in the rule;
    * A, the left endpoint;
    * B, the right endpoint;
    * FILENAME, which defines the output filenames.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    01 October 2012

  Author:

    John Burkardt
*/
{
  double a;
  double b;
  char filename[255];
  int order;
  double *r;
  double *w;
  double *x;

  timestamp ( );
  printf ( "\n" );
  printf ( "CLENSHAW_CURTIS_RULE\n" );
  printf ( "  C version\n" );
  printf ( "\n" );
  printf ( "  Compute a Clenshaw Curtis rule for approximating\n" );
  printf ( "    Integral ( -1 <= x <= +1 ) f(x) dx\n" );
  printf ( "  of order ORDER.\n" );
  printf ( "\n" );
  printf ( "  The user specifies ORDER, A, B and FILENAME.\n" );
  printf ( "\n" );
  printf ( "  ORDER is the number of points.\n" );
  printf ( "  A is the left endpoint.\n" );
  printf ( "  B is the right endpoint.\n" );
  printf ( "  FILENAME is used to generate 3 files:\n" );
  printf ( "    filename_w.txt - the weight file\n" );
  printf ( "    filename_x.txt - the abscissa file.\n" );
  printf ( "    filename_r.txt - the region file.\n" );
/*
  Get ORDER.
*/
  if ( 1 < argc )
  {
    order = atoi ( argv[1] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  Enter the value of ORDER (1 or greater)\n" );
    scanf ( "%d", &order );
  }
/*
  Get A.
*/
  if ( 2 < argc )
  {
    a = atof ( argv[2] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  Enter the left endpoint A:\n" );
    scanf ( "%lf", &a );
  }
/*
  Get B.
*/
  if ( 3 < argc )
  {
    b = atof ( argv[3] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  Enter the right endpoint B:\n" );
    scanf ( "%lf", &b );
  }
/*
  Get FILENAME:
*/
  if ( 4 < argc )
  {
    strcpy ( filename, argv[4] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  Enter FILENAME, the \"root name\" of the quadrature files).\n" );
    scanf ( "%s", filename );
  }
/*
  Input summary.
*/
  printf ( "\n" );
  printf ( "  ORDER = %d\n", order );
  printf ( "  A = %g\n", a );
  printf ( "  B = %g\n", b );
  printf ( "  FILENAME = \"%s\".\n", filename );
/*
  Construct the rule.
*/
  r = ( double * ) malloc ( 2 * sizeof ( double ) );
  w = ( double * ) malloc ( order * sizeof ( double ) );
  x = ( double * ) malloc ( order * sizeof ( double ) );

  r[0] = a;
  r[1] = b;

  clenshaw_curtis_compute ( order, x, w );
/*
  Rescale the rule.
*/
  rescale ( a, b, order, x, w );
/*
  Output the rule.
*/
  rule_write ( order, filename, x, w, r );
/*
  Free memory.
*/
  free ( r );
  free ( w );
  free ( x );
/*
  Terminate.
*/
  printf ( "\n" );
  printf ( "CLENSHAW_CURTIS_RULE:\n" );
  printf ( "  Normal end of execution.\n" );
  printf ( "\n" );
  timestamp ( );

  return 0;
}
Ejemplo n.º 2
0
int main_old ( int argc, char *argv[] )
{
  double a;
  double alpha;
  double b;
  double beta;
  char filename[255];
  int kind;
  int order;
  double *r;
  double *w;
  double *x;

  printf ( "\n" );
  printf ( "legendre_rule\n" );
  printf ( "  c version\n" );
  printf ( "\n" );
  /*printf ( "  compiled on %s at %s.\n", __date__, __time__ );*/
  printf ( "\n" );
  printf ( "  compute a gauss-legendre rule for approximating\n" );
  printf ( "\n" );
  printf ( "    integral ( a <= x <= b ) f(x) dx\n" );
  printf ( "\n" );
  printf ( "  of order order.\n" );
  printf ( "\n" );
  printf ( "  the user specifies order, a, b and filename.\n" );
  printf ( "\n" );
  printf ( "  order is the number of points.\n" );
  printf ( "\n" );
  printf ( "  a is the left endpoint.\n" );
  printf ( "\n" );
  printf ( "  b is the right endpoint.\n" );
  printf ( "\n" );
  printf ( "  filename is used to generate 3 files:\n" );
  printf ( "\n" );
  printf ( "    filename_w.txt - the weight file\n" );
  printf ( "    filename_x.txt - the abscissa file.\n" );
  printf ( "    filename_r.txt - the region file.\n" );
/*
  initialize parameters;
*/
  alpha = 0.0;
  beta = 0.0;
/*
  get order.
*/
  if ( 1 < argc )
  {
    order = atoi ( argv[1] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  enter the value of order (1 or greater)\n" );
    scanf ( "%d", &order );
  }
/*
  get a.
*/
  if ( 2 < argc )
  {
    a = atof ( argv[2] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  enter the value of a:\n" );
    scanf ( "%lf", &a );
  }
/*
  get b.
*/
  if ( 3 < argc )
  {
    b = atof ( argv[3] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  enter the value of b:\n" );
    scanf ( "%lf", &b );
  }
/*
  get filename:
*/
  if ( 4 < argc )
  {
    strcpy ( filename, argv[4] );
  }
  else
  {
    printf ( "\n" );
    printf ( "  enter filename, the \"root name\" of the quadrature files).\n" );
    scanf ( "%s", filename );
  }
/*
  input summary.
*/
  printf ( "\n" );
  printf ( "  order = %d\n", order );
  printf ( "  a = %g\n", a );
  printf ( "  b = %g\n", b );
  printf ( "  filename = \"%s\".\n", filename );
/*
  construct the rule.
*/
  w = ( double * ) malloc ( order * sizeof ( double ) );
  x = ( double * ) malloc ( order * sizeof ( double ) );
  
  kind = 1;
  cgqf ( order, kind, alpha, beta, a, b, x, w );
/*
  write the rule.
*/
  r = ( double * ) malloc ( 2 * sizeof ( double ) );
  r[0] = a;
  r[1] = b;

  rule_write ( order, filename, x, w, r );
/*
  free memory.
*/
  free ( r );
  free ( w );
  free ( x );
/*
  terminate.
*/
  printf ( "\n" );
  printf ( "legendre_rule:\n" );
  printf ( "  normal end of execution.\n" );

  printf ( "\n" );

  return 0;
}