# include # include # include # include "r8utt.h" int main ( ); void r8utt_det_test ( ); void r8utt_indicator_test ( ); void r8utt_inverse_test ( ); void r8utt_mm_test ( ); void r8utt_mtm_test ( ); void r8utt_mtv_test ( ); void r8utt_mv_test ( ); void r8utt_print_test ( ); void r8utt_print_some_test ( ); void r8utt_random_test ( ); void r8utt_sl_test ( ); void r8utt_slt_test ( ); void r8utt_to_r8ge_test ( ); void r8utt_zeros_test ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: MAIN is the main program for R8UTT_TEST. Discussion: R8UTT_TEST tests the R8UTT library. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "R8UTT_TEST\n" ); printf ( " C version\n" ); printf ( " Test the R8UTT library.\n" ); r8utt_det_test ( ); r8utt_indicator_test ( ); r8utt_inverse_test ( ); r8utt_mm_test ( ); r8utt_mtm_test ( ); r8utt_mtv_test ( ); r8utt_mv_test ( ); r8utt_print_test ( ); r8utt_print_some_test ( ); r8utt_random_test ( ); r8utt_sl_test ( ); r8utt_slt_test ( ); r8utt_to_r8ge_test ( ); r8utt_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "R8UTT_TEST\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8utt_det_test ( ) /******************************************************************************/ /* Purpose: R8UTT_DET_TEST tests R8UTT_DET. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 November 2015 Author: John Burkardt */ { double *a; double det; int i; int j; int n = 5; int seed = 123456789; printf ( "\n" ); printf ( "R8UTT_DET_TEST\n" ); printf ( " R8UTT_DET computes the determinant of an R8UTT matrix.\n" ); a = r8utt_random ( n, &seed ); r8utt_print ( n, a, " The matrix A:" ); /* Compute the determinant. */ det = r8utt_det ( n, a ); printf ( "\n" ); printf ( " Determinant is %g\n", det ); free ( a ); return; } /******************************************************************************/ void r8utt_indicator_test ( ) /******************************************************************************/ /* Purpose: R8UTT_INDICATOR_TEST tests R8UTT_INDICATOR. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8UTT_INDICATOR_TEST\n" ); printf ( " R8UTT_INDICATOR sets up an indicator matrix in R8UTT format\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8utt_indicator ( n ); r8utt_print ( n, a, " The indicator matrix:" ); free ( a ); return; } /******************************************************************************/ void r8utt_inverse_test ( ) /******************************************************************************/ /* Purpose: R8UTT_INVERSE_TEST tests R8UTT_INVERSE. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; double *b; double *c; int n = 5; int seed; seed = 123456789; printf ( "\n" ); printf ( "R8UTT_INVERSE_TEST\n" ); printf ( " R8UTT_INVERSE computes the inverse of an R8UTT matrix.\n" ); a = r8utt_random ( n, &seed ); r8utt_print ( n, a, " The matrix A:" ); /* Compute the inverse matrix B. */ b = r8utt_inverse ( n, a ); r8utt_print ( n, b, " The inverse matrix B:" ); /* Check */ c = r8utt_mm ( n, a, b ); r8utt_print ( n, c, " The product A * B:" ); free ( a ); free ( b ); free ( c ); return; } /******************************************************************************/ void r8utt_mm_test ( ) /******************************************************************************/ /* Purpose: R8UTT_MM_TEST tests R8UTT_MM. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; double *a_ge; double *b; double *b_ge; double *c; double *c_ge; int n = 5; int seed; printf ( "\n" ); printf ( "R8UTT_MM_TEST\n" ); printf ( " R8UTT_MM computes C = A * B for R8UTT matrices.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); seed = 123456789; a = r8utt_random ( n, &seed ); r8utt_print ( n, a, " Factor A:" ); b = r8utt_random ( n, &seed ); r8utt_print ( n, b, " Factor B:" ); c = r8utt_mm ( n, a, b ); r8utt_print ( n, c, " The product C = A * B" ); a_ge = r8utt_to_r8ge ( n, a ); b_ge = r8utt_to_r8ge ( n, b ); c_ge = r8ge_mm ( n, a_ge, b_ge ); r8ge_print ( n, n, c_ge, " The R8GE product C:" ); free ( a ); free ( a_ge ); free ( b ); free ( b_ge ); free ( c ); free ( c_ge ); return; } /******************************************************************************/ void r8utt_mtm_test ( ) /******************************************************************************/ /* Purpose: R8UTT_MTM_TEST tests R8UTT_MTM. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; double *a_ge; double *b; double *b_ge; double *c_ge; int n = 5; int seed; seed = 123456789; printf ( "\n" ); printf ( "R8UTT_MTM_TEST\n" ); printf ( " R8UTT_MTM computes C = A' * B for R8UTT matrices.\n" ); a = r8utt_random ( n, &seed ); r8utt_print ( n, a, " The matrix A:" ); b = r8utt_random ( n, &seed ); r8utt_print ( n, b, " The matrix B:" ); c_ge = r8utt_mtm ( n, a, b ); r8ge_print ( n, n, c_ge, " The product C = A' * B:" ); free ( c_ge ); /* Compare with an R8GE calculation. */ a_ge = r8utt_to_r8ge ( n, a ); b_ge = r8utt_to_r8ge ( n, b ); c_ge = r8ge_mtm ( n, a_ge, b_ge ); r8ge_print ( n, n, c_ge, " The R8GE product C = A' * B:" ); free ( a ); free ( a_ge ); free ( b ); free ( b_ge ); free ( c_ge ); return; } /******************************************************************************/ void r8utt_mtv_test ( ) /******************************************************************************/ /* Purpose: R8UTT_MTV_TEST tests R8UTT_MTV. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; double *x; printf ( "\n" ); printf ( "R8UTT_MTV_TEST\n" ); printf ( " R8UTT_MTV computes a matrix product b=A'*x for an R8UTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8utt_indicator ( n ); r8utt_print ( n, a, " The matrix A:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector X:" ); b = r8utt_mtv ( n, a, x ); r8vec_print ( n, b, " The vector b=A'*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8utt_mv_test ( ) /******************************************************************************/ /* Purpose: R8UTT_MV_TEST tests R8UTT_MV Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; double *x; printf ( "\n" ); printf ( "R8UTT_MV_TEST\n" ); printf ( " R8UTT_MV computes a product b=A*x for an R8UTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8utt_indicator ( n ); r8utt_print ( n, a, " The R8UTT matrix A:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " Vector x:" ); b = r8utt_mv ( n, a, x ); r8vec_print ( n, b, " Vector b = A*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8utt_print_test ( ) /******************************************************************************/ /* Purpose: R8UTT_PRINT_TEST tests R8UTT_PRINT. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8UTT_PRINT_TEST\n" ); printf ( " R8UTT_PRINT prints an R8UTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8utt_indicator ( n ); r8utt_print ( n, a, " The matrix:" ); free ( a ); return; } /******************************************************************************/ void r8utt_print_some_test ( ) /******************************************************************************/ /* Purpose: R8UTT_PRINT_SOME_TEST tests R8UTT_PRINT_SOME. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8UTT_PRINT_SOME_TEST\n" ); printf ( " R8UTT_PRINT_SOME prints some of an R8UTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8utt_indicator ( n ); r8utt_print_some ( n, a, 1, 4, 3, 6, " Some of the matrix:" ); free ( a ); return; } /******************************************************************************/ void r8utt_random_test ( ) /******************************************************************************/ /* Purpose: R8UTT_RANDOM_TEST tests R8UTT_RANDOM. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 November 2015 Author: John Burkardt */ { double *a; int n; int seed; n = 5; seed = 123456789; printf ( "\n" ); printf ( "R8UTT_RANDOM_TEST\n" ); printf ( " R8UTT_RANDOM randomizes an R8UTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8utt_random ( n, &seed ); r8utt_print ( n, a, " Matrix A:" ); free ( a ); return; } /******************************************************************************/ void r8utt_sl_test ( ) /******************************************************************************/ /* Purpose: R8UTT_SL_TEST tests R8UTT_SL. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; int seed; double *x; printf ( "\n" ); printf ( "R8UTT_SL_TEST\n" ); printf ( " R8UTT_SL solves a linear system A*x=b with R8UTT matrix\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); seed = 123456789; a = r8utt_random ( n, &seed ); r8utt_print ( n, a, " Matrix A:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( n ); /* Compute the corresponding right hand side. */ b = r8utt_mv ( n, a, x ); r8vec_print ( n, b, " Right hand side b:" ); /* Solve the linear system. */ x = r8utt_sl ( n, a, b ); r8vec_print ( n, x, " Solution x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8utt_slt_test ( ) /******************************************************************************/ /* Purpose: R8UTT_SLT_TEST tests R8UTT_SLT. Licensing: This code is distributed under the GNU LGPL license. Modified: 16 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; int seed; double *x; printf ( "\n" ); printf ( "R8UTT_SLT_TEST\n" ); printf ( " R8UTT_SLT solves a linear system A'x=b with R8UTT matrix\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); seed = 123456789; a = r8utt_random ( n, &seed ); r8utt_print ( n, a, " Matrix A:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( n ); /* Compute the corresponding right hand side. */ b = r8utt_mtv ( n, a, x ); r8vec_print ( n, b, " Right hand side b:" ); /* Solve the linear system. */ x = r8utt_slt ( n, a, b ); r8vec_print ( n, x, " Solution x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8utt_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8UTT_TO_R8GE_TEST tests R8UTT_TO_R8GE. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 November 2015 Author: John Burkardt */ { double *a_ge; double *a_utt; int n; int seed; n = 5; seed = 123456789; printf ( "\n" ); printf ( "R8UTT_TO_R8GE_TEST\n" ); printf ( " R8UTT_TO_R8GE converts an R8UTT matrix to R8GE format.\n" ); a_utt = r8utt_random ( n, &seed ); r8utt_print ( n, a_utt, " R8UTT matrix:" ); a_ge = r8utt_to_r8ge ( n, a_utt ); r8ge_print ( n, n, a_ge, " R8GE matrix" ); free ( a_ge ); free ( a_utt ); return; } /******************************************************************************/ void r8utt_zeros_test ( ) /******************************************************************************/ /* Purpose: R8UTT_ZEROS_TEST tests R8UTT_ZEROS. Licensing: This code is distributed under the GNU LGPL license. Modified: 15 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8UTT_ZEROS_TEST\n" ); printf ( " R8UTT_ZEROS returns a zeroed out R8UTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8utt_zeros ( n ); r8utt_print ( n, a, " Matrix A:" ); free ( a ); return; }