# include # include # include # include # include "r8pp.h" int main ( ); void r8pp_det_test ( ); void r8pp_dif2_test ( ); void r8pp_fa_test ( ); void r8pp_indicator_test ( ); void r8pp_mv_test ( ); void r8pp_print_test ( ); void r8pp_print_some_test ( ); void r8pp_random_test ( ); void r8pp_to_r8ge_test ( ); void r8pp_zeros_test ( ); void r8pp_sl_test ( ); void r8pp_zeros_test ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: MAIN is the main program for R8PP_TEST. Discussion: R8PP_TEST tests R8PP. Licensing: This code is distributed under the GNU LGPL license. Modified: 18 June 2016 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "R8PP_TEST\n" ); printf ( " C version\n" ); printf ( " Test the R8PP library.\n" ); r8pp_det_test ( ); r8pp_dif2_test ( ); r8pp_fa_test ( ); r8pp_indicator_test ( ); r8pp_mv_test ( ); r8pp_print_test ( ); r8pp_print_some_test ( ); r8pp_random_test ( ); r8pp_sl_test ( ); r8pp_to_r8ge_test ( ); r8pp_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "R8PP_TEST\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8pp_det_test ( ) /******************************************************************************/ /* Purpose: R8PP_DET_TEST tests R8PP_DET. Licensing: This code is distributed under the GNU LGPL license. Modified: 14 June 2016 Author: John Burkardt */ { double *a; double *a_lu; double det; int n = 5; printf ( "\n" ); printf ( "R8PP_DET_TEST\n" ); printf ( " R8PP_DET computes the determinant of an R8PP matrix\n" ); printf ( " factored by R8PP_FA.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); /* Set the matrix. */ a = r8pp_dif2 ( n ); r8pp_print ( n, a, " The R8PP matrix:" ); /* Factor the matrix. */ a_lu = r8pp_fa ( n, a ); /* Compute the determinant. */ det = r8pp_det ( n, a_lu ); printf ( "\n" ); printf ( " Determinant = %g\n", det ); printf ( " Exact determinant = %g\n", ( double ) ( n + 1 ) ); free ( a ); free ( a_lu ); return; } /******************************************************************************/ void r8pp_dif2_test ( ) /******************************************************************************/ /* Purpose: R8PP_DIF2_TEST tests R8PP_DIF2. Licensing: This code is distributed under the GNU LGPL license. Modified: 14 June 2016 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8PP_DIF2_TEST\n" ); printf ( " R8PP_DIF2 sets up an R8PP second difference matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8pp_dif2 ( n ); r8pp_print ( n, a, " The R8PP second difference matrix:" ); free ( a ); return; } /******************************************************************************/ void r8pp_fa_test ( ) /******************************************************************************/ /* Purpose: R8PP_FA_TEST tests R8PP_FA. Licensing: This code is distributed under the GNU LGPL license. Modified: 17 April 2013 Author: John Burkardt */ { # define N 5 double *a; double *b; int i; int info; int j; double *r; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8PP_FA_TEST\n" ); printf ( " R8PP_FA factors an R8PP system,\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ a = r8pp_random ( N, &seed ); r8pp_print ( N, a, " The R8PP matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); r8vec_print ( N, x, " The desired solution:" ); /* Compute the corresponding right hand side. */ b = r8pp_mv ( N, a, x ); r8vec_print ( N, b, " The right hand side:" ); /* Factor the matrix. */ r = r8pp_fa ( N, a ); if ( r == NULL ) { printf ( "\n" ); printf ( "R8PP_FA_TEST - Fatal error!\n" ); printf ( " R8PP_FA declares the matrix is singular!\n" ); return; } printf ( "\n" ); printf ( " The R8PP matrix has been factored.\n" ); /* Solve the linear system. */ free ( x ); x = r8pp_sl ( N, r, b ); r8vec_print ( N, x, " Solution:" ); free ( a ); free ( b ); free ( r ); free ( x ); return; # undef N } /******************************************************************************/ void r8pp_indicator_test ( ) /******************************************************************************/ /* Purpose: R8PP_INDICATOR_TEST tests R8PP_INDICATOR. Licensing: This code is distributed under the GNU LGPL license. Modified: 17 April 2013 Author: John Burkardt */ { # define N 5 double *a; printf ( "\n" ); printf ( "R8PP_INDICATOR_TEST\n" ); printf ( " R8PP_INDICATOR sets up an R8PP indicator matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); a = r8pp_indicator ( N ); r8pp_print ( N, a, " The R8PP indicator matrix:" ); free ( a ); return; # undef N } /******************************************************************************/ void r8pp_mv_test ( ) /******************************************************************************/ /* Purpose: R8PP_MV_TEST tests R8PP_MV. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 June 2016 Author: John Burkardt */ { double *a; double *b; int n = 5; double *x; printf ( "\n" ); printf ( "R8PP_MV_TEST\n" ); printf ( " R8PP_MV computes b=A*x, where A is an R8PP matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8pp_indicator ( n ); r8pp_print ( n, a, " The R8PP matrix A:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " Vector x:" ); b = r8pp_mv ( n, a, x ); r8vec_print ( n, b, " Product b=A*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8pp_print_test ( ) /******************************************************************************/ /* Purpose: R8PP_PRINT_TEST tests R8PP_PRINT. Licensing: This code is distributed under the GNU LGPL license. Modified: 14 June 2016 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8PP_PRINT_TEST\n" ); printf ( " R8PP_PRINT prints an R8PP matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8pp_dif2 ( n ); r8pp_print ( n, a, " The R8PP matrix:" ); free ( a ); return; } /******************************************************************************/ void r8pp_print_some_test ( ) /******************************************************************************/ /* Purpose: R8PP_PRINT_SOME_TEST tests R8PP_PRINT_SOME. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 June 2016 Author: John Burkardt */ { double *a; int n = 10; printf ( "\n" ); printf ( "R8PP_PRINT_SOME_TEST\n" ); printf ( " R8PP_PRINT_SOME prints some of an R8PP matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8pp_indicator ( n ); r8pp_print_some ( n, a, 1, 2, 5, 4, " Rows 1-5, Cols 2-4:" ); free ( a ); return; } /******************************************************************************/ void r8pp_random_test ( ) /******************************************************************************/ /* / Purpose: R8PP_RANDOM_TEST tests R8PP_RANDOM. Licensing: This code is distributed under the GNU LGPL license. Modified: 17 April 2013 Author: John Burkardt */ { # define N 5 double *a; double *b; int seed = 123456789; printf ( "\n" ); printf ( "R8PP_RANDOM_TEST\n" ); printf ( " R8PP_RANDOM, compute a random positive definite\n" ); printf ( " symmetric packed matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ a = r8pp_random ( N, &seed ); r8pp_print ( N, a, " The matrix (printed by R8PP_PRINT):" ); b = r8pp_to_r8ge ( N, a ); r8ge_print ( N, N, b, " The random R8PP matrix (printed by R8GE_PRINT):" ); free ( a ); free ( b ); return; # undef N } /******************************************************************************/ void r8pp_sl_test ( ) /******************************************************************************/ /* Purpose: R8PP_SL_TEST tests R8PP_SL. Licensing: This code is distributed under the GNU LGPL license. Modified: 17 April 2013 Author: John Burkardt */ { # define N 5 double *a; double *b; int i; int info; int j; double *r; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8PP_SL_TEST\n" ); printf ( " R8PP_SL solves a linear system factored by R8PP_FA.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ a = r8pp_random ( N, &seed ); r8pp_print ( N, a, " The R8PP matrix:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( N ); r8vec_print ( N, x, " The desired solution:" ); /* Compute the corresponding right hand side. */ b = r8pp_mv ( N, a, x ); r8vec_print ( N, b, " The right hand side:" ); /* Factor the matrix. */ r = r8pp_fa ( N, a ); if ( r == NULL ) { printf ( "\n" ); printf ( "R8PP_SL_TEST - Fatal error!\n" ); printf ( " R8PP_FA declares the matrix is singular!\n" ); return; } printf ( "\n" ); printf ( " The R8PP matrix has been factored.\n" ); /* Solve the linear system. */ free ( x ); x = r8pp_sl ( N, r, b ); r8vec_print ( N, x, " Solution:" ); free ( a ); free ( b ); free ( r ); free ( x ); return; # undef N } /******************************************************************************/ void r8pp_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8PP_TO_R8GE_TEST tests R8PP_TO_R8GE. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 June 2016 Author: John Burkardt */ { # define N 5 double *a; double *a_r8ge; printf ( "\n" ); printf ( "R8PP_TO_R8GE_TEST\n" ); printf ( " R8PP_TO_R8GE converts an R8PP matrix to R8GE format.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); a = r8pp_indicator ( N ); r8pp_print ( N, a, " The R8PP indicator matrix:" ); a_r8ge = r8pp_to_r8ge ( N, a ); r8ge_print ( N, N, a_r8ge, " The R8GE matrix:" ); free ( a ); free ( a_r8ge ); return; # undef N } /******************************************************************************/ void r8pp_zeros_test ( ) /******************************************************************************/ /* Purpose: R8PP_ZEROS_TEST tests R8PP_ZEROS. Licensing: This code is distributed under the GNU LGPL license. Modified: 14 June 2016 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8PP_ZEROS_TEST\n" ); printf ( " R8PP_ZEROS zeros an R8PP matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8pp_zeros ( n ); r8pp_print ( n, a, " The R8PP zero matrix:" ); free ( a ); return; }