# include # include # include # include # include "r8gb.h" int main ( ); void r8gb_det_test ( ); void r8gb_dif2_test ( ); void r8gb_fa_test ( ); void r8gb_indicator_test ( ); void r8gb_ml_test ( ); void r8gb_mtv_test ( ); void r8gb_mu_test ( ); void r8gb_mv_test ( ); void r8gb_nz_num_test ( ); void r8gb_print_test ( ); void r8gb_print_some_test ( ); void r8gb_random_test ( ); void r8gb_sl_test ( ); void r8gb_to_r8ge_test ( ); void r8gb_to_r8vec_test ( ); void r8gb_trf_test ( ); void r8gb_trs_test ( ); void r8gb_zeros_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: r8gb_test() tests r8gb(). Licensing: This code is distributed under the MIT license. Modified: 22 August 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "r8gb_test():\n" ); printf ( " C version\n" ); printf ( " Test r8gb().\n" ); r8gb_det_test ( ); r8gb_dif2_test ( ); r8gb_fa_test ( ); r8gb_indicator_test ( ); r8gb_ml_test ( ); r8gb_mtv_test ( ); r8gb_mu_test ( ); r8gb_mv_test ( ); r8gb_nz_num_test ( ); r8gb_print_test ( ); r8gb_print_some_test ( ); r8gb_random_test ( ); r8gb_sl_test ( ); r8gb_to_r8ge_test ( ); r8gb_to_r8vec_test ( ); r8gb_trf_test ( ); r8gb_trs_test ( ); r8gb_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "r8gb_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8gb_det_test ( ) /******************************************************************************/ /* Purpose: R8GB_DET_TEST tests R8GB_DET. Licensing: This code is distributed under the MIT license. Modified: 20 March 2013 Author: John Burkardt */ { # define M 10 # define ML 3 # define MU 2 # define N 10 double *a; double *a2; double det; int info; int pivot[N]; int seed = 123456789; printf ( "\n" ); printf ( "R8GB_DET_TEST\n" ); printf ( " R8GB_DET computes the determinant of an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8gb_random ( M, N, ML, MU, &seed ); /* Copy the matrix into a general array. */ a2 = r8gb_to_r8ge ( M, N, ML, MU, a ); /* Print the matrix just to show what it looks like. */ r8ge_print ( M, N, a2, " The banded matrix:" ); /* Factor the matrix. */ info = r8gb_fa ( N, ML, MU, a, pivot ); if ( info != 0 ) { printf ( "\n" ); printf ( "r8gb_det(): Fatal error!\n" ); printf ( " r8gb_fa() returns nonzero value for info.\n" ); exit ( 1 ); } /* Compute the determinant. */ det = r8gb_det ( N, ML, MU, a, pivot ); printf ( "\n" ); printf ( " R8GB_DET computes the determinant = %g\n", det ); /* Factor the general matrix. */ info = r8ge_fa ( N, a2, pivot ); /* Compute the determinant. */ det = r8ge_det ( N, a2, pivot ); printf ( " R8GE_DET computes the determinant = %g\n", det ); free ( a ); free ( a2 ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_dif2_test ( ) /******************************************************************************/ /* Purpose: R8GB_DIF2_TEST tests R8GB_DIF2. Licensing: This code is distributed under the MIT license. Modified: 19 June 2016 Author: John Burkardt */ { # define M 5 # define ML 1 # define MU 1 # define N 5 double *a; printf ( "\n" ); printf ( "R8GB_DIF2_TEST\n" ); printf ( " R8GB_DIF2 sets up an R8GB second difference matrix .\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8gb_dif2 ( M, N, ML, MU ); r8gb_print ( M, N, ML, MU, a, " The R8GB second difference matrix:" ); free ( a ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_fa_test ( ) /******************************************************************************/ /* Purpose: R8GB_FA_TEST tests R8GB_FA. Licensing: This code is distributed under the MIT license. Modified: 21 March 2013 Author: John Burkardt */ { # define M 5 # define ML 1 # define MU 2 # define N 5 double *a; double *b; int info; int job; int pivot[N]; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8GB_FA_TEST\n" ); printf ( " R8GB_FA computes the PLU factors of an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8gb_random ( M, N, ML, MU, &seed ); r8gb_print ( M, N, ML, MU, a, " The banded matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ b = r8gb_mv ( M, N, ML, MU, a, x ); /* Factor the matrix. */ info = r8gb_fa ( N, ML, MU, a, pivot ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8GB_FA_TEST - Fatal error!\n" ); printf ( " R8GB_FA declares the matrix is singular!\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Solve the linear system. */ job = 0; free ( x ); x = r8gb_sl ( N, ML, MU, a, pivot, b, job ); r8vec_print ( N, x, " Solution:" ); /* Set the desired solution. */ free ( x ); x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ job = 1; free ( b ); b = r8gb_ml ( N, ML, MU, a, pivot, x, job ); r8vec_print ( N, b, " Right hand side of transposed system:" ); /* Solve the linear system. */ job = 1; free ( x ); x = r8gb_sl ( N, ML, MU, a, pivot, b, job ); r8vec_print ( N, x, " Solution to transposed system:" ); free ( a ); free ( b ); free ( x ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_indicator_test ( ) /******************************************************************************/ /* Purpose: R8GB_INDICATOR_TEST tests R8GB_INDICATOR. Licensing: This code is distributed under the MIT license. Modified: 26 March 2013 Author: John Burkardt */ { # define M 5 # define ML 2 # define MU 1 # define N 5 double *a; printf ( "\n" ); printf ( "R8GB_INDICATOR_TEST\n" ); printf ( " R8GB_INDICATOR returns an indicator matrix in R8GB format.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8gb_indicator ( M, N, ML, MU ); r8gb_print ( M, N, ML, MU, a, " The R8GB indicator matrix:" ); free ( a ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_ml_test ( ) /******************************************************************************/ /* Purpose: R8GB_ML_TEST tests R8GB_ML. Licensing: This code is distributed under the MIT license. Modified: 27 March 2013 Author: John Burkardt */ { # define M 10 # define ML 1 # define MU 2 # define N 10 double *a; double *b; double *b2; int info; int job; int pivot[N]; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8GB_ML_TEST\n" ); printf ( " R8GB_ML computes A*x or A'*X\n" ); printf ( " where the R8GB matrix A has been factored by R8GB_FA.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); for ( job = 0; job <= 1; job++ ) { /* Set the matrix. */ a = r8gb_random ( M, N, ML, MU, &seed ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ if ( job == 0 ) { b = r8gb_mv ( M, N, ML, MU, a, x ); } else { b = r8gb_mtv ( M, N, ML, MU, a, x ); } /* Factor the matrix. */ info = r8gb_fa ( N, ML, MU, a, pivot ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8GB_ML_TEST - Fatal error!\n" ); printf ( " R8GB_FA declares the matrix is singular!\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Now multiply factored matrix times solution to get right hand side again. */ b2 = r8gb_ml ( N, ML, MU, a, pivot, x, job ); if ( job == 0 ) { r8vec2_print ( N, b, b2, " A*x and PLU*x" ); } else { r8vec2_print ( N, b, b2, " A'*x and (PLU)'*x" ); } free ( a ); free ( b ); free ( b2 ); free ( x ); } return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_mtv_test ( ) /******************************************************************************/ /* Purpose: R8GB_MTV_TEST tests R8GB_MTV. Licensing: This code is distributed under the MIT license. Modified: 20 June 2016 Author: John Burkardt */ { # define M 5 # define ML 1 # define MU 2 # define N 5 double *a; double *b; int seed; double *x; printf ( "\n" ); printf ( "R8GB_MTV_TEST\n" ); printf ( " R8GB_MTV computes A'*x, where A is an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ seed = 123456789; a = r8gb_random ( M, N, ML, MU, &seed ); r8gb_print ( M, N, ML, MU, a, " Matrix A:" ); /* Set x. */ x = r8vec_indicator1_new ( N ); r8vec_print ( N, x, " Vector x:" ); /* Compute b. */ b = r8gb_mtv ( M, N, ML, MU, a, x ); r8vec_print ( N, b, " b=A'*x:" ); free ( a ); free ( b ); free ( x ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_mu_test ( ) /******************************************************************************/ /* Purpose: R8GB_MU_TEST tests R8GB_MU. Licensing: This code is distributed under the MIT license. Modified: 20 June 2016 Author: John Burkardt */ { # define M 10 # define ML 1 # define MU 2 # define N 10 double *a; double *b; double *b2; int info; int job; int pivot[N]; int seed; double *x; printf ( "\n" ); printf ( "R8GB_MU_TEST\n" ); printf ( " R8GB_MU computes A*x or A'*X\n" ); printf ( " where the R8GB matrix A has been factored by R8GB_TRF.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); for ( job = 0; job <= 1; job++ ) { /* Set the matrix. */ seed = 123456789; a = r8gb_random ( M, N, ML, MU, &seed ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ if ( job == 0 ) { b = r8gb_mv ( M, N, ML, MU, a, x ); } else { b = r8gb_mtv ( M, N, ML, MU, a, x ); } /* Factor the matrix. */ info = r8gb_trf ( N, N, ML, MU, a, pivot ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8GB_ML_TEST - Fatal error!\n" ); printf ( " R8GB_TRF declares the matrix is singular!\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Now multiply factored matrix times solution to get right hand side again. */ b2 = r8gb_mu ( N, ML, MU, a, pivot, x, job ); if ( job == 0 ) { r8vec2_print ( N, b, b2, " A*x and PLU*x" ); } else { r8vec2_print ( N, b, b2, " A'*x and (PLU)'*x" ); } free ( a ); free ( b ); free ( b2 ); free ( x ); } return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_mv_test ( ) /******************************************************************************/ /* Purpose: R8GB_MV_TEST tests R8GB_MV. Licensing: This code is distributed under the MIT license. Modified: 20 June 2016 Author: John Burkardt */ { # define M 5 # define ML 1 # define MU 2 # define N 5 double *a; double *b; int seed; double *x; printf ( "\n" ); printf ( "R8GB_MV_TEST\n" ); printf ( " R8GB_MV computes A*x, where A is an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ seed = 123456789; a = r8gb_random ( M, N, ML, MU, &seed ); r8gb_print ( M, N, ML, MU, a, " Matrix A:" ); /* Set x. */ x = r8vec_indicator1_new ( M ); r8vec_print ( M, x, " Vector x:" ); /* Compute b. */ b = r8gb_mv ( M, N, ML, MU, a, x ); r8vec_print ( N, b, " b=A*x:" ); free ( a ); free ( b ); free ( x ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_nz_num_test ( ) /******************************************************************************/ /* Purpose: R8GB_NZ_NUM_TEST tests R8GB_NZ_NUM. Licensing: This code is distributed under the MIT license. Modified: 29 March 2013 Author: John Burkardt */ { # define M 10 # define N 10 # define ML 1 # define MU 2 double *a; int diag; int j; int nz_num; int seed = 123456789; printf ( "\n" ); printf ( "R8GB_NZ_NUM_TEST\n" ); printf ( " R8GB_NZ_NUM counts the nonzero entries in an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8gb_random ( M, N, ML, MU, &seed ); /* Make some zero entries. */ for ( j = 0; j < N; j++ ) { for ( diag = 0; diag < 2*ML+MU+1; diag++ ) { if ( a[diag+j*(2*ML+MU+1)] < 0.3 ) { a[diag+j*(2*ML+MU+1)] = 0.0; } } } r8gb_print ( M, N, ML, MU, a, " The R8GB matrix:" ); nz_num = r8gb_nz_num ( M, N, ML, MU, a ); printf ( "\n" ); printf ( " Nonzero entries = %d\n", nz_num ); free ( a ); return; # undef M # undef N # undef ML # undef MU } /******************************************************************************/ void r8gb_print_test ( ) /******************************************************************************/ /* Purpose: R8GB_PRINT_TEST tests R8GB_PRINT. Licensing: This code is distributed under the MIT license. Modified: 28 March 2013 Author: John Burkardt */ { # define M 8 # define ML 1 # define MU 3 # define N 10 double *a; printf ( "\n" ); printf ( "R8GB_PRINT_TEST\n" ); printf ( " R8GB_PRINT prints an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8gb_indicator ( M, N, ML, MU ); r8gb_print ( M, N, ML, MU, a, " The banded matrix:" ); free ( a ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_print_some_test ( ) /******************************************************************************/ /* Purpose: R8GB_PRINT_SOME_TEST tests R8GB_PRINT_SOME. Licensing: This code is distributed under the MIT license. Modified: 20 June 2016 Author: John Burkardt */ { # define M 8 # define ML 1 # define MU 3 # define N 10 double *a; printf ( "\n" ); printf ( "R8GB_PRINT_SOME_TEST\n" ); printf ( " R8GB_PRINT_SOME prints some of an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8gb_indicator ( M, N, ML, MU ); r8gb_print_some ( M, N, ML, MU, a, 4, 3, 6, 9, " Rows(4-6), Cols (3-9)" ); free ( a ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_random_test ( ) /******************************************************************************/ /* Purpose: R8GB_RANDOM_TEST tests R8GB_RANDOM. Licensing: This code is distributed under the MIT license. Modified: 20 June 2016 Author: John Burkardt */ { # define M 5 # define ML 2 # define MU 1 # define N 5 double *a; int seed; printf ( "\n" ); printf ( "R8GB_RANDOM_TEST\n" ); printf ( " R8GB_RANDOM sets up a random R8GB matrix .\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); seed = 123456789; a = r8gb_random ( M, N, ML, MU, &seed ); r8gb_print ( M, N, ML, MU, a, " The random R8GB matrix:" ); free ( a ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_sl_test ( ) /******************************************************************************/ /* Purpose: R8GB_SL_TEST tests R8GB_SL. Licensing: This code is distributed under the MIT license. Modified: 21 March 2013 Author: John Burkardt */ { # define M 5 # define ML 1 # define MU 2 # define N 5 double *a; double *b; int info; int job; int pivot[N]; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8GB_SL_TEST\n" ); printf ( " R8GB_SL solves a linear system factored by R8GB_FA.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8gb_random ( M, N, ML, MU, &seed ); r8gb_print ( M, N, ML, MU, a, " The banded matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ b = r8gb_mv ( M, N, ML, MU, a, x ); /* Factor the matrix. */ info = r8gb_fa ( N, ML, MU, a, pivot ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8GB_SL_TEST - Fatal error!\n" ); printf ( " R8GB_FA declares the matrix is singular!\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Solve the linear system. */ job = 0; free ( x ); x = r8gb_sl ( N, ML, MU, a, pivot, b, job ); r8vec_print ( N, x, " Solution:" ); /* Set the desired solution. */ free ( x ); x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ job = 1; free ( b ); b = r8gb_ml ( N, ML, MU, a, pivot, x, job ); r8vec_print ( N, b, " Right hand side of transposed system:" ); /* Solve the linear system. */ job = 1; free ( x ); x = r8gb_sl ( N, ML, MU, a, pivot, b, job ); r8vec_print ( N, x, " Solution to transposed system:" ); free ( a ); free ( b ); free ( x ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8GB_TO_R8GE_TEST tests R8GB_TO_R8GE. Licensing: This code is distributed under the MIT license. Modified: 30 March 2013 Author: John Burkardt */ { # define M 5 # define ML 2 # define MU 1 # define N 8 double *a; double *b; double *c; printf ( "\n" ); printf ( "R8GB_TO_R8GE_TEST\n" ); printf ( " R8GB_TO_R8GE copies an R8GB matrix to R8GE format.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8gb_indicator ( M, N, ML, MU ); r8gb_print ( M, N, ML, MU, a, " The R8GB matrix:" ); b = r8gb_to_r8ge ( M, N, ML, MU, a ); r8ge_print ( M, N, b, " The R8GE matrix:" ); c = r8ge_to_r8gb ( M, N, ML, MU, b ); r8gb_print ( M, N, ML, MU, c, " The recovered R8GB matrix:" ); free ( a ); free ( b ); free ( c ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_to_r8vec_test ( ) /******************************************************************************/ /* Purpose: R8GB_TO_R8VEC_TEST tests R8GB_TO_R8VEC. Licensing: This code is distributed under the MIT license. Modified: 20 June 2016 Author: John Burkardt */ { # define M 5 # define ML 2 # define MU 1 # define N 8 double *a; double *a_r8vec; printf ( "\n" ); printf ( "R8GB_TO_R8VEC_TEST\n" ); printf ( " R8GB_TO_R8VEC converts an R8GB matrix to R8VEC format.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8gb_indicator ( M, N, ML, MU ); r8gb_print ( M, N, ML, MU, a, " The R8GB matrix:" ); a_r8vec = r8gb_to_r8vec ( M, N, ML, MU, a ); r8vec_print ( (2*ML+MU+1)*N, a_r8vec, " The R8VEC vector:" ); free ( a ); free ( a_r8vec ); return; # undef M # undef ML # undef MU # undef N } /******************************************************************************/ void r8gb_trf_test ( ) /******************************************************************************/ /* Purpose: R8GB_TRF_TEST tests R8GB_TRF. Licensing: This code is distributed under the MIT license. Modified: 31 March 2013 Author: John Burkardt */ { # define M 10 # define N 10 # define ML 1 # define MU 2 # define NRHS 1 double *a; double *b; int info; int job; int pivot[N]; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8GB_TRF_TEST\n" ); printf ( " R8GB_TRF computes the PLU factors of an R8GB matrix.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8gb_random ( M, N, ML, MU, &seed ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ b = r8gb_mv ( M, N, ML, MU, a, x ); /* Factor the matrix. */ info = r8gb_trf ( M, N, ML, MU, a, pivot ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8GB_TRF_TEST - Fatal error!\n" ); printf ( " R8GB_TRF declares the matrix is singular!\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Solve the linear system. */ free ( x ); x = r8gb_trs ( N, ML, MU, NRHS, 'N', a, pivot, b ); r8vec_print ( N, x, " Solution:" ); /* Set the desired solution. */ free ( x ); x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ job = 1; free ( b ); b = r8gb_mu ( N, ML, MU, a, pivot, x, job ); /* Solve the linear system. */ free ( x ); x = r8gb_trs ( N, ML, MU, NRHS, 'T', a, pivot, b ); r8vec_print ( N, x, " Solution to transposed system:" ); free ( a ); free ( b ); free ( x ); return; # undef M # undef N # undef ML # undef MU # undef NRHS } /******************************************************************************/ void r8gb_trs_test ( ) /******************************************************************************/ /* Purpose: R8GB_TRS_TEST tests R8GB_TRS. Licensing: This code is distributed under the MIT license. Modified: 31 March 2013 Author: John Burkardt */ { # define M 10 # define N 10 # define ML 1 # define MU 2 # define NRHS 1 double *a; double *b; int info; int job; int pivot[N]; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8GB_TRS_TEST\n" ); printf ( " R8GB_TRS solves a linear system factored by R8GB_TRF.\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); /* Set the matrix. */ a = r8gb_random ( M, N, ML, MU, &seed ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ b = r8gb_mv ( M, N, ML, MU, a, x ); /* Factor the matrix. */ info = r8gb_trf ( M, N, ML, MU, a, pivot ); if ( info != 0 ) { printf ( "\n" ); printf ( "R8GB_TRS_TEST - Fatal error!\n" ); printf ( " R8GB_TRF declares the matrix is singular!\n" ); printf ( " The value of INFO is %d\n", info ); return; } /* Solve the linear system. */ free ( x ); x = r8gb_trs ( N, ML, MU, NRHS, 'N', a, pivot, b ); r8vec_print ( N, x, " Solution:" ); /* Set the desired solution. */ free ( x ); x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ job = 1; free ( b ); b = r8gb_mu ( N, ML, MU, a, pivot, x, job ); /* Solve the linear system. */ free ( x ); x = r8gb_trs ( N, ML, MU, NRHS, 'T', a, pivot, b ); r8vec_print ( N, x, " Solution to transposed system:" ); free ( a ); free ( b ); free ( x ); return; # undef M # undef N # undef ML # undef MU # undef NRHS } /******************************************************************************/ void r8gb_zeros_test ( ) /******************************************************************************/ /* Purpose: R8GB_ZEROS_TEST tests R8GB_ZEROS. Licensing: This code is distributed under the MIT license. Modified: 19 June 2016 Author: John Burkardt */ { # define M 5 # define ML 2 # define MU 1 # define N 5 double *a; printf ( "\n" ); printf ( "R8GB_ZEROS_TEST\n" ); printf ( " R8GB_ZEROS zeros an R8GB matrix .\n" ); printf ( "\n" ); printf ( " Matrix rows M = %d\n", M ); printf ( " Matrix columns N = %d\n", N ); printf ( " Lower bandwidth ML = %d\n", ML ); printf ( " Upper bandwidth MU = %d\n", MU ); a = r8gb_zeros ( M, N, ML, MU ); r8gb_print ( M, N, ML, MU, a, " The R8GB zero matrix:" ); free ( a ); return; # undef M # undef ML # undef MU # 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 }