# include # include # include # include # include # include "asa109.hpp" using namespace std; int main ( ); void test01 ( ); void test02 ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // asa109_test() tests asa109(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 25 September 2014 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "asa109_test():\n"; cout << " C++ version\n"; cout << " Test asa109().\n"; test01 ( ); test02 ( ); // // Terminate. // cout << "\n"; cout << "asa109_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void test01 ( ) //****************************************************************************80 // // Purpose: // // test01() tests xinbta(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 28 April 2013 // // Author: // // John Burkardt // { double a; double b; double beta_log; double fx; int ifault; int n_data; double x; double x2; cout << "\n"; cout << "test01():\n"; cout << " xinbta() inverts the incomplete Beta function.\n"; cout << " Given CDF, it computes an X.\n"; cout << "\n"; cout << " A B CDF " << " X X\n"; cout << " " << " (Tabulated) (XINBTA) DIFF\n"; cout << "\n"; n_data = 0; for ( ; ; ) { beta_inc_values ( n_data, a, b, x, fx ); if ( n_data == 0 ) { break; } beta_log = lgamma ( a ) + lgamma ( b ) - lgamma ( a + b ); x2 = xinbta ( a, b, beta_log, fx, ifault ); cout << " " << setprecision(4) << setw(10) << a << " " << setprecision(4) << setw(10) << b << " " << setprecision(4) << setw(10) << fx << " " << setprecision(16) << setw(24) << x << " " << setprecision(16) << setw(24) << x2 << " " << setprecision(4) << setw(10) << fabs ( x - x2 ) << "\n"; } return; } //****************************************************************************80 void test02 ( ) //****************************************************************************80 // // Purpose: // // test02() tests beta_inc_values(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 25 September 2014 // // Author: // // John Burkardt // { double a; double b; double beta_log; double fx; double fx2; int ifault; int n_data; double x; cout << "\n"; cout << "test02():\n"; cout << " beta_inc_values() stores values of\n"; cout << " the incomplete Beta function.\n"; cout << "\n"; cout << " A B X BETA_INC(A,B)(X)\n"; cout << "\n"; n_data = 0; for ( ; ; ) { beta_inc_values ( n_data, a, b, x, fx ); if ( n_data == 0 ) { break; } beta_log = lgamma ( a ) + lgamma ( b ) - lgamma ( a + b ); ifault = 0; fx2 = betain ( x, a, b, beta_log, ifault ); cout << " " << setprecision(4) << setw(10) << a << " " << setprecision(4) << setw(10) << b << " " << setprecision(4) << setw(10) << x << " " << setprecision(16) << setw(24) << fx << " " << setprecision(16) << setw(24) << fx2 << " " << setprecision(4) << setw(10) << fabs ( fx - fx2 ) << "\n"; } return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // 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 ); cout << time_buffer << "\n"; return; # undef TIME_SIZE }