# include # include # include # include # include "r8cbb.h" int main ( ); void r8cbb_add_test ( ); void r8cbb_dif2_test ( ); void r8cbb_fa_test ( ); void r8cbb_get_test ( ); void r8cbb_indicator_test ( ); void r8cbb_mtv_test ( ); void r8cbb_mv_test ( ); void r8cbb_print_test ( ); void r8cbb_print_some_test ( ); void r8cbb_random_test ( ); void r8cbb_set_test ( ); void r8cbb_sl_test ( ); void r8cbb_to_r8ge_test ( ); void r8cbb_zeros_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: r8cbb_test() tests r8cbb(). Licensing: This code is distributed under the MIT license. Modified: 21 August 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "r8cbb_test():\n" ); printf ( " C version\n" ); printf ( " Test r8cbb().\n" ); r8cbb_add_test ( ); r8cbb_dif2_test ( ); r8cbb_fa_test ( ); r8cbb_get_test ( ); r8cbb_indicator_test ( ); r8cbb_mtv_test ( ); r8cbb_mv_test ( ); r8cbb_print_test ( ); r8cbb_print_some_test ( ); r8cbb_random_test ( ); r8cbb_set_test ( ); r8cbb_sl_test ( ); r8cbb_to_r8ge_test ( ); r8cbb_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "r8cbb_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8cbb_add_test ( ) /******************************************************************************/ /* Purpose: R8CBB_ADD_TEST tests R8CBB_ADD. Licensing: This code is distributed under the MIT license. Modified: 24 July 2016 Author: John Burkardt */ { double *a; int i; int j; int ml = 1; int mu = 0; int n1 = 3; int n2 = 2; double value; printf ( "\n" ); printf ( "R8CBB_ADD_TEST\n" ); printf ( " R8CBB_ADD adds a value to elements of an R8CBB matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); /* Initialize matrix to indicator matrix. */ a = r8cbb_indicator ( n1, n2, ml, mu ); /* Print initial matrix. */ r8cbb_print ( n1, n2, ml, mu, a, " Matrix before additions:" ); /* Add 100 to band diagonal. */ for ( i = 0; i < n1; i++ ) { j = i; value = 100.0; r8cbb_add ( n1, n2, ml, mu, a, i, j, value ); } /* Add 200 to right border. */ for ( i = 0; i < n1; i++ ) { for ( j = n1; j < n1 + n2; j++ ) { value = 200.0; r8cbb_add ( n1, n2, ml, mu, a, i, j, value ); } } /* Add 400 to offdiagonals in lower right dense matrix. */ for ( i = n1; i < n1 + n2; i++ ) { for ( j = n1; j < n1 + n2; j++ ) { if ( i != j ) { value = 400.0; r8cbb_add ( n1, n2, ml, mu, a, i, j, value ); } } } r8cbb_print ( n1, n2, ml, mu, a, " The R8BB matrix after additions:" ); free ( a ); return; } /******************************************************************************/ void r8cbb_dif2_test ( ) /******************************************************************************/ /* Purpose: R8CBB_DIF2_TEST tests R8CBB_DIF2. Licensing: This code is distributed under the MIT license. Modified: 24 July 2016 Author: John Burkardt */ { double *a; int ml = 1; int mu = 1; int n1 = 6; int n2 = 2; printf ( "\n" ); printf ( "R8CBB_DIF2_TEST\n" ); printf ( " R8CBB_DIF2 sets up an R8CBB second difference matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); a = r8cbb_dif2 ( n1, n2, ml, mu ); r8cbb_print ( n1, n2, ml, mu, a, " The R8CBB second difference matrix:" ); free ( a ); return; } /******************************************************************************/ void r8cbb_fa_test ( ) /******************************************************************************/ /* Purpose: R8CBB_FA_TEST tests R8CBB_FA. Licensing: This code is distributed under the MIT license. Modified: 17 March 2013 Author: John Burkardt */ { # define N1 8 # define N2 2 # define ML 1 # define MU 1 double *a; double *b; int info; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8CBB_FA_TEST\n" ); printf ( " R8CBB_FA factors an R8CBB matrix with no pivoting;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N1 + N2 ); printf ( " Matrix suborder N1 = %d\n", N1 ); printf ( " Matrix suborder N2 = %d\n", N2 ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8cbb_random ( N1, N2, ML, MU, &seed ); r8cbb_print ( N1, N2, ML, MU, a, " The R8CBB matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N1 + N2 ); /* Compute the corresponding right hand side. */ b = r8cbb_mv ( N1, N2, ML, MU, a, x ); /* Factor the matrix */ info = r8cbb_fa ( N1, N2, ML, MU, a ); r8cbb_print ( N1, N2, ML, MU, a, " The factored R8CBB matrix:" ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8CBB_FA_TEST - Fatal error!\n" ); printf ( " R8CBB_FA claims the matrix is singular.\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Solve the system. */ r8vec_print ( N1 + N2, b, " The right hand side vector b:" ); free ( x ); x = r8cbb_sl ( N1, N2, ML, MU, a, b ); r8vec_print ( N1 + N2, x, " Solution to A*x=b:" ); free ( a ); free ( b ); free ( x ); return; # undef ML # undef MU # undef N1 # undef N2 } /******************************************************************************/ void r8cbb_get_test ( ) /******************************************************************************/ /* Purpose: R8CBB_GET_TEST tests R8CBB_GET. Licensing: This code is distributed under the MIT license. Modified: 24 July 2016 Author: John Burkardt */ { double *a; int i; int j; int k; int ml = 1; int mu = 0; int n1 = 3; int n2 = 2; int seed; double value; printf ( "\n" ); printf ( "R8CBB_GET_TEST\n" ); printf ( " R8CBB_GET gets a value of an element of an R8CBB matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); /* Set matrix to indicator matrix. */ a = r8cbb_indicator ( n1, n2, ml, mu ); /* Print matrix. */ r8cbb_print ( n1, n2, ml, mu, a, " The R8CBB matrix to be queried:" ); /* Request random entries. */ seed = 123456789; printf ( "\n" ); for ( k = 0; k < 10; k++ ) { i = i4_uniform_ab ( 0, n1 + n2 - 1, &seed ); j = i4_uniform_ab ( 0, n1 + n2 - 1, &seed ); value = r8cbb_get ( n1, n2, ml, mu, a, i, j ); printf ( " A[%d,%d] = %g\n", i, j, value ); } free ( a ); return; } /******************************************************************************/ void r8cbb_indicator_test ( ) /******************************************************************************/ /* Purpose: R8CBB_INDICATOR_TEST tests R8CBB_INDICATOR. Licensing: This code is distributed under the MIT license. Modified: 18 March 2013 Author: John Burkardt */ { double *a; int ml = 1; int mu = 1; int n1 = 6; int n2 = 2; printf ( "\n" ); printf ( "R8CBB_INDICATOR_TEST\n" ); printf ( " R8CBB_INDICATOR sets up an R8CBB indicator matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); a = r8cbb_indicator ( n1, n2, ml, mu ); r8cbb_print ( n1, n2, ml, mu, a, " The R8CBB indicator matrix:" ); free ( a ); return; } /******************************************************************************/ void r8cbb_mtv_test ( ) /******************************************************************************/ /* Purpose: R8CBB_MTV_TEST tests R8CBB_MTV. Licensing: This code is distributed under the MIT license. Modified: 18 March 2013 Author: John Burkardt */ { double *a; double *b; int ml = 1; int mu = 1; int n; int n1 = 6; int n2 = 2; double *x; n = n1 + n2; printf ( "\n" ); printf ( "R8CBB_MTV_TEST\n" ); printf ( " R8CBB_MTV computes b=A'*x, where A is an R8CBB matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); a = r8cbb_indicator ( n1, n2, ml, mu ); r8cbb_print ( n1, n2, ml, mu, a, " The R8CBB indicator matrix:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector x:" ); b = r8cbb_mtv ( n1, n2, ml, mu, a, x ); r8vec_print ( n, b, " The product b=A'*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8cbb_mv_test ( ) /******************************************************************************/ /* Purpose: R8CBB_MV_TEST tests R8CBB_MV. Licensing: This code is distributed under the MIT license. Modified: 18 March 2013 Author: John Burkardt */ { double *a; double *b; int ml = 1; int mu = 1; int n; int n1 = 6; int n2 = 2; double *x; n = n1 + n2; printf ( "\n" ); printf ( "R8CBB_MV_TEST\n" ); printf ( " R8CBB_MV computes b=A*x, where A is an R8CBB matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); a = r8cbb_indicator ( n1, n2, ml, mu ); r8cbb_print ( n1, n2, ml, mu, a, " The R8CBB indicator matrix:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector x:" ); b = r8cbb_mv ( n1, n2, ml, mu, a, x ); r8vec_print ( n, b, " The product b=A*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8cbb_print_test ( ) /******************************************************************************/ /* Purpose: R8CBB_PRINT_TEST tests R8CBB_PRINT. Licensing: This code is distributed under the MIT license. Modified: 04 June 2016 Author: John Burkardt */ { double *a; int ml = 1; int mu = 1; int n1 = 8; int n2 = 2; int seed = 123456789; printf ( "\n" ); printf ( "R8CBB_PRINT_TEST\n" ); printf ( " R8CBB_PRINT prints an R8CBB matrix;\n" );; printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); /* Set the matrix. */ a = r8cbb_random ( n1, n2, ml, mu, &seed ); r8cbb_print ( n1, n2, ml, mu, a, " The R8CBB matrix:" ); free ( a ); return; } /******************************************************************************/ void r8cbb_print_some_test ( ) /******************************************************************************/ /* Purpose: R8CBB_PRINT_SOME_TEST tests R8CBB_PRINT_SOME. Licensing: This code is distributed under the MIT license. Modified: 24 July 2016 Author: John Burkardt */ { double *a; int ml = 1; int mu = 1; int n1 = 8; int n2 = 2; int seed = 123456789; printf ( "\n" ); printf ( "R8CBB_PRINT_SOME_TEST\n" ); printf ( " R8CBB_PRINT_SOME prints some of an R8CBB matrix;\n" );; printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); /* Set the matrix. */ a = r8cbb_random ( n1, n2, ml, mu, &seed ); r8cbb_print_some ( n1, n2, ml, mu, a, 0, 8, 9, 9, " Rows 0-9, Cols 8-9" ); free ( a ); return; } /******************************************************************************/ void r8cbb_random_test ( ) /******************************************************************************/ /* Purpose: R8CBB_RANDOM_TEST tests R8CBB_RANDOM. Licensing: This code is distributed under the MIT license. Modified: 03 June 2016 Author: John Burkardt */ { # define N1 8 # define N2 2 # define ML 1 # define MU 1 double *a; int seed = 123456789; printf ( "\n" ); printf ( "R8CBB_RANDOM_TEST\n" ); printf ( " R8CBB_RANDOM randomly generates an R8CBB matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N1 + N2 ); printf ( " Matrix suborder N1 = %d\n", N1 ); printf ( " Matrix suborder N2 = %d\n", N2 ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8cbb_random ( N1, N2, ML, MU, &seed ); r8cbb_print ( N1, N2, ML, MU, a, " The R8CBB matrix:" ); free ( a ); return; # undef ML # undef MU # undef N1 # undef N2 } /******************************************************************************/ void r8cbb_set_test ( ) /******************************************************************************/ /* Purpose: R8CBB_SET_TEST tests R8CBB_SET. Licensing: This code is distributed under the MIT license. Modified: 24 July 2016 Author: John Burkardt */ { double *a; int i; int j; int ml = 1; int mu = 0; int n1 = 3; int n2 = 2; double value; printf ( "\n" ); printf ( "R8CBB_SET_TEST\n" ); printf ( " R8CBB_SET sets the value of elements of an R8CBB matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); /* Initialize matrix to zero. */ a = r8cbb_zeros ( n1, n2, ml, mu ); /* A1: */ for ( i = 0; i < n1; i++ ) { for ( j = 0; j < n1; j++ ) { if ( i - ml <= j && j <= i + mu ) { value = ( double ) ( 10 * ( i + 1 ) + ( j + 1 ) ); r8cbb_set ( n1, n2, ml, mu, a, i, j, value ); } } } /* A2: */ for ( i = 0; i < n1; i++ ) { for ( j = n1; j < n1 + n2; j++ ) { value = ( double ) ( 10 * ( i + 1 ) + ( j + 1 ) ); r8cbb_set ( n1, n2, ml, mu, a, i, j, value ); } } /* A3 */ for ( i = n1; i < n1 + n2; i++ ) { for ( j = 0; j < n1; j++ ) { value = ( double ) ( 10 * ( i + 1 ) + ( j + 1 ) ); r8cbb_set ( n1, n2, ml, mu, a, i, j, value ); } } /* A4 */ for ( i = n1; i < n1 + n2; i++ ) { for ( j = n1; j < n1 + n2; j++ ) { value = ( double ) ( 10 * ( i + 1 ) + ( j + 1 ) ); r8cbb_set ( n1, n2, ml, mu, a, i, j, value ); } } r8cbb_print ( n1, n2, ml, mu, a, " The R8BB matrix:" ); free ( a ); return; } /******************************************************************************/ void r8cbb_sl_test ( ) /******************************************************************************/ /* Purpose: R8CBB_SL_TEST tests R8CBB_SL. Licensing: This code is distributed under the MIT license. Modified: 17 March 2013 Author: John Burkardt */ { # define N1 8 # define N2 2 # define ML 1 # define MU 1 double *a; double *b; int info; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8CBB_SL_TEST\n" ); printf ( " R8CBB_SL solves a linear system factored by R8CBB_FA.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N1 + N2 ); printf ( " Matrix suborder N1 = %d\n", N1 ); printf ( " Matrix suborder N2 = %d\n", N2 ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8cbb_random ( N1, N2, ML, MU, &seed ); r8cbb_print ( N1, N2, ML, MU, a, " The R8CBB matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N1 + N2 ); /* Compute the corresponding right hand side. */ b = r8cbb_mv ( N1, N2, ML, MU, a, x ); /* Factor the matrix */ info = r8cbb_fa ( N1, N2, ML, MU, a ); r8cbb_print ( N1, N2, ML, MU, a, " The factored R8CBB matrix:" ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8CBB_SL_TEST - Fatal error!\n" ); printf ( " R8CBB_FA claims the matrix is singular.\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Solve the system. */ r8vec_print ( N1 + N2, b, " The right hand side vector b:" ); free ( x ); x = r8cbb_sl ( N1, N2, ML, MU, a, b ); r8vec_print ( N1 + N2, x, " Solution to A*x=b:" ); free ( a ); free ( b ); free ( x ); return; # undef ML # undef MU # undef N1 # undef N2 } /******************************************************************************/ void r8cbb_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8CBB_TO_R8GE_TEST tests R8CBB_TO_R8GE. Licensing: This code is distributed under the MIT license. Modified: 24 July 2016 Author: John Burkardt */ { double *a; double *a_r8ge; int ml = 1; int mu = 1; int n1 = 6; int n2 = 2; printf ( "\n" ); printf ( "R8CBB_TO_R8GE_TEST\n" ); printf ( " R8CBB_TO_R8GE converts an R8CBB matrix to R8GE format.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n1 + n2 ); printf ( " Matrix suborder N1 = %d\n", n1 ); printf ( " Matrix suborder N2 = %d\n", n2 ); printf ( " Lower bandwidth ML = %d\n", ml ); printf ( " Upper bandwidth MU = %d\n", mu ); a = r8cbb_indicator ( n1, n2, ml, mu ); r8cbb_print ( n1, n2, ml, mu, a, " The R8CBB matrix:" ); a_r8ge = r8cbb_to_r8ge ( n1, n2, ml, mu, a ); r8ge_print ( n1 + n2, n1 + n2, a_r8ge, " The R8GE matrix:" ); free ( a ); free ( a_r8ge ); return; } /******************************************************************************/ void r8cbb_zeros_test ( ) /******************************************************************************/ /* Purpose: R8CBB_ZEROS_TEST tests R8CBB_ZEROS. Licensing: This code is distributed under the MIT license. Modified: 10 July 2016 Author: John Burkardt */ { # define N1 6 # define N2 2 # define ML 1 # define MU 1 double *a; printf ( "\n" ); printf ( "R8CBB_ZEROS_TEST\n" ); printf ( " R8CBB_ZEROS zeros an R8CBB matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N1 + N2 ); printf ( " Matrix suborder N1 = %d\n", N1 ); printf ( " Matrix suborder N2 = %d\n", N2 ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8cbb_zeros ( N1, N2, ML, MU ); r8cbb_print ( N1, N2, ML, MU, a, " The R8CBB zero matrix:" ); free ( a ); return; # undef ML # undef MU # undef N1 # undef N2 } /******************************************************************************/ 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 }