# include # include # include # include # include # include "test_int_nd.h" int main ( ); void test01 ( ); void test02 ( ); void test03 ( ); void test04 ( ); void test05 ( ); void test06 ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: test_int_nd_test() tests test_int_nd(). Licensing: This code is distributed under the MIT license. Modified: 02 June 2025 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "test_int_nd_test():\n" ); printf ( " C version\n" ); printf ( " Test test_int_nd().\n" ); test01 ( ); test02 ( ); test03 ( ); test04 ( ); test05 ( ); test06 ( ); /* Terminate. */ printf ( "\n" ); printf ( "test_int_nd_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 retrieves and prints the problem names. Licensing: This code is distributed under the MIT license. Modified: 02 June 2025 Author: John Burkardt */ { char *name; int problem; int problem_num; printf ( "\n" ); printf ( "TEST01()\n" ); printf ( " P00_NAME(#) returns the name for problem #.\n" ); printf ( "\n" ); printf ( " We use these two routines to print a directory\n" ); printf ( " of all the problems.\n" ); problem_num = get_problem_num ( ); printf ( "\n" ); printf ( " The number of problems available is %d\n", problem_num ); printf ( "\n" ); for ( problem = 1; problem <= problem_num; problem++ ) { name = p00_name ( problem ); printf ( " %8d \"%s\"\n", problem, name ); free ( name ); } return; } /******************************************************************************/ void test02 ( ) /******************************************************************************/ /* Purpose: TEST02 just prints out the title information. Licensing: This code is distributed under the MIT license. Modified: 02 June 2025 Author: John Burkardt */ { int problem; int problem_num; printf ( "\n" ); printf ( "TEST02()\n" ); printf ( " P00_TITLE(#) prints the title for problem #.\n" ); printf ( "\n" ); printf ( " We use these two routines to print a directory\n" ); printf ( " of all the problems.\n" ); problem_num = get_problem_num ( ); printf ( "\n" ); printf ( " The number of problems available is %d\n", problem_num ); printf ( "\n" ); for ( problem = 1; problem <= problem_num; problem++ ) { p00_title ( problem ); } return; } /******************************************************************************/ void test03 ( ) /******************************************************************************/ /* Purpose: TEST03 applies a composite midpoint rule to box regions. Licensing: This code is distributed under the MIT license. Modified: 02 June 2025 Author: John Burkardt */ { int dim_num; double error; double exact; int problem; int problem_num; char *region; double result; int sub_num; printf ( "\n" ); printf ( "TEST03\n" ); printf ( " Use a simple product rule on box regions.\n" ); printf ( " Use a fixed spatial dimension.\n" ); problem_num = get_problem_num ( ); dim_num = 3; printf ( "\n" ); printf ( " Prob Dim Subs Approx Exact Error\n" ); printf ( "\n" ); for ( problem = 1; problem <= problem_num; problem++ ) { /* Set data to default values. */ p00_default ( problem, dim_num ); region = p00_region ( problem ); if ( s_eqi ( region, "BOX" ) ) { for ( sub_num = 1; sub_num <= 5; sub_num = sub_num + 2 ) { result = p00_box_gl05 ( problem, dim_num, sub_num ); exact = p00_exact ( problem, dim_num ); if ( exact == HUGE_VAL ) { printf ( " %4d %4d %4d %12g ------------ ------------\n", problem, dim_num, sub_num, result ); } else { error = fabs ( result - exact ); printf ( " %4d %4d %4d %12g %12g %12g\n", problem, dim_num, sub_num, result, exact, error ); } } printf ( "\n" ); } free ( region ); } return; } /******************************************************************************/ void test04 ( ) /******************************************************************************/ /* Purpose: test04() applies a Monte Carlo rule to box regions. Licensing: This code is distributed under the MIT license. Modified: 02 June 2025 Author: John Burkardt */ { int dim_num; double error; double exact; int i; int point_num; int problem; int problem_num; char *region; double result; printf ( "\n" ); printf ( "test04()\n" ); printf ( " Use a Monte Carlo rule on box regions.\n" ); printf ( " Use a fixed spatial dimension.\n" ); printf ( "\n" ); printf ( " Repeatedly multiply the number of points by 16.\n" ); problem_num = get_problem_num ( ); printf ( "\n" ); printf ( " Prob Dim Points Approx Exact Error\n" ); printf ( "\n" ); dim_num = 3; for ( problem = 1; problem <= problem_num; problem++ ) { /* Set data to default values. */ p00_default ( problem, dim_num ); /* Get the region type. */ region = p00_region ( problem ); if ( s_eqi ( region, "BOX" ) ) { for ( i = 1; i <= 5; i++ ) { if ( i == 1 ) { point_num = 1; } else { point_num = 16 * point_num; } result = p00_box_mc ( problem, dim_num, point_num ); exact = p00_exact ( problem, dim_num ); if ( exact == HUGE_VAL ) { printf ( " %4d %4d %10d %12g ------------ ------------\n", problem, dim_num, point_num, result ); } else { error = fabs ( result - exact ); printf ( " %4d %4d %10d %12g %12g %12g\n", problem, dim_num, point_num, result, exact, error ); } } printf ( "\n" ); } free ( region ); } return; } /******************************************************************************/ void test05 ( ) /******************************************************************************/ /* Purpose: TEST05() demonstrates how a base point can be moved. Licensing: This code is distributed under the MIT license. Modified: 02 June 2025 Author: John Burkardt */ { # define DIM_NUM 2 # define TEST_NUM 5 int dim; double error; double exact; int i; int problem; int point_num; int problem_index[TEST_NUM] = { 16, 17, 18, 19, 31 }; double result; int run; int test; double z[DIM_NUM]; printf ( "\n" ); printf ( "TEST05\n" ); printf ( " Demonstrate problems that use a base point\n" ); printf ( " by moving the base point around.\n" ); printf ( " Use a Monte Carlo rule on box regions.\n" ); printf ( " Use a fixed spatial dimension.\n" ); for ( test = 0; test < TEST_NUM; test++ ) { problem = problem_index[test]; printf ( "\n" ); printf ( " Problem number = %d\n", problem ); p00_default ( problem, DIM_NUM ); for ( run = 1; run <= 3; run++ ) { p00_r8vec ( problem, 'R', 'Z', DIM_NUM, z ); printf ( "\n" ); printf ( " Run number %d\n", run ); printf ( " Basis point Z = " ); for ( dim = 0; dim < DIM_NUM; dim++ ) { printf ( " %12g", z[dim] ); } printf ( "\n" ); printf ( "\n" ); printf ( " Prob Dim Points Approx Exact Error\n" ); printf ( "\n" ); for ( i = 1; i <= 3; i++ ) { if ( i == 1 ) { point_num = 10; } else if ( i == 2 ) { point_num = 1000; } else if ( i == 3 ) { point_num = 100000; } result = p00_box_mc ( problem, DIM_NUM, point_num ); exact = p00_exact ( problem, DIM_NUM ); if ( exact == HUGE_VAL ) { printf ( " %4d %4d %10d %12g ------------ ------------\n", problem, DIM_NUM, point_num, result ); } else { error = fabs ( result - exact ); printf ( " %4d %4d %10d %12g %12g %12g\n", problem, DIM_NUM, point_num, result, exact, error ); } } printf ( "\n" ); } } return; # undef DIM_NUM # undef TEST_NUM } /******************************************************************************/ void test06 ( ) /******************************************************************************/ /* Purpose: TEST06 applies a composite midpoint rule for increasing spatial dimension. Licensing: This code is distributed under the MIT license. Modified: 02 June 2025 Author: John Burkardt */ { int calls; double error; double exact; int problem; int dim_num; double result; int sub_num; printf ( "\n" ); printf ( "TEST06\n" ); printf ( " Use a simple product rule on a box region.\n" ); printf ( " Use a fixed problem;\n" ); printf ( " Let the spatial dimension increase.\n" ); problem = 6; printf ( "\n" ); printf ( " Prob Dim Subs Approx Exact Error Calls\n" ); printf ( "\n" ); for ( dim_num = 1; dim_num <= 6; dim_num++ ) { p00_default ( problem, dim_num ); for ( sub_num = 1; sub_num <= 5; sub_num = sub_num + 2 ) { calls = 0; p00_i4 ( problem, 'S', '#', &calls ); result = p00_box_gl05 ( problem, dim_num, sub_num ); p00_i4 ( problem, 'G', '#', &calls ); exact = p00_exact ( problem, dim_num ); if ( exact == HUGE_VAL ) { printf ( " %4d %4d %4d %12g ------------ ------------\n", problem, dim_num, sub_num, result ); } else { error = fabs ( result - exact ); printf ( " %4d %4d %4d %12g %12g %12g\n", problem, dim_num, sub_num, result, exact, error ); } } printf ( "\n" ); } return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 01 May 2021 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }