# include # include # include # include # include "r8ri.h" int main ( ); void r8ri_dif2_test ( ); void r8ri_indicator_test ( ); void r8ri_mtv_test ( ); void r8ri_mv_test ( ); void r8ri_print_test ( ); void r8ri_print_some_test ( ); void r8ri_random_test ( ); void r8ri_to_r8ge_test ( ); void r8ri_zeros_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: r8ri_test() tests r8ri(). Licensing: This code is distributed under the MIT license. Modified: 26 August 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "r8ri_test()\n" ); printf ( " C version\n" ); printf ( " Test r8ri().\n" ); r8ri_dif2_test ( ); r8ri_indicator_test ( ); r8ri_mtv_test ( ); r8ri_mv_test ( ); r8ri_print_test ( ); r8ri_print_some_test ( ); r8ri_random_test ( ); r8ri_to_r8ge_test ( ); r8ri_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "r8ri_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8ri_dif2_test ( ) /******************************************************************************/ /* Purpose: R8RI_DIF2_TEST tests R8RI_DIF2. Licensing: This code is distributed under the MIT license. Modified: 10 July 2016 Author: John Burkardt */ { double a[14]; int ija[14]; int n = 5; int nz = 14; printf ( "\n" ); printf ( "R8RI_DIF2_TEST\n" ); printf ( " R8RI_DIF2 sets up an R8RI indicator matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); r8ri_dif2 ( n, nz, ija, a ); r8ri_print ( n, nz, ija, a, " The R8RI second difference matrix:" ); return; } /******************************************************************************/ void r8ri_indicator_test ( ) /******************************************************************************/ /* Purpose: R8RI_INDICATOR_TEST tests R8RI_INDICATOR. Licensing: This code is distributed under the MIT license. Modified: 10 July 2016 Author: John Burkardt */ { double *a; int ija[11] = { 6, 7, 7, 9, 10, 11, 2, 1, 3, 4, 3 }; int n = 5; int nz = 11; printf ( "\n" ); printf ( "R8RI_INDICATOR_TEST\n" ); printf ( " R8RI_INDICATOR returns an R8RI indicator matrix\n" ); printf ( " for a given sparsity pattern.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); a = r8ri_indicator ( n, nz, ija ); r8ri_print ( n, nz, ija, a, " The R8RI matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ri_mtv_test ( ) /******************************************************************************/ /* Purpose: R8RI_MTV_TEST tests R8RI_MTV. Licensing: This code is distributed under the MIT license. Modified: 11 July 2016 Author: John Burkardt */ { double a[11] = { 3.0, 4.0, 5.0, 0.0, 8.0, 0.0, 1.0, 7.0, 9.0, 2.0, 6.0 }; double *b; int ija[11] = { 6, 7, 7, 9, 10, 11, 2, 1, 3, 4, 3 }; int n = 5; int nz = 11; double *x; printf ( "\n" ); printf ( "R8RI_MTV_TEST\n" ); printf ( " R8RI_MTV computes b=A'*x, where A is an R8RI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); r8ri_print ( n, nz, ija, a, " The R8RI matrix:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector x:" ); b = r8ri_mtv ( n, nz, ija, a, x ); r8vec_print ( n, b, " The product b=A'*x:" ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ri_mv_test ( ) /******************************************************************************/ /* Purpose: R8RI_MV_TEST tests R8RI_MV. Licensing: This code is distributed under the MIT license. Modified: 11 July 2016 Author: John Burkardt */ { double a[11] = { 3.0, 4.0, 5.0, 0.0, 8.0, 0.0, 1.0, 7.0, 9.0, 2.0, 6.0 }; double *b; int ija[11] = { 6, 7, 7, 9, 10, 11, 2, 1, 3, 4, 3 }; int n = 5; int nz = 11; double *x; printf ( "\n" ); printf ( "R8RI_MV_TEST\n" ); printf ( " R8RI_MV computes b=A*x, where A is an R8RI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); r8ri_print ( n, nz, ija, a, " The R8RI matrix:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector x:" ); b = r8ri_mv ( n, nz, ija, a, x ); r8vec_print ( n, b, " The product b=A*x:" ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ri_print_test ( ) /******************************************************************************/ /* Purpose: R8RI_PRINT_TEST tests R8RI_PRINT. Licensing: This code is distributed under the MIT license. Modified: 11 July 2016 Author: John Burkardt */ { double a[11] = { 3.0, 4.0, 5.0, 0.0, 8.0, 0.0, 1.0, 7.0, 9.0, 2.0, 6.0 }; int ija[11] = { 6, 7, 7, 9, 10, 11, 2, 1, 3, 4, 3 }; int n = 5; int nz = 11; printf ( "\n" ); printf ( "R8RI_PRINT_TEST\n" ); printf ( " R8RI_PRINT prints an R8RI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); r8ri_print ( n, nz, ija, a, " The R8RI matrix:" ); return; } /******************************************************************************/ void r8ri_print_some_test ( ) /******************************************************************************/ /* Purpose: R8RI_PRINT_SOME_TEST tests R8RI_PRINT_SOME. Licensing: This code is distributed under the MIT license. Modified: 11 July 2016 Author: John Burkardt */ { double a[34] = { 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 }; int ija[34] = { 10, 12, 15, 17, 20, 24, 27, 29, 32, 34, 1, 3, 0, 2, 4, 1, 5, 0, 4, 6, 1, 3, 5, 7, 2, 4, 8, 3, 7, 4, 6, 8, 5, 7 }; int n = 9; int nz = 34; printf ( "\n" ); printf ( "R8RI_PRINT_SOME_TEST\n" ); printf ( " R8RI_PRINT_SOME prints some of an R8RI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); r8ri_print_some ( n, nz, ija, a, 0, 3, 8, 5, " Rows(0-8), Cols(3-5):" ); return; } /******************************************************************************/ void r8ri_random_test ( ) /******************************************************************************/ /* Purpose: R8RI_RANDOM_TEST tests R8RI_RANDOM. Licensing: This code is distributed under the MIT license. Modified: 11 July 2016 Author: John Burkardt */ { double *a; int ija[11] = { 6, 7, 7, 9, 10, 11, 2, 1, 3, 4, 3 }; int n = 5; int nz = 11; int seed; printf ( "\n" ); printf ( "R8RI_RANDOM_TEST\n" ); printf ( " R8RI_RANDOM randomizes an R8RI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); seed = 123456789; a = r8ri_random ( n, nz, ija, &seed ); r8ri_print ( n, nz, ija, a, " The R8RI matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ri_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8RI_TO_R8GE_TEST tests R8RI_TO_R8GE. Licensing: This code is distributed under the MIT license. Modified: 11 July 2016 Author: John Burkardt */ { double *a; double *a_r8ge; int ija[11] = { 6, 7, 7, 9, 10, 11, 2, 1, 3, 4, 3 }; int n = 5; int nz = 11; printf ( "\n" ); printf ( "R8RI_TO_R8GE_TEST\n" ); printf ( " R8RI_TO_R8GE converts an R8RI matrix to R8GE format.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); a = r8ri_indicator ( n, nz, ija ); r8ri_print ( n, nz, ija, a, " The R8RI matrix:" ); a_r8ge = r8ri_to_r8ge ( n, nz, ija, a ); r8ge_print ( n, n, a_r8ge, " The R8GE matrix:" ); free ( a ); free ( a_r8ge ); return; } /******************************************************************************/ void r8ri_zeros_test ( ) /******************************************************************************/ /* Purpose: R8RI_ZEROS_TEST tests R8RI_ZEROS. Licensing: This code is distributed under the MIT license. Modified: 11 July 2016 Author: John Burkardt */ { double *a; int ija[11] = { 6, 7, 7, 9, 10, 11, 2, 1, 3, 4, 3 }; int n = 5; int nz = 11; printf ( "\n" ); printf ( "R8RI_ZEROS_TEST\n" ); printf ( " R8RI_ZEROS zeros an R8RI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Storage NZ = %d\n", nz ); a = r8ri_zeros ( n, nz, ija ); r8ri_print ( n, nz, ija, a, " The R8RI matrix:" ); free ( a ); 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 ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }