# include # include # include # include # include # include "asa091.hpp" using namespace std; int main ( ); void test01 ( ); void test02 ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // asa091_test() tests asa091(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "asa091_test():\n"; cout << " C++ version\n"; cout << " Test asa091().\n"; test01 ( ); test02 ( ); // // Terminate. // cout << "\n"; cout << "asa091_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void test01 ( ) //****************************************************************************80 // // Purpose: // // test01() tests ppchi2(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 05 February 2008 // // Author: // // John Burkardt // { double g; int ifault; double p; double v; double value; double value_correct = 0.4; p = 0.017523; v = 4.0; cout << "\n"; cout << "test01():\n"; cout << " Perform a simple sample calculation using\n"; cout << " ppchi2() to invert the Chi-Squared CDF.\n"; g = lgamma ( v / 2.0 ); cout << "\n"; cout << " P = " << setw(24) << setprecision(16) << p << "\n"; cout << " V = " << setw(24) << setprecision(16) << v << "\n"; cout << " G Log(Gamma(V/2)) = " << setw(24) << setprecision(16) << g << "\n"; value = ppchi2 ( p, v, g, &ifault ); cout << " VALUE = " << setw(24) << setprecision(16) << value << "\n"; cout << " VALUE (correct) = " << setw(24) << setprecision(16) << value_correct << "\n"; cout << "\n"; cout << " Error flag IFAULT = " << ifault << "\n"; return; } //****************************************************************************80 void test02 ( ) //****************************************************************************80 // // Purpose: // // test02() tests ppchi2(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 05 February 2008 // // Author: // // John Burkardt // { int a; double fx; double g; int ifault; int n_data; double v; double x; double x2; cout << "\n"; cout << "test02():\n"; cout << " ppchi2() computes percentage points of the Chi-Square CDF.\n"; cout << " Compare to tabulated values.\n"; cout << "\n"; cout << " N CDF X " << " X2 DIFF\n"; cout << " (tabulated) " << "(PPCHI2)\n"; cout << "\n"; n_data = 0; for ( ; ; ) { chi_square_cdf_values ( &n_data, &a, &x, &fx ); if ( n_data == 0 ) { break; } v = ( double ) ( a ); g = lgamma ( v / 2.0 ); x2 = ppchi2 ( fx, v, g, &ifault ); cout << " " << setprecision(4) << setw(10) << a << " " << 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 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 }