# include # include # include # include # include # include "test_eigen.h" int main ( ); void r8nsymm_gen_test ( ); void r8symm_gen_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: test_eigen_test() tests test_eigen(). Licensing: This code is distributed under the MIT license. Modified: 09 March 2018 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "test_eigen_test():\n" ); printf ( " C version\n" ); printf ( " Test test_eigen().\n" ); r8symm_gen_test ( ); r8nsymm_gen_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "test_eigen_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void r8symm_gen_test ( ) /******************************************************************************/ /* Purpose: r8symm_gen_test() tests r8symm_gen(). Licensing: This code is distributed under the MIT license. Modified: 05 June 2024 Author: John Burkardt */ { double *A; double *aq; int i; int j; double *lambda; double *lambda2; double lambda_dev = 5.0; double lambda_mean = 10.0; int n = 5; double *Q; int seed = 123456789; printf ( "\n" ); printf ( "r8symm_gen_test():\n" ); printf ( " r8symm_gen() generates an arbitrary size symmetric matrix\n" ); printf ( " with known eigenvalues and eigenvectors.\n" ); A = ( double * ) malloc ( n * n * sizeof ( double ) ); Q = ( double * ) malloc ( n * n * sizeof ( double ) ); lambda = ( double * ) malloc ( n * sizeof ( double ) ); r8symm_gen ( n, lambda_mean, lambda_dev, &seed, A, Q, lambda ); r8mat_print ( n, n, A, " The matrix A:" ); r8mat_print ( n, n, Q, " The eigenvector matrix Q:" ); r8vec_print ( n, lambda, " The eigenvalue vector LAMBDA:" ); aq = r8mat_mm_new ( n, n, n, A, Q ); lambda2 = ( double * ) malloc ( n * sizeof ( double ) ); for ( j = 0; j < n; j++ ) { lambda2[j] = 0.0; for ( i = 0; i < n; i++ ) { lambda2[j] = lambda2[j] + pow ( aq[i+j*n], 2 ); } lambda2[j] = sqrt ( lambda2[j] ); } r8vec2_print ( n, lambda, lambda2, " LAMBDA versus the column norms of A*Q:" ); /* Free memory. */ free ( A ); free ( aq ); free ( lambda ); free ( lambda2 ); free ( Q ); return; } /******************************************************************************/ void r8nsymm_gen_test ( ) /******************************************************************************/ /* Purpose: r8nsymm_gen_test() tests r8nsymm_gen(). Licensing: This code is distributed under the MIT license. Modified: 04 June 2024 Author: John Burkardt */ { double *A; int i; double *lambda; double lambda_dev = 5.0; double lambda_mean = 10.0; int n = 5; double *Q; int seed = 123456789; double *T; printf ( "\n" ); printf ( "r8nsymm_gen_test():\n" ); printf ( " r8nsymm_gen() generates an arbitrary size nonsymmetric matrix\n" ); printf ( " with known eigenvalues and eigenvectors.\n" ); A = ( double * ) malloc ( n * n * sizeof ( double ) ); Q = ( double * ) malloc ( n * n * sizeof ( double ) ); T = ( double * ) malloc ( n * n * sizeof ( double ) ); r8nsymm_gen ( n, lambda_mean, lambda_dev, &seed, A, Q, T ); lambda = ( double * ) malloc ( n * sizeof ( double ) ); for ( i = 0; i < n; i++ ) { lambda[i] = T[i+i*n]; } r8vec_sort_bubble_a ( n, lambda ); r8mat_print ( n, n, A, " The matrix A:" ); r8mat_print ( n, n, Q, " The orthogonal factor Q:" ); r8mat_print ( n, n, T, " The upper triangular T:" ); r8vec_print ( n, lambda, " The eigenvalue vector LAMBDA:" ); /* Free memory. */ free ( A ); free ( lambda ); free ( Q ); free ( T ); 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 ); fprintf ( stdout, "%s\n", time_buffer ); return; # undef TIME_SIZE }