# include # include # include # include # include "r8utp.h" 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 ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: r8utp_test() tests r8utp(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "r8utp_test():\n" ); printf ( " C version\n" ); printf ( " 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. */ printf ( "\n" ); printf ( "r8utp_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8ge_to_r8utp_test ( ) /******************************************************************************/ /* Purpose: r8ge_to_r8utp_test() tests r8ge_to_r8utp(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a_ge; double *a_ut; int i; int j; int k; int m = 5; int n = 4; printf ( "\n" ); printf ( "r8ge_to_r8utp_test():\n" ); printf ( " r8ge_to_r8utp() converts an R8GE matrix to r8utp format.\n" ); a_ge = ( double * ) malloc ( m * n * sizeof ( double ) ); 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" ); free ( a_ge ); free ( a_ut ); return; } /******************************************************************************/ void r8utp_det_test ( ) /******************************************************************************/ /* Purpose: r8utp_det_test() tests r8utp_det(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a; double det; int i; int j; int k; int m = 5; int n = 5; printf ( "\n" ); printf ( "r8utp_det_test():\n" ); printf ( " 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 ); printf ( "\n" ); printf ( " Determinant is %g\n", det ); free ( a ); return; } /******************************************************************************/ void r8utp_indicator_test ( ) /******************************************************************************/ /* Purpose: r8utp_indicator_test() tests r8utp_indicator(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a; int m = 5; int n = 4; printf ( "\n" ); printf ( "r8utp_indicator_test()\n" ); printf ( " r8utp_indicator() sets up an indicator matrix in r8utp format.\n" ); a = r8utp_indicator ( m, n ); r8utp_print ( m, n, a, " The matrix:" ); free ( a ); return; } /******************************************************************************/ void r8utp_print_test ( ) /******************************************************************************/ /* Purpose: r8utp_print_test() tests r8utp_print(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a; int m = 6; int n = 4; printf ( "\n" ); printf ( "r8utp_print_test()\n" ); printf ( " r8utp_print() prints an r8utp matrix.\n" ); a = r8utp_indicator ( m, n ); r8utp_print ( m, n, a, " The matrix:" ); free ( a ); return; } /******************************************************************************/ void r8utp_print_some_test ( ) /******************************************************************************/ /* Purpose: r8utp_print_some_test() tests r8utp_print_some(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a; int m = 4; int n = 6; printf ( "\n" ); printf ( "r8utp_print_some_test()\n" ); printf ( " 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:" ); free ( a ); return; } /******************************************************************************/ void r8utp_random_test ( ) /******************************************************************************/ /* Purpose: r8utp_random_test() tests r8utp_random(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a; int m; int n; int seed; m = 5; n = 4; printf ( "\n" ); printf ( "r8utp_random_test()\n" ); printf ( " r8utp_random() randomizes an r8utp matrix.\n" ); printf ( "\n" ); printf ( " Matrix order M, N = %d, %d\n", m, n ); seed = 123456789; srand48 ( seed ); a = r8utp_random ( m, n ); r8utp_print ( m, n, a, " Matrix A:" ); free ( a ); return; } /******************************************************************************/ void r8utp_size_test ( ) /******************************************************************************/ /* Purpose: r8utp_size_test() tests r8utp_size(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { int i; int j; int k; int m; int mn; int mn2; int n; printf ( "\n" ); printf ( "r8utp_size_test()\n" ); printf ( " r8utp_size() finds the storage needed for an r8utp matrix;\n" ); printf ( "\n" ); printf ( " M N Size Size(check)\n" ); printf ( "\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; } } printf ( " %2d %2d %2d %2d\n", m, n, mn, mn2 ); } return; } /******************************************************************************/ void r8utp_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: r8utp_to_r8ge_test() tests r8utp_to_r8ge(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a_ge; double *a_ut; int m; int n; m = 5; n = 4; printf ( "\n" ); printf ( "r8utp_to_r8ge_test()\n" ); printf ( " 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" ); free ( a_ge ); free ( a_ut ); return; } /******************************************************************************/ void r8utp_zeros_test ( ) /******************************************************************************/ /* Purpose: r8utp_zeros_test() tests r8utp_zeros(). Licensing: This code is distributed under the MIT license. Modified: 15 August 2022 Author: John Burkardt */ { double *a; int m = 5; int n = 4; printf ( "\n" ); printf ( "r8utp_zeros_test()\n" ); printf ( " r8utp_zeros() returns a zeroed out r8utp matrix.\n" ); printf ( "\n" ); printf ( " Matrix order M, N = %d, %d\n", m, n ); a = r8utp_zeros ( m, n ); r8utp_print ( m, n, a, " Matrix A:" ); free ( a ); 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 }