# include # include # include # include # include # include "r8ci.h" int main ( ); void r8ci_det_test ( ); void r8ci_dif2_test ( ); void r8ci_eval_test ( ); void r8ci_indicator_test ( ); void r8ci_mtv_test ( ); void r8ci_mv_test ( ); void r8ci_print_test ( ); void r8ci_print_some_test ( ); void r8ci_sl_test ( ); void r8ci_to_r8ge_test ( ); void r8ci_zeros_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: r8ci_test() tests r8ci(). Licensing: This code is distributed under the MIT license. Modified: 21 August 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "r8ci_test():\n" ); printf ( " C version\n" ); printf ( " Test r8ci().\n" ); r8ci_det_test ( ); r8ci_dif2_test ( ); r8ci_eval_test ( ); r8ci_indicator_test ( ); r8ci_mtv_test ( ); r8ci_mv_test ( ); r8ci_print_test ( ); r8ci_print_some_test ( ); r8ci_sl_test ( ); r8ci_to_r8ge_test ( ); r8ci_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "r8ci_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8ci_det_test ( ) /******************************************************************************/ /* Purpose: R8CI_DET_TEST tests R8CI_DET. Licensing: This code is distributed under the MIT license. Modified: 17 June 2016 Author: John Burkardt */ { double *a; double det; int n = 5; int seed = 123456789; printf ( "\n" ); printf ( "R8CI_DET_TEST\n" ); printf ( " R8CI_DET finds the determinant of an R8CI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); /* Set the matrix. */ a = r8ci_random ( n, &seed ); r8ci_print ( n, a, " The R8CI matrix:" ); det = r8ci_det ( n, a ); printf ( "\n" ); printf ( " Computed determinant = %g\n", det ); free ( a ); return; } /******************************************************************************/ void r8ci_dif2_test ( ) /******************************************************************************/ /* Purpose: R8CI_DIF2_TEST tests R8CI_DIF2. Licensing: This code is distributed under the MIT license. Modified: 17 June 2016 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8CI_DIF2_TEST\n" ); printf ( " R8CI_DIF2 sets up an R8CI periodic second difference matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_dif2 ( n ); r8ci_print ( n, a, " The R8CI matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ci_eval_test ( ) /******************************************************************************/ /* Purpose: R8CI_EVAL_TEST tests R8CI_EVAL. Licensing: This code is distributed under the MIT license. Modified: 18 March 2013 Author: John Burkardt */ { # define N 5 double *a; double complex *lambda; int seed = 123456789; printf ( "\n" ); printf ( "R8CI_EVAL_TEST\n" ); printf ( " R8CI_EVAL finds the eigenvalues of an R8CI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", N ); /* Set the matrix. */ a = r8ci_random ( N, &seed ); r8ci_print ( N, a, " The circulant matrix:" ); lambda = r8ci_eval ( N, a ); c8vec_print ( N, lambda, " The eigenvalues:" ); free ( a ); free ( lambda ); return; # undef N } /******************************************************************************/ void r8ci_indicator_test ( ) /******************************************************************************/ /* Purpose: R8CI_INDICATOR_TEST tests R8CI_INDICATOR. Licensing: This code is distributed under the MIT license. Modified: 18 March 2013 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8CI_INDICATOR_TEST\n" ); printf ( " R8CI_INDICATOR sets up an R8CI indicator matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_indicator ( n ); r8ci_print ( n, a, " The R8CI matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ci_mtv_test ( ) /******************************************************************************/ /* Purpose: R8CI_MTV_TEST tests R8CI_MTV. Licensing: This code is distributed under the MIT license. Modified: 17 June 2016 Author: John Burkardt */ { double *a; double *b; double *x; int n = 5; printf ( "\n" ); printf ( "R8CI_MTV_TEST\n" ); printf ( " R8CI_MTV computes b=A'*x, where A is an R8CI indicator matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_indicator ( n ); r8ci_print ( n, a, " The R8CI matrix:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector x:" ); b = r8ci_mtv ( n, a, x ); r8vec_print ( n, b, " The product b=A'*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ci_mv_test ( ) /******************************************************************************/ /* Purpose: R8CI_MV_TEST tests R8CI_MV. Licensing: This code is distributed under the MIT license. Modified: 17 June 2016 Author: John Burkardt */ { double *a; double *b; double *x; int n = 5; printf ( "\n" ); printf ( "R8CI_MV_TEST\n" ); printf ( " R8CI_MV computes b=A*x, where A is an R8CI indicator matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_indicator ( n ); r8ci_print ( n, a, " The R8CI matrix:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector x:" ); b = r8ci_mv ( n, a, x ); r8vec_print ( n, b, " The product b=A*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ci_print_test ( ) /******************************************************************************/ /* Purpose: R8CI_PRINT_TEST tests R8CI_PRINT. Licensing: This code is distributed under the MIT license. Modified: 18 March 2013 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8CI_PRINT_TEST\n" ); printf ( " R8CI_PRINT prints an R8CI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_indicator ( n ); r8ci_print ( n, a, " The R8CI matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ci_print_some_test ( ) /******************************************************************************/ /* Purpose: R8CI_PRINT_SOME_TEST tests R8CI_PRINT_SOME. Licensing: This code is distributed under the MIT license. Modified: 17 June 2016 Author: John Burkardt */ { double *a; int n = 10; printf ( "\n" ); printf ( "R8CI_PRINT_SOME_TEST\n" ); printf ( " R8CI_PRINT_SOME prints some of an R8CI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_indicator ( n ); r8ci_print_some ( n, a, 1, 2, 5, 4, " Rows 1-5, Cols 2-4:" ); free ( a ); return; } /******************************************************************************/ void r8ci_sl_test ( ) /******************************************************************************/ /* Purpose: R8CI_SL_TEST tests R8CI_SL. Licensing: This code is distributed under the MIT license. Modified: 19 March 2013 Author: John Burkardt */ { double *a; double *b; int job; int n = 10; int seed = 123456789; double *x; printf ( "\n" ); printf ( "R8CI_SL_TEST\n" ); printf ( " R8CI_SL solves a linear system with an R8CI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); /* Set the matrix. */ a = r8ci_random ( n, &seed ); r8ci_print ( n, a, " The circulant matrix:" ); for ( job = 0; job <= 1; job++ ) { /* Set the desired solution. */ x = r8vec_indicator1_new ( n ); /* Compute the corresponding right hand side. */ if ( job == 0 ) { b = r8ci_mv ( n, a, x ); } else { b = r8ci_mtv ( n, a, x ); } /* Solve the linear system. */ free ( x ); x = r8ci_sl ( n, a, b, job ); if ( job == 0 ) { r8vec_print ( n, x, " Solution to A*x=b:" ); } else { r8vec_print ( n, x, " Solution to A'*x=b:" ); } free ( b ); free ( x ); } free ( a ); return; } /******************************************************************************/ void r8ci_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8CI_TO_R8GE_TEST tests R8CI_TO_R8GE. Licensing: This code is distributed under the MIT license. Modified: 17 June 2016 Author: John Burkardt */ { double *a; double *a_r8ge; int n = 5; printf ( "\n" ); printf ( "R8CI_TO_R8GE_TEST\n" ); printf ( " R8CI_TO_R8GE converts an R8CI matrix to R8GE format.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_indicator ( n ); r8ci_print ( n, a, " The R8CI matrix:" ); a_r8ge = r8ci_to_r8ge ( n, a ); r8ge_print ( n, n, a_r8ge, " The R8GE matrix:" ); free ( a ); free ( a_r8ge ); return; } /******************************************************************************/ void r8ci_zeros_test ( ) /******************************************************************************/ /* Purpose: R8CI_ZEROS_TEST tests R8CI_ZEROS. Licensing: This code is distributed under the MIT license. Modified: 17 June 2017 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8CI_ZEROS_TEST\n" ); printf ( " R8CI_ZEROS sets up a zero R8CI matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ci_zeros ( n ); r8ci_print ( n, a, " The R8CI matrix:" ); free ( a ); return; } /******************************************************************************/ 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 }