# include # include # include # include "r8gd.h" int main ( ); void r8gd_dif2_test ( ); void r8gd_indicator_test ( ); void r8gd_mtv_test ( ); void r8gd_mv_test ( ); void r8gd_print_test ( ); void r8gd_print_some_test ( ); void r8gd_random_test ( ); void r8gd_to_r8ge_test ( ); void r8gd_zeros_test ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: MAIN is the main program for R8GD_TEST. Discussion: R8GD_TEST tests R8GD. Licensing: This code is distributed under the GNU LGPL license. Modified: 19 July 2016 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "R8GD_TEST\n" ); printf ( " C version\n" ); printf ( " Test the R8GD library.\n" ); r8gd_dif2_test ( ); r8gd_indicator_test ( ); r8gd_mtv_test ( ); r8gd_mv_test ( ); r8gd_print_test ( ); r8gd_print_some_test ( ); r8gd_random_test ( ); r8gd_to_r8ge_test ( ); r8gd_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "R8GD_TEST\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8gd_dif2_test ( ) /******************************************************************************/ /* Purpose: R8GD_DIF2_TEST tests R8GD_DIF2. Licensing: This code is distributed under the GNU LGPL license. Modified: 18 July 2016 Author: John Burkardt */ { double *a; int n = 5; int ndiag = 3; int offset[3] = { -1, 0, 1 }; printf ( "\n" ); printf ( "R8GD_DIF2_TEST\n" ); printf ( " R8GD_DIF2 sets up an R8GD second difference matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Number of diagonals NDIAG = %d\n", ndiag ); i4vec_print ( ndiag, offset, " The offset vector:" ); a = r8gd_dif2 ( n, ndiag, offset ); r8gd_print ( n, ndiag, offset, a, " The R8GD second difference matrix:" ); free ( a ); return; } /******************************************************************************/ void r8gd_indicator_test ( ) /******************************************************************************/ /* Purpose: R8GD_INDICATOR_TEST tests R8GD_INDICATOR. Licensing: This code is distributed under the GNU LGPL license. Modified: 31 March 2013 Author: John Burkardt */ { double *a; int n = 10; int ndiag = 4; int offset[4] = { -2, 0, 1, 3 }; printf ( "\n" ); printf ( "R8GD_INDICATOR_TEST\n" ); printf ( " R8GD_INDICATOR sets up an R8GD indicator matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Number of diagonals NDIAG = %d\n", ndiag ); i4vec_print ( ndiag, offset, " The offset vector:" ); a = r8gd_indicator ( n, ndiag, offset ); r8gd_print ( n, ndiag, offset, a, " The R8GD indicator matrix:" ); free ( a ); return; } /******************************************************************************/ void r8gd_mtv_test ( ) /******************************************************************************/ /* Purpose: R8GD_MTV_TEST tests R8GD_MTV. Licensing: This code is distributed under the GNU LGPL license. Modified: 01 April 2013 Author: John Burkardt */ { # define N 10 # define NDIAG 4 double *a; double *b; int i; int j; int offset[NDIAG] = { -2, 0, 1, N-1 }; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8GD_MTV_TEST\n" ); printf ( " R8GD_MTV computes A'*x where A is an R8GD matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Number of diagonals NDIAG = %d\n", NDIAG ); i4vec_print ( NDIAG, offset, " The offset vector:" ); /* Set the matrix. */ a = r8gd_random ( N, NDIAG, offset, &seed ); r8ge_print ( N, NDIAG, a, " The raw matrix: " ); r8gd_print ( N, NDIAG, offset, a, " The general diagonal matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ b = r8gd_mtv ( N, NDIAG, offset, a, x ); r8vec_print ( N, b, " A' * x:" ); free ( a ); free ( b ); free ( x ); return; # undef N # undef NDIAG } /******************************************************************************/ void r8gd_mv_test ( ) /******************************************************************************/ /* Purpose: R8GD_MV_TEST tests R8GD_MV. Licensing: This code is distributed under the GNU LGPL license. Modified: 01 April 2013 Author: John Burkardt */ { # define N 10 # define NDIAG 4 double *a; double *b; int i; int j; int offset[NDIAG] = { -2, 0, 1, N-1 }; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8GD_MV_TEST\n" ); printf ( " R8GD_MV computes A * x where A is an R8GD matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Number of diagonals NDIAG = %d\n", NDIAG ); i4vec_print ( NDIAG, offset, " The offset vector:" ); /* Set the matrix. */ a = r8gd_random ( N, NDIAG, offset, &seed ); r8ge_print ( N, NDIAG, a, " The raw matrix: " ); r8gd_print ( N, NDIAG, offset, a, " The general diagonal matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); /* Compute the corresponding right hand side. */ b = r8gd_mv ( N, NDIAG, offset, a, x ); r8vec_print ( N, b, " A * x:" ); free ( a ); free ( b ); free ( x ); return; # undef N # undef NDIAG } /******************************************************************************/ void r8gd_print_test ( ) /******************************************************************************/ /* Purpose: R8GD_PRINT_TEST tests R8GD_PRINT. Licensing: This code is distributed under the GNU LGPL license. Modified: 18 July 2016 Author: John Burkardt */ { double *a; int n = 10; int ndiag = 4; int offset[4] = { -2, 0, 1, 3 }; int seed = 123456789; printf ( "\n" ); printf ( "R8GD_PRINT_TEST\n" ); printf ( " R8GD_PRINT prints an R8GD matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Number of diagonals NDIAG = %d\n", ndiag ); i4vec_print ( ndiag, offset, " The offset vector:" ); /* Set the matrix. */ a = r8gd_random ( n, ndiag, offset, &seed ); r8gd_print ( n, ndiag, offset, a, " The general diagonal matrix:" ); free ( a ); return; } /******************************************************************************/ void r8gd_print_some_test ( ) /******************************************************************************/ /* Purpose: R8GD_PRINT_SOME_TEST tests R8GD_PRINT_SOME. Licensing: This code is distributed under the GNU LGPL license. Modified: 18 July 2016 Author: John Burkardt */ { double *a; int n = 10; int ndiag = 4; int offset[4] = { -2, 0, 1, 3 }; int seed = 123456789; printf ( "\n" ); printf ( "R8GD_PRINT_SOME_TEST\n" ); printf ( " R8GD_PRINT_SOME prints some of an R8GD matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Number of diagonals NDIAG = %d\n", ndiag ); i4vec_print ( ndiag, offset, " The offset vector:" ); /* Set the matrix. */ a = r8gd_random ( n, ndiag, offset, &seed ); r8gd_print_some ( n, ndiag, offset, a, 3, 3, 6, 6, " Rows 3-6, Cols 3-6:" ); free ( a ); return; } /******************************************************************************/ void r8gd_random_test ( ) /******************************************************************************/ /* Purpose: R8GD_RANDOM_TEST tests R8GD_RANDOM. Licensing: This code is distributed under the GNU LGPL license. Modified: 01 April 2013 Author: John Burkardt */ { # define N 10 # define NDIAG 4 double *a; int offset[NDIAG] = { -2, 0, 1, N-1 }; int seed = 123456789; printf ( "\n" ); printf ( "R8GD_RANDOM_TEST\n" ); printf ( " R8GD_RANDOM randomly generates an R8GD matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); printf ( " Number of diagonals NDIAG = %d\n", NDIAG ); i4vec_print ( NDIAG, offset, " The offset vector:" ); /* Set the matrix. */ a = r8gd_random ( N, NDIAG, offset, &seed ); r8gd_print ( N, NDIAG, offset, a, " The general diagonal matrix:" ); free ( a ); return; # undef N # undef NDIAG } /******************************************************************************/ void r8gd_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8GD_TO_R8GE_TEST tests R8GD_TO_R8GE. Licensing: This code is distributed under the GNU LGPL license. Modified: 31 March 2013 Author: John Burkardt */ { double *a; double *a_r8ge; int n = 10; int ndiag = 4; int offset[4] = { -2, 0, 1, 3 }; printf ( "\n" ); printf ( "R8GD_TO_R8GE_TEST\n" ); printf ( " R8GD_TO_R8GE converts an R8GD matrix to R8GE format;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Number of diagonals NDIAG = %d\n", ndiag ); i4vec_print ( ndiag, offset, " The offset vector:" ); a = r8gd_indicator ( n, ndiag, offset ); r8gd_print ( n, ndiag, offset, a, " The R8GD matrix:" ); a_r8ge = r8gd_to_r8ge ( n, ndiag, offset, a ); r8ge_print ( n, n, a_r8ge, " The R8GE matrix:" ); free ( a ); free ( a_r8ge ); return; } /******************************************************************************/ void r8gd_zeros_test ( ) /******************************************************************************/ /* Purpose: R8GD_ZEROS_TEST tests R8GD_ZEROS. Licensing: This code is distributed under the GNU LGPL license. Modified: 18 July 2016 Author: John Burkardt */ { double *a; int n = 10; int ndiag = 4; int offset[4] = { -2, 0, 1, 3 }; printf ( "\n" ); printf ( "R8GD_ZEROS_TEST\n" ); printf ( " R8GD_ZEROS zeros an R8GD matrix;\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); printf ( " Number of diagonals NDIAG = %d\n", ndiag ); i4vec_print ( ndiag, offset, " The offset vector:" ); a = r8gd_zeros ( n, ndiag, offset ); r8gd_print ( n, ndiag, offset, a, " The R8GD zero matrix:" ); free ( a ); return; }