# include # include # include # include # include using namespace std; # include "r8utp.hpp" int main ( ); void r8ge_to_r8utp_test ( ); void r8utp_det_test ( ); void r8utp_indicator_test ( ); void r8utp_print_test ( ); void r8utp_print_some_test ( ); void r8utp_random_test ( ); void r8utp_size_test ( ); void r8utp_to_r8ge_test ( ); void r8utp_zeros_test ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // r8utp_test() tests r8utp(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "r8utp_test():\n"; cout << " C++ version\n"; cout << " Test r8utp().\n"; r8ge_to_r8utp_test ( ); r8utp_det_test ( ); r8utp_indicator_test ( ); r8utp_print_test ( ); r8utp_print_some_test ( ); r8utp_random_test ( ); r8utp_size_test ( ); r8utp_to_r8ge_test ( ); r8utp_zeros_test ( ); // // Terminate. // cout << "\n"; cout << "r8utp_test():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void r8ge_to_r8utp_test ( ) //****************************************************************************80 // // Purpose: // // r8ge_to_r8utp_test() tests r8ge_to_r8utp(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a_ge; double *a_ut; int i; int j; int k; int m = 5; int n = 4; cout << "\n"; cout << "r8ge_to_r8utp_test():\n"; cout << " r8ge_to_r8utp() converts an R8GE matrix to r8utp format.\n"; a_ge = new double [ m * n ]; k = 0; for ( j = 0; j < n; j++ ) { for ( i = 0; i < m; i++ ) { a_ge[k] = 10 * ( i + 1 ) + ( j + 1 ); k = k + 1; } } r8ge_print ( m, n, a_ge, " The random R8GE matrix:" ); a_ut = r8ge_to_r8utp ( m, n, a_ge ); r8utp_print ( m, n, a_ut, " The r8utp matrix" ); delete [] a_ge; delete [] a_ut; return; } //****************************************************************************80 void r8utp_det_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_det_test() tests r8utp_det(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a; double det; int i; int j; int k; int m = 5; int n = 5; cout << "\n"; cout << "r8utp_det_test():\n"; cout << " r8utp_det() computes the determinant of an r8utp matrix.\n"; a = r8utp_zeros ( m, n ); k = 0; for ( j = 0; j < n; j++ ) { for ( i = 0; i < i4_min ( j + 1, m ); i++ ) { a[k] = k + 1; k = k + 1; } } r8utp_print ( m, n, a, " The matrix A:" ); // // Compute the determinant. // det = r8utp_det ( m, n, a ); cout << "\n"; cout << " Determinant is " << det << "\n"; delete [] a; return; } //****************************************************************************80 void r8utp_indicator_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_indicator_test() tests r8utp_indicator(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a; int m = 5; int n = 4; cout << "\n"; cout << "r8utp_indicator_test()\n"; cout << " r8utp_indicator() sets up an indicator matrix in r8utp format.\n"; a = r8utp_indicator ( m, n ); r8utp_print ( m, n, a, " The matrix:" ); delete [] a; return; } //****************************************************************************80 void r8utp_print_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_print_test() tests r8utp_print(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a; int m = 6; int n = 4; cout << "\n"; cout << "r8utp_print_test()\n"; cout << " r8utp_print() prints an r8utp matrix.\n"; a = r8utp_indicator ( m, n ); r8utp_print ( m, n, a, " The matrix:" ); delete [] a; return; } //****************************************************************************80 void r8utp_print_some_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_print_some_test() tests r8utp_print_some(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a; int m = 4; int n = 6; cout << "\n"; cout << "r8utp_print_some_test()\n"; cout << " r8utp_print_some() prints some of an r8utp matrix.\n"; a = r8utp_indicator ( m, n ); r8utp_print_some ( m, n, a, 0, 3, 2, 5, " Some of the matrix:" ); delete [] a; return; } //****************************************************************************80 void r8utp_random_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_random_test() tests r8utp_random(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a; int m; int n; int seed; m = 5; n = 4; cout << "\n"; cout << "r8utp_random_test()\n"; cout << " r8utp_random() randomizes an r8utp matrix.\n"; cout << "\n"; cout << " Matrix order M = " << m << ", N = " << n << "\n"; seed = 123456789; srand48 ( seed ); a = r8utp_random ( m, n ); r8utp_print ( m, n, a, " Matrix A:" ); delete [] a; return; } //****************************************************************************80 void r8utp_size_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_size_test() tests r8utp_size(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { int i; int j; int k; int m; int mn; int mn2; int n; cout << "\n"; cout << "r8utp_size_test()\n"; cout << " r8utp_size() finds the storage needed for an r8utp matrix;\n"; cout << "\n"; cout << " M N Size Size(check)\n"; cout << "\n"; m = 4; for ( k = 1; k <= 3; k++ ) { if ( k == 1 ) { n = 3; } else if ( k == 2 ) { n = 4; } else { n = 6; } mn = r8utp_size ( m, n ); mn2 = 0; for ( j = 0; j < n; j++ ) { for ( i = 0; i < i4_min ( j + 1, m ); i++ ) { mn2 = mn2 + 1; } } cout << " " << setw(2) << m << " " << setw(2) << n << " " << setw(2) << mn << " " << setw(2) << mn2 << "\n"; } return; } //****************************************************************************80 void r8utp_to_r8ge_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_to_r8ge_test() tests r8utp_to_r8ge(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a_ge; double *a_ut; int m; int n; m = 5; n = 4; cout << "\n"; cout << "r8utp_to_r8ge_test()\n"; cout << " r8utp_to_r8ge() converts an r8utp matrix to R8GE format.\n"; a_ut = r8utp_random ( m, n ); r8utp_print ( m, n, a_ut, " r8utp matrix:" ); a_ge = r8utp_to_r8ge ( m, n, a_ut ); r8ge_print ( m, n, a_ge, " R8GE matrix" ); delete [] a_ge; delete [] a_ut; return; } //****************************************************************************80 void r8utp_zeros_test ( ) //****************************************************************************80 // // Purpose: // // r8utp_zeros_test() tests r8utp_zeros(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 16 August 2022 // // Author: // // John Burkardt // { double *a; int m = 5; int n = 4; cout << "\n"; cout << "r8utp_zeros_test()\n"; cout << " r8utp_zeros() returns a zeroed out r8utp matrix.\n"; cout << "\n"; cout << " Matrix order M = " << m << ", N = " << n << "\n"; a = r8utp_zeros ( m, n ); r8utp_print ( m, n, a, " Matrix A:" ); delete [] a; 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: // // 19 March 2018 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }