# include # include # include # include # include "triangle01_integrals.h" int main ( ); void test01 ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: triangle01_integrals_test() tests triangle01_integrals(). Licensing: This code is distributed under the MIT license. Modified: 14 January 2014 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "TRIANGLE01_INTEGRALS_TEST():\n" ); printf ( " C version\n" ); printf ( " Test TRIANGLE01_INTEGRALS().\n" ); test01 ( ); /* Terminate. */ printf ( "\n" ); printf ( "TRIANGLE01_INTEGRALS_TEST():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void test01 ( ) /******************************************************************************/ /* Purpose: TEST01 uses TRIANGLE01_SAMPLE to compare exact and estimated monomial integrals. Licensing: This code is distributed under the MIT license. Modified: 14 January 2014 Author: John Burkardt */ { int e[2]; double error; double exact; int i; int j; int m = 2; int n = 4192; double result; int seed; double *value; double *x; printf ( "\n" ); printf ( "TEST01\n" ); printf ( " Estimate monomial integrals using Monte Carlo\n" ); printf ( " over the interior of the unit triangle in 2D.\n" ); /* Get sample points. */ seed = 123456789; x = triangle01_sample ( n, &seed ); printf ( "\n" ); printf ( " Number of sample points used is %d\n", n ); /* Randomly choose X, Y exponents. */ printf ( "\n" ); printf ( " We will restrict this test to randomly chosen even exponents.\n" ); printf ( "\n" ); printf ( " Ex Ey MC-Estimate Exact Error\n" ); printf ( "\n" ); for ( i = 0; i <= 4; i++ ) { e[0] = i; for ( j = 0; j <= 4; j++ ) { e[1] = j; value = monomial_value ( m, n, e, x ); result = triangle01_area ( ) * r8vec_sum ( n, value ) / ( double ) ( n ); exact = triangle01_monomial_integral ( e ); error = fabs ( result - exact ); printf ( " %2d %2d %14.6g %14.6g %10.2e\n", e[0], e[1], result, exact, error ); free ( value ); } } free ( x ); return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: TIMESTAMP prints the current YMDHMS date as a time stamp. Example: 31 May 2001 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 24 September 2003 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 ); fprintf ( stdout, "%s\n", time_buffer ); return; # undef TIME_SIZE }