void test01 ( )

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

    TEST01 tests P00_PROBLEM_NUM and P00_TITLE.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    11 September 2012

  Author:

    John Burkardt
*/
{
  int problem;
  int problem_num;
  char *title;

  printf ( "\n" );
  printf ( "TEST01\n" );
  printf ( "  P00_PROBLEM_NUM returns the number of problems.\n" );
  printf ( "  P00_TITLE returns the title of a problem.\n" );

  problem_num = p00_problem_num ( );

  printf ( "\n" );
  printf ( "  P00_PROBLEM_NUM: number of problems is %d\n", problem_num );
  printf ( "\n" );
  printf ( "   Problem       Title\n" );
  printf ( "\n" );

  for ( problem = 1; problem <= problem_num; problem++ )
  {
    title = p00_title ( problem );

    printf ( "  %8d  \"%s\".\n", problem, title );

    free ( title );
  }

  return;
}
void test01 ( void )

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

    TEST01 simply prints the title of each problem.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    17 February 2012

  Author:

    John Burkardt
*/
{
  int problem_num;
  int problem;
  char title[100];

  printf ( "\n" );
  printf ( "TEST01\n" );
  printf ( "  For each problem, print the title.\n" );
/*
  Get the number of problems.
*/
  problem_num = p00_problem_num ( );

  printf ( "\n" );
  printf ( "  Problem    Title\n" );
  printf ( "\n" );

  for ( problem = 1; problem <= problem_num; problem++ )
  {
    p00_title ( problem, title );

    printf ( "  %6d  %s\n", problem, title );
  }

  return;
}
void test01 ( )

//****************************************************************************80
//
//  Purpose:
//
//    TEST01 simply prints the title of each function.
//
//  Licensing:
//
//    This code is distributed under the GNU LGPL license.
//
//  Modified:
//
//    28 August 2012
//
//  Author:
//
//    John Burkardt
//
{
  int prob;
  int prob_num;
  char *title;

  printf ( "\n" );
  printf ( "TEST01\n" );
  printf ( "  Print the title of each function.\n" );

  prob_num = p00_prob_num ( );
  
  printf ( "\n" );
  printf ( "  There are %d functions available:\n", prob_num );
  printf ( "  Index  Title\n" );
  printf ( "\n" );

  for ( prob = 1; prob <= prob_num; prob++ )
  {
    title = p00_title ( prob );
    printf ( "  %2d  %s\n", prob, title );
    free ( title );
  }
  return;
}
void test02 ( void )

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

    TEST02 evaluates the objective function at each starting point.

  Licensing:

    This code is distributed under the GNU LGPL license. 

  Modified:

    17 February 2012

  Author:

    John Burkardt
*/
{
  double *a;
  double *b;
  double *f;
  double *fs;
  int i;
  int know;
  int m;
  int n = 100000;
  int problem;
  int problem_num;
  int seed;
  char title[100];
  double *x;
  double *xs;

  printf ( "\n" );
  printf ( "TEST02\n" );
  printf ( "  For each problem, evaluate the function at many points.\n" );
  printf ( "  Number of sample points = %d\n", n );
/*
  Get the number of problems.
*/
  problem_num = p00_problem_num ( );

  for ( problem = 1; problem <= problem_num; problem++ )
  {
    printf ( "\n" );
    printf ( "  Problem %d\n", problem );

    p00_title ( problem, title );

    printf ( "  %s\n", title );

    m = p00_m ( problem );

    printf ( "  M =     %d\n", m );

    a = ( double * ) malloc ( m * sizeof ( double ) );
    b = ( double * ) malloc ( m * sizeof ( double ) );
 
    p00_ab ( problem, m, a, b );

    printf ( "\n" );
    printf ( "    I      A(i)      B(i)\n" );
    printf ( "\n" );

    for ( i = 0; i < m; i++ )
    {
      printf ( "  %4d  %10g  %10g\n", i, a[i], b[i] );
    }

    seed = 123456789;
    x = r8col_uniform_new ( m, n, a, b, &seed );
    f = p00_f ( problem, m, n, x );

    printf ( "\n" );
    printf ( "  Max(F) = %g\n", r8vec_max ( n, f ) );
    printf ( "  Min(F) = %g\n", r8vec_min ( n, f ) );

    know = 0;
    xs = p00_sol ( problem, m, &know );
    if ( know != 0 )
    {
      fs = p00_f ( problem, m, 1, xs );
      printf ( "  F(X*)  = %g\n", fs[0] );
      free ( fs );
      free ( xs );
    }
    else
    {
      printf ( "  X* is not given.\n" );
    }

    free ( a );
    free ( b );
    free ( f );
    free ( x );
  }
  return;
}
Exemple #5
0
void test06 ( void )

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

    TEST06 carries out a version of Brent's derivative-free minimizer.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    03 February 2012

  Author:

    John Burkardt
*/
{
  double a;
  double b;
  double fa;
  double fb;
  double fx;
  int problem_num;
  int problem;
  char title[50];
  double tol = 0.000001;
  double x;

  printf ( "\n" );
  printf ( "TEST06\n" );
  printf ( "  For each problem, use Brent's method.\n" );
/*
  Get the number of problems.
*/
  problem_num = p00_problem_num ( );

  for ( problem = 1; problem <= problem_num; problem++ )
  {
    p00_title ( problem, title );

    printf ( "\n" );
    printf ( "  Problem %d\n", problem );
    printf ( "  %s\n", title );

    p00_interval ( problem, &a, &b );

    fa = p00_f ( problem, a );
    fb = p00_f ( problem, b );

    printf ( "\n" );
    printf ( "  Initial interval [A,B]:\n" );
    printf ( "\n" );
    printf ( "   A,       B:  %16g                      %16g\n", a, b );
    printf ( "  FA,      FB:  %16g                      %16g\n", fa, fb );

    x = p00_fmin ( &a, &b, problem, tol );

    fa = p00_f ( problem, a );
    fb = p00_f ( problem, b );
    fx = p00_f ( problem, x );

    printf ( "\n" );
    printf ( "  Final interval [A,X*,B]:\n" );
    printf ( "\n" );
    printf ( "   A,  X*,  B:  %16g  %16g  %16g\n", a, x, b );
    printf ( "  FA, FX*, FB:  %16g  %16g  %16g\n", fa, fx, fb );
  }

  return;
}
Exemple #6
0
void test05 ( void )

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

    TEST05 carries out a simple bisection method.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    03 February 2012

  Author:

    John Burkardt
*/
{
  double a;
  double b;
  double c;
  double d;
  double e;
  double fa;
  double fb;
  double fc;
  double fd;
  double fe;
  int i;
  int max_step = 10;
  int problem_num;
  int problem;
  char title[50];

  printf ( "\n" );
  printf ( "TEST05\n" );
  printf ( "  For each problem, take a few steps of \n" );
  printf ( "  the bisection method.\n" );
/*
  Get the number of problems.
*/
  problem_num = p00_problem_num ( );

  for ( problem = 1; problem <= problem_num; problem++ )
  {
    p00_title ( problem, title );

    printf ( "\n" );
    printf ( "  Problem %d\n", problem );
    printf ( "  %s\n", title );

    p00_interval ( problem, &a, &c );
    b = 0.5 * ( a + c );
    fa = p00_f ( problem, a );
    fc = p00_f ( problem, c );
    fb = p00_f ( problem, b );

    i = 0;
    printf ( "\n" );
    printf ( "  %d\n", i );
    printf ( "  X:  %10g  %10g  %10g\n", a, b, c );
    printf ( "  F:  %10g  %10g  %10g\n", fa, fb, fc );

    for ( i = 1; i <= max_step; i++ )
    {
      d = 0.5 * ( a + b );
      fd = p00_f ( problem, d );

      e = 0.5 * ( b + c );
      fe = p00_f ( problem, e );

      if ( fd <= fb )
      {
        c = b;
        fc = fb;
        b = d;
        fb = fd;
      }
      else if ( fe <= fb )
      {
        a = b;
        fa = fb;
        b = e;
        fb = fe;
      }
      else
      {
        a = d;
        fa = fd;
        c = e;
        fc = fe;
      }
    printf ( "  %d\n", i );
    printf ( "  X:  %10g  %10g  %10g\n", a, b, c );
    printf ( "  F:  %10g  %10g  %10g\n", fa, fb, fc );
    }
  }

  return;
}
Exemple #7
0
void test04 ( void )

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

    TEST04 compares the exact and approximate second derivatives.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    03 February 2012

  Author:

    John Burkardt
*/
{
  double f2;
  double f2_dif;
  int problem_num;
  int problem;
  char title[50];
  double x;

  printf ( "\n" );
  printf ( "TEST04\n" );
  printf ( "  For each problem, compare the exact and\n" );
  printf ( "  approximate second derivatives at the starting point.\n" );
/*
  Get the number of problems.
*/
  problem_num = p00_problem_num ( );

  for ( problem = 1; problem <= problem_num; problem++ )
  {
    p00_title ( problem, title );

    printf ( "\n" );
    printf ( "  Problem %d\n", problem );
    printf ( "  %s\n", title );

    x = p00_start ( problem );

    printf ( "\n" );
    printf ( "  X:\n" );
    printf ( "  %g\n", x );

    f2 = p00_f2 ( problem, x );

    printf ( "  F\"(X) (exact):\n" );
    printf ( "  %g\n", f2 );

    f2_dif = p00_f2_dif ( problem, x );

    printf ( "  F\"(X) (difference):\n" );
    printf ( "  %g\n", f2_dif );
  }

  return;
}
Exemple #8
0
void test02 ( void )

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

    TEST02 evaluates the objective function at each starting point.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    03 February 2012

  Author:

    John Burkardt
*/
{
  double f_sol;
  double f_start;
  int know;
  int problem_num;
  int problem;
  char title[50];
  double x;

  printf ( "\n" );
  printf ( "TEST02\n" );
  printf ( "  For each problem, evaluate the function\n" );
  printf ( "  at the starting point and the solution.\n" );
/*
  Get the number of problems.
*/
  problem_num = p00_problem_num ( );

  for ( problem = 1; problem <= problem_num; problem++ )
  {
    p00_title ( problem, title );

    printf ( "\n" );
    printf ( "  Problem %d\n", problem );
    printf ( "  %s\n", title );
    printf ( "\n" );

    x = p00_start ( problem );

    f_start = p00_f ( problem, x );

    printf ( "    F(X_START) = %g\n", f_start );

    p00_sol ( problem, &know, &x );

    if ( 0 < know )
    {
      f_sol = p00_f ( problem, x );
      printf ( "    F(X_SOL) = %g\n", f_sol );
    }
  }

  return;
}