# include # include # include # include "r8sr.h" int main ( ); void r8sr_dif2_test ( ); void r8sr_indicator_test ( ); void r8sr_mtv_test ( ); void r8sr_mv_test ( ); void r8sr_print_test ( ); void r8sr_print_some_test ( ); void r8sr_random_test ( ); void r8sr_to_r8ge_test ( ); void r8sr_zeros_test ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: MAIN is the main program for R8SR_TEST. Discussion: R8SR_TEST tests R8SR. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 June 2016 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "R8SR_TEST\n" ); printf ( " C version\n" ); printf ( " Test the R8SR library.\n" ); r8sr_dif2_test ( ); r8sr_indicator_test ( ); r8sr_mtv_test ( ); r8sr_mv_test ( ); r8sr_print_test ( ); r8sr_print_some_test ( ); r8sr_random_test ( ); r8sr_to_r8ge_test ( ); r8sr_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "R8SR_TEST\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8sr_dif2_test ( ) /******************************************************************************/ /* Purpose: R8SR_DIF2_TEST tests R8SR_DIF2. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 June 2016 Author: John Burkardt */ { int *col; double *diag; int n = 5; int nz; double *off; int *row; printf ( "\n" ); printf ( "R8SR_DIF2_TEST\n" ); printf ( " R8SR_DIF2 sets an R8SR second difference matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); col = ( int * ) malloc ( 2 * ( n - 1 ) * sizeof ( int ) ); diag = ( double * ) malloc ( n * sizeof ( double ) ); off = ( double * ) malloc ( 2 * ( n - 1 ) * sizeof ( double ) ); row = ( int * ) malloc ( ( n + 1 ) * sizeof ( int ) ); r8sr_dif2 ( n, &nz, row, col, diag, off ); r8sr_print ( n, nz, row, col, diag, off, " The R8SR second difference matrix:" ); free ( col ); free ( diag ); free ( off ); free ( row ); return; } /******************************************************************************/ void r8sr_indicator_test ( ) /******************************************************************************/ /* Purpose: R8SR_INDICATOR_TEST tests R8SR_INDICATOR. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 June 2016 Author: John Burkardt */ { # define N 5 # define NZ 7 int col[NZ] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[N]; double off[NZ]; int row[N+1] = { 0, 2, 3, 4, 5, 7 }; printf ( "\n" ); printf ( "R8SR_INDICATOR_TEST\n" ); printf ( " R8SR_INDICATOR sets up an R8SR indicator matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); r8sr_indicator ( N, NZ, row, col, diag, off ); r8sr_print ( N, NZ, row, col, diag, off, " The R8SR indicator matrix:" ); return; # undef N # undef NZ } /******************************************************************************/ void r8sr_mtv_test ( ) /******************************************************************************/ /* Purpose: R8SR_MTV_TEST tests R8SR_MTV. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 June 2016 Author: John Burkardt */ { # define N 5 # define NZ 7 double *b; int col[NZ] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[N]; int i; double off[NZ]; int row[N+1] = { 0, 2, 3, 4, 5, 7 }; int seed = 123456789; double x[N]; printf ( "\n" ); printf ( "R8SR_MTV_TEST\n" ); printf ( " R8SR_MTV computes b=A'*x, where A is an R8SR matrix\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ r8sr_random ( N, NZ, row, col, diag, off, &seed ); /* Print the matrix. */ r8sr_print ( N, NZ, row, col, diag, off, " The R8SR matrix A:" ); x[0] = 1.0; for ( i = 1; i < N-1; i++ ) { x[i] = 0.0; } x[N-1] = -1.0; r8vec_print ( N, x, " x:" ); b = r8sr_mtv ( N, NZ, row, col, diag, off, x ); r8vec_print ( N, b, " b=A'*x:" ); free ( b ); return; # undef N # undef NZ } /******************************************************************************/ void r8sr_mv_test ( ) /******************************************************************************/ /* Purpose: R8SR_MV_TEST tests R8SR_MV. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 June 2016 Author: John Burkardt */ { # define N 5 # define NZ 7 double *b; int col[NZ] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[N]; int i; double off[NZ]; int row[N+1] = { 0, 2, 3, 4, 5, 7 }; int seed = 123456789; double x[N]; printf ( "\n" ); printf ( "R8SR_MV_TEST\n" ); printf ( " R8SR_MV computes b=A*X, where A is an R8SR matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ r8sr_random ( N, NZ, row, col, diag, off, &seed ); /* Print it. */ r8sr_print ( N, NZ, row, col, diag, off, " The R8SR matrix:" ); x[0] = 1.0; for ( i = 1; i < N-1; i++ ) { x[i] = 0.0; } x[N-1] = -1.0; r8vec_print ( N, x, " The vector x:" ); b = r8sr_mv ( N, NZ, row, col, diag, off, x ); r8vec_print ( N, b, " The product A * x:" ); free ( b ); return; # undef N # undef NZ } /******************************************************************************/ void r8sr_print_test ( ) /******************************************************************************/ /* Purpose: R8SR_PRINT_TEST tests R8SR_PRINT. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 April 2013 Author: John Burkardt */ { # define N 5 # define NZ 7 int col[NZ] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[N]; double off[NZ]; int row[N+1] = { 0, 2, 3, 4, 5, 7 }; int seed = 123456789; printf ( "\n" ); printf ( "R8SR_PRINT_TEST\n" ); printf ( " R8SR_PRINT prints an R8SR matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ r8sr_random ( N, NZ, row, col, diag, off, &seed ); /* Print the matrix. */ r8sr_print ( N, NZ, row, col, diag, off, " The R8SR matrix:" ); return; # undef N # undef NZ } /******************************************************************************/ void r8sr_print_some_test ( ) /******************************************************************************/ /* Purpose: R8SR_PRINT_SOME_TEST tests R8SR_PRINT_SOME. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 June 2016 Author: John Burkardt */ { int col[7] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[5]; int n = 5; int nz = 7; double off[7]; int row[6] = { 0, 2, 3, 4, 5, 7 }; int seed = 123456789; printf ( "\n" ); printf ( "R8SR_PRINT_SOME_TEST\n" ); printf ( " R8SR_PRINT_SOME prints some of an R8SR matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); /* Set the matrix. */ r8sr_random ( n, nz, row, col, diag, off, &seed ); /* Print the matrix. */ r8sr_print_some ( n, nz, row, col, diag, off, 0, 4, n - 1, 4, " Rows 0:N-1, column 4" ); return; } /******************************************************************************/ void r8sr_random_test ( ) /******************************************************************************/ /* Purpose: R8SR_RANDOM_TEST tests R8SR_RANDOM. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 June 2016 Author: John Burkardt */ { # define N 5 # define NZ 7 int col[NZ] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[N]; double off[NZ]; int row[N+1] = { 0, 2, 3, 4, 5, 7 }; int seed = 123456789; printf ( "\n" ); printf ( "R8SR_RANDOM_TEST\n" ); printf ( " R8SR_RANDOM randomizes an R8SR matrix\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ r8sr_random ( N, NZ, row, col, diag, off, &seed ); /* Print the matrix. */ r8sr_print ( N, NZ, row, col, diag, off, " The R8SR matrix:" ); return; # undef N # undef NZ } /******************************************************************************/ void r8sr_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8SR_TO_R8GE_TEST tests R8SR_TO_R8GE. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 June 2016 Author: John Burkardt */ { double *a_r8ge; int col[7] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[5]; int n = 5; int nz = 7; double off[7]; int row[6] = { 0, 2, 3, 4, 5, 7 }; int seed = 123456789; printf ( "\n" ); printf ( "R8SR_TO_R8GE_TEST\n" ); printf ( " R8SR_TO_R8GE converts a matrix from R8SR to R8GE format.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); /* Set the matrix. */ r8sr_random ( n, nz, row, col, diag, off, &seed ); /* Print the matrix. */ r8sr_print ( n, nz, row, col, diag, off, " The R8SR matrix:" ); /* Convert the matrix. */ a_r8ge = r8sr_to_r8ge ( n, nz, row, col, diag, off ); /* Print the R8GE matrix. */ r8ge_print ( n, n, a_r8ge, " The R8GE matrix:" ); free ( a_r8ge ); return; } /******************************************************************************/ void r8sr_zeros_test ( ) /******************************************************************************/ /* Purpose: R8SR_ZEROS_TEST tests R8SR_ZEROS. Licensing: This code is distributed under the GNU LGPL license. Modified: 12 June 2016 Author: John Burkardt */ { # define N 5 # define NZ 7 int col[NZ] = { 1, 4, 4, 0, 0, 1, 2 }; double diag[N]; double off[NZ]; int row[N+1] = { 0, 2, 3, 4, 5, 7 }; printf ( "\n" ); printf ( "R8SR_ZEROS_TEST\n" ); printf ( " R8SR_ZEROS zeros an R8SR matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); r8sr_zeros ( N, NZ, row, col, diag, off ); r8sr_print ( N, NZ, row, col, diag, off, " The zero R8SR matrix:" ); return; # undef N # undef NZ }