# include # include # include # include # include "r8blt.h" int main ( ); void r8blt_det_test ( ); void r8blt_indicator_test ( ); void r8blt_mtv_test ( ); void r8blt_mv_test ( ); void r8blt_print_test ( ); void r8blt_print_some_test ( ); void r8blt_random_test ( ); void r8blt_sl_test ( ); void r8blt_slt_test ( ); void r8blt_to_r8ge_test ( ); void r8blt_zeros_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: r8blt_test() tests r8blt(). Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "r8blt_test():\n" ); printf ( " C version\n" ); printf ( " Test r8blt().\n" ); r8blt_det_test ( ); r8blt_indicator_test ( ); r8blt_mtv_test ( ); r8blt_mv_test ( ); r8blt_print_test ( ); r8blt_print_some_test ( ); r8blt_random_test ( ); r8blt_sl_test ( ); r8blt_slt_test ( ); r8blt_to_r8ge_test ( ); r8blt_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "r8blt():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8blt_det_test ( ) /******************************************************************************/ /* Purpose: R8BLT_DET_TEST tests R8BLT_DET. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a; double det; int seed = 123456789; printf ( "\n" ); printf ( "R8BLT_DET_TEST\n" ); printf ( " R8BLT_DET gets the determinant of an R8BLT matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a = r8blt_random ( N, ML, &seed ); r8blt_print ( N, ML, a, " The R8BLT matrix:" ); det = r8blt_det ( N, ML, a ); printf ( "\n" ); printf ( " Determinant = %g\n", det ); free ( a ); return; # undef ML # undef N } /******************************************************************************/ void r8blt_indicator_test ( ) /******************************************************************************/ /* Purpose: R8BLT_INDICATOR_TEST tests R8BLT_INDICATOR. Licensing: This code is distributed under the MIT license. Modified: 10 March 2013 Author: John Burkardt */ { double *a; int n = 6; int ml = 2; printf ( "\n" ); printf ( "R8BLT_INDICATOR_TEST\n" ); printf ( " R8BLT_INDICATOR sets up an R8BLT indicator matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Lower bandwidth ML = %d\n", ml ); a = r8blt_indicator ( n, ml ); r8blt_print ( n, ml, a, " The R8BLT indicator matrix:" ); free ( a ); return; } /******************************************************************************/ void r8blt_mtv_test ( ) /******************************************************************************/ /* Purpose: R8BLT_MTV_TEST tests R8BLT_MTV. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a; double *b; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8BLT_MTV_TEST\n" ); printf ( " R8BLT_MTV computes A'*x, where A is an R8BLT matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a = r8blt_random ( N, ML, &seed ); r8blt_print ( N, ML, a, " The R8BLT matrix:" ); /* Set X. */ x = r8vec_indicator1_new ( N ); r8vec_print ( N, x, " x:" ); /* Compute b=A'*x. */ b = r8blt_mtv ( N, ML, a, x ); r8vec_print ( N, b, " b = A'*x:" ); free ( a ); free ( b ); free ( x ); return; # undef ML # undef N } /******************************************************************************/ void r8blt_mv_test ( ) /******************************************************************************/ /* Purpose: R8BLT_MV_TEST tests R8BLT_MV. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a; double *b; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8BLT_MV_TEST\n" ); printf ( " R8BLT_MV computes A*x, where A is an R8BLT matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a = r8blt_random ( N, ML, &seed ); r8blt_print ( N, ML, a, " The R8BLT matrix:" ); /* Set X. */ x = r8vec_indicator1_new ( N ); r8vec_print ( N, x, " x:" ); /* Compute b=A*x. */ b = r8blt_mv ( N, ML, a, x ); r8vec_print ( N, b, " b = A*x:" ); free ( a ); free ( b ); free ( x ); return; # undef ML # undef N } /******************************************************************************/ void r8blt_print_test ( ) /******************************************************************************/ /* Purpose: R8BLT_PRINT_TEST tests R8BLT_PRINT. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { double *a; int n = 6; int ml = 2; printf ( "\n" ); printf ( "R8BLT_PRINT_TEST\n" ); printf ( " R8BLT_PRINT prints an R8BLT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Lower bandwidth ML = %d\n", ml ); a = r8blt_indicator ( n, ml ); r8blt_print ( n, ml, a, " The R8BLT matrix:" ); free ( a ); return; } /******************************************************************************/ void r8blt_print_some_test ( ) /******************************************************************************/ /* Purpose: R8BLT_PRINT_SOME_TEST tests R8BLT_PRINT_SOME. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { double *a; int n = 10; int ml = 3; printf ( "\n" ); printf ( "R8BLT_PRINT_SOME_TEST\n" ); printf ( " R8BLT_PRINT_SOME prints some of an R8BLT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Lower bandwidth ML = %d\n", ml ); a = r8blt_indicator ( n, ml ); r8blt_print_some ( n, ml, a, 1, 2, 4, 4, " Rows 1:4, Cols 2:4:" ); free ( a ); return; } /******************************************************************************/ void r8blt_random_test ( ) /******************************************************************************/ /* Purpose: R8BLT_RANDOM_TEST tests R8BLT_RANDOM. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a; int seed = 123456789; printf ( "\n" ); printf ( "R8BLT_RANDOM_TEST\n" ); printf ( " R8BLT_RANDOM randomizes an R8BLT matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a = r8blt_random ( N, ML, &seed ); r8blt_print ( N, ML, a, " The R8BLT matrix:" ); free ( a ); return; # undef ML # undef N } /******************************************************************************/ void r8blt_sl_test ( ) /******************************************************************************/ /* Purpose: R8BLT_SL_TEST tests R8BLT_SL. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a; double *b; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8BLT_SL_TEST\n" ); printf ( " R8BLT_SL solves A*x=b for an R8BLT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a = r8blt_random ( N, ML, &seed ); r8blt_print ( N, ML, a, " The R8BLT matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); r8vec_print ( N, x, " x:" ); /* Compute the corresponding right hand side. */ b = r8blt_mv ( N, ML, a, x ); r8vec_print ( N, b, " The right hand side:" ); /* Solve the linear system. */ free ( x ); x = r8blt_sl ( N, ML, a, b ); r8vec_print ( N, x, " Solution to A*x=b:" ); free ( a ); free ( b ); free ( x ); return; # undef ML # undef N } /******************************************************************************/ void r8blt_slt_test ( ) /******************************************************************************/ /* Purpose: R8BLT_SLT_TEST tests R8BLT_SLT. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a; double *b; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8BLT_SLT_TEST\n" ); printf ( " R8BLT_SLT solves A'*x=b, where A is an R8BLT matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a = r8blt_random ( N, ML, &seed ); r8blt_print ( N, ML, a, " The R8BLT matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); r8vec_print ( N, x, " x:" ); /* Compute the corresponding right hand side. */ b = r8blt_mtv ( N, ML, a, x ); r8vec_print ( N, b, " The right hand side:" ); /* Solve the linear system. */ free ( x ); x = r8blt_slt ( N, ML, a, b ); r8vec_print ( N, x, " Solution to A'*x=b:" ); free ( a ); free ( b ); free ( x ); return; # undef ML # undef N } /******************************************************************************/ void r8blt_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8BLT_TO_R8GE_TEST tests R8BLT_TO_R8GE. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a_r8blt; double *a_r8ge; int seed = 123456789; printf ( "\n" ); printf ( "R8BLT_TO_R8GE_TEST\n" ); printf ( " R8BLT_TO_R8GE converts a matrix from R8BLT to R8GE format;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a_r8blt = r8blt_random ( N, ML, &seed ); r8blt_print ( N, ML, a_r8blt, " The R8BLT matrix:" ); a_r8ge = r8blt_to_r8ge ( N, ML, a_r8blt ); r8ge_print ( N, N, a_r8ge, " The R8GE matrix:" ); free ( a_r8blt ); free ( a_r8ge ); return; # undef ML # undef N } /******************************************************************************/ void r8blt_zeros_test ( ) /******************************************************************************/ /* Purpose: R8BLT_ZEROS_TEST tests R8BLT_ZEROS. Licensing: This code is distributed under the MIT license. Modified: 04 October 2015 Author: John Burkardt */ { # define ML 3 # define N 10 double *a; printf ( "\n" ); printf ( "R8BLT_ZEROS_TEST\n" ); printf ( " R8BLT_ZEROS zeros an R8BLT matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); a = r8blt_zeros ( N, ML ); r8blt_print ( N, ML, a, " The R8BLT matrix:" ); free ( a ); return; # undef ML # undef N } /******************************************************************************/ 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 }