# include # include # include # include # include "r8ltt.h" int main ( ); void r8ltt_det_test ( ); void r8ltt_indicator_test ( ); void r8ltt_inverse_test ( ); void r8ltt_mm_test ( ); void r8ltt_mtm_test ( ); void r8ltt_mtv_test ( ); void r8ltt_mv_test ( ); void r8ltt_print_test ( ); void r8ltt_print_some_test ( ); void r8ltt_random_test ( ); void r8ltt_sl_test ( ); void r8ltt_slt_test ( ); void r8ltt_to_r8ge_test ( ); void r8ltt_zeros_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: r8ltt_test() tests r8ltt(). Licensing: This code is distributed under the MIT license. Modified: 23 August 2022 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "r8ltt_test():\n" ); printf ( " C version\n" ); printf ( " Test r8ltt().\n" ); r8ltt_det_test ( ); r8ltt_indicator_test ( ); r8ltt_inverse_test ( ); r8ltt_mm_test ( ); r8ltt_mtm_test ( ); r8ltt_mtv_test ( ); r8ltt_mv_test ( ); r8ltt_print_test ( ); r8ltt_print_some_test ( ); r8ltt_random_test ( ); r8ltt_sl_test ( ); r8ltt_slt_test ( ); r8ltt_to_r8ge_test ( ); r8ltt_zeros_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "r8ltt_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8ltt_det_test ( ) /******************************************************************************/ /* Purpose: R8LTT_DET_TEST tests R8LTT_DET. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; double det; int n = 5; int seed = 123456789; printf ( "\n" ); printf ( "R8LTT_DET_TEST\n" ); printf ( " R8LTT_DET computes the determinant of an R8LTT matrix.\n" ); a = r8ltt_random ( n, &seed ); r8ltt_print ( n, a, " The matrix A:" ); /* Compute the determinant. */ det = r8ltt_det ( n, a ); printf ( "\n" ); printf ( " Determinant is %g\n", det ); free ( a ); return; } /******************************************************************************/ void r8ltt_indicator_test ( ) /******************************************************************************/ /* Purpose: R8LTT_INDICATOR_TEST tests R8LTT_INDICATOR. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8LTT_INDICATOR_TEST\n" ); printf ( " R8LTT_INDICATOR sets up an indicator matrix in R8LTT format\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ltt_indicator ( n ); r8ltt_print ( n, a, " The indicator matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ltt_inverse_test ( ) /******************************************************************************/ /* Purpose: R8LTT_INVERSE_TEST tests R8LTT_INVERSE. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; double *b; double *c; int n = 5; int seed; seed = 123456789; printf ( "\n" ); printf ( "R8LTT_INVERSE_TEST\n" ); printf ( " R8LTT_INVERSE computes the inverse of an R8LTT matrix.\n" ); a = r8ltt_random ( n, &seed ); r8ltt_print ( n, a, " The matrix A:" ); /* Compute the inverse matrix B. */ b = r8ltt_inverse ( n, a ); r8ltt_print ( n, b, " The inverse matrix B:" ); /* Check */ c = r8ltt_mm ( n, a, b ); r8ltt_print ( n, c, " The product A * B:" ); free ( a ); free ( b ); free ( c ); return; } /******************************************************************************/ void r8ltt_mm_test ( ) /******************************************************************************/ /* Purpose: R8LTT_MM_TEST tests R8LTT_MM. Licensing: This code is distributed under the MIT license. Modified: 19 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 ( "R8LTT_MM_TEST\n" ); printf ( " R8LTT_MM computes C = A * B for R8LTT matrices.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); seed = 123456789; a = r8ltt_random ( n, &seed ); r8ltt_print ( n, a, " Factor A:" ); b = r8ltt_random ( n, &seed ); r8ltt_print ( n, b, " Factor B:" ); c = r8ltt_mm ( n, a, b ); r8ltt_print ( n, c, " The product C = A * B" ); a_ge = r8ltt_to_r8ge ( n, a ); b_ge = r8ltt_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 r8ltt_mtm_test ( ) /******************************************************************************/ /* Purpose: R8LTT_MTM_TEST tests R8LTT_MTM. Licensing: This code is distributed under the MIT license. Modified: 19 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 ( "R8LTT_MTM_TEST\n" ); printf ( " R8LTT_MTM computes C = A' * B for R8LTT matrices.\n" ); a = r8ltt_random ( n, &seed ); r8ltt_print ( n, a, " The matrix A:" ); b = r8ltt_random ( n, &seed ); r8ltt_print ( n, b, " The matrix B:" ); c_ge = r8ltt_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 = r8ltt_to_r8ge ( n, a ); b_ge = r8ltt_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 r8ltt_mtv_test ( ) /******************************************************************************/ /* Purpose: R8LTT_MTV_TEST tests R8LTT_MTV. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; double *x; printf ( "\n" ); printf ( "R8LTT_MTV_TEST\n" ); printf ( " R8LTT_MTV computes a matrix product b=A'*x for an R8LTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ltt_indicator ( n ); r8ltt_print ( n, a, " The matrix A:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " The vector X:" ); b = r8ltt_mtv ( n, a, x ); r8vec_print ( n, b, " The vector b=A'*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ltt_mv_test ( ) /******************************************************************************/ /* Purpose: R8LTT_MV_TEST tests R8LTT_MV Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; double *x; printf ( "\n" ); printf ( "R8LTT_MV_TEST\n" ); printf ( " R8LTT_MV computes a product b=A*x for an R8LTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ltt_indicator ( n ); r8ltt_print ( n, a, " The R8LTT matrix A:" ); x = r8vec_indicator1_new ( n ); r8vec_print ( n, x, " Vector x:" ); b = r8ltt_mv ( n, a, x ); r8vec_print ( n, b, " Vector b = A*x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ltt_print_test ( ) /******************************************************************************/ /* Purpose: R8LTT_PRINT_TEST tests R8LTT_PRINT. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8LTT_PRINT_TEST\n" ); printf ( " R8LTT_PRINT prints an R8LTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ltt_indicator ( n ); r8ltt_print ( n, a, " The matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ltt_print_some_test ( ) /******************************************************************************/ /* Purpose: R8LTT_PRINT_SOME_TEST tests R8LTT_PRINT_SOME. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8LTT_PRINT_SOME_TEST\n" ); printf ( " R8LTT_PRINT_SOME prints some of an R8LTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ltt_indicator ( n ); r8ltt_print_some ( n, a, 1, 0, 4, 3, " Some of the matrix:" ); free ( a ); return; } /******************************************************************************/ void r8ltt_random_test ( ) /******************************************************************************/ /* Purpose: R8LTT_RANDOM_TEST tests R8LTT_RANDOM. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; int n; int seed; n = 5; seed = 123456789; printf ( "\n" ); printf ( "R8LTT_RANDOM_TEST\n" ); printf ( " R8LTT_RANDOM randomizes an R8LTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ltt_random ( n, &seed ); r8ltt_print ( n, a, " Matrix A:" ); free ( a ); return; } /******************************************************************************/ void r8ltt_sl_test ( ) /******************************************************************************/ /* Purpose: R8LTT_SL_TEST tests R8LTT_SL. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; int seed; double *x; printf ( "\n" ); printf ( "R8LTT_SL_TEST\n" ); printf ( " R8LTT_SL solves a linear system A*x=b with R8LTT matrix\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); seed = 123456789; a = r8ltt_random ( n, &seed ); r8ltt_print ( n, a, " Matrix A:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( n ); /* Compute the corresponding right hand side. */ b = r8ltt_mv ( n, a, x ); r8vec_print ( n, b, " Right hand side b:" ); /* Solve the linear system. */ x = r8ltt_sl ( n, a, b ); r8vec_print ( n, x, " Solution x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ltt_slt_test ( ) /******************************************************************************/ /* Purpose: R8LTT_SLT_TEST tests R8LTT_SLT. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; double *b; int n = 5; int seed; double *x; printf ( "\n" ); printf ( "R8LTT_SLT_TEST\n" ); printf ( " R8LTT_SLT solves a linear system A'x=b with R8LTT matrix\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); seed = 123456789; a = r8ltt_random ( n, &seed ); r8ltt_print ( n, a, " Matrix A:" ); /* Set the desired solution. */ x = r8vec_indicator1_new ( n ); /* Compute the corresponding right hand side. */ b = r8ltt_mtv ( n, a, x ); r8vec_print ( n, b, " Right hand side b:" ); /* Solve the linear system. */ x = r8ltt_slt ( n, a, b ); r8vec_print ( n, x, " Solution x:" ); free ( a ); free ( b ); free ( x ); return; } /******************************************************************************/ void r8ltt_to_r8ge_test ( ) /******************************************************************************/ /* Purpose: R8LTT_TO_R8GE_TEST tests R8LTT_TO_R8GE. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a_ge; double *a_utt; int n; int seed; n = 5; seed = 123456789; printf ( "\n" ); printf ( "R8LTT_TO_R8GE_TEST\n" ); printf ( " R8LTT_TO_R8GE converts an R8LTT matrix to R8GE format.\n" ); a_utt = r8ltt_random ( n, &seed ); r8ltt_print ( n, a_utt, " R8LTT matrix:" ); a_ge = r8ltt_to_r8ge ( n, a_utt ); r8ge_print ( n, n, a_ge, " R8GE matrix" ); free ( a_ge ); free ( a_utt ); return; } /******************************************************************************/ void r8ltt_zeros_test ( ) /******************************************************************************/ /* Purpose: R8LTT_ZEROS_TEST tests R8LTT_ZEROS. Licensing: This code is distributed under the MIT license. Modified: 19 November 2015 Author: John Burkardt */ { double *a; int n = 5; printf ( "\n" ); printf ( "R8LTT_ZEROS_TEST\n" ); printf ( " R8LTT_ZEROS returns a zeroed out R8LTT matrix.\n" ); printf ( "\n" ); printf ( " Matrix order N = %d\n", n ); a = r8ltt_zeros ( n ); r8ltt_print ( n, a, " Matrix A:" ); 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 }