Tue Oct 19 12:00:28 2021 matrix_exponential_test Python version: 3.6.9 Test the matrix_exponential library. This test needs the test_matrix_exponential library. matrix_exponential_test01: r8mat_expm1 is an equivalent to EXPM r8mat_expm2 uses a Taylor series approach r8mat_expm3 relies on an eigenvalue calculation. Test #1 This matrix is diagonal. The calculation of the matrix exponential is simple. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 1 0 1 : 0 2 r8mat_expM1(A): Col: 0 1 Row 0 : 2.71828 0 1 : 0 7.38906 r8mat_expM2(A): Col: 0 1 Row 0 : 2.71828 0 1 : 0 7.38906 r8mat_expM3(A): Col: 0 1 Row 0 : 2.71828 0 1 : 0 7.38906 Exact Exponential: Col: 0 1 Row 0 : 2.71828 0 1 : 0 7.38906 Test #2 This matrix is symmetric. The calculation of the matrix exponential is straightforward. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 1 3 1 : 3 2 r8mat_expM1(A): Col: 0 1 Row 0 : 39.3228 46.1663 1 : 46.1663 54.7116 r8mat_expM2(A): Col: 0 1 Row 0 : 39.3228 46.1663 1 : 46.1663 54.7116 r8mat_expM3(A): Col: 0 1 Row 0 : 39.3228 46.1663 1 : 46.1663 54.7116 Exact Exponential: Col: 0 1 Row 0 : 39.3228 46.1663 1 : 46.1663 54.7116 Test #3 This example is due to Laub. This matrix is ill-suited for the Taylor series approach. As powers of A are computed, the entries blow up too quickly. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 0 -39 1 : 1 -40 r8mat_expM1(A): Col: 0 1 Row 0 : 0.37756 -0.37756 1 : 0.00968104 -0.00968104 r8mat_expM2(A): Col: 0 1 Row 0 : 0.371409 -0.267244 1 : 0.0120339 0.232756 r8mat_expM3(A): Col: 0 1 Row 0 : 0.37756 -0.37756 1 : 0.00968104 -0.00968104 Exact Exponential: Col: 0 1 Row 0 : 0.37756 -0.37756 1 : 0.00968104 -0.00968104 Test #4 This example is due to Moler and Van Loan. The example will cause problems for the series summation approach, as well as for diagonal Pade approximations. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : -49 -64 1 : 24 31 r8mat_expM1(A): Col: 0 1 Row 0 : -0.735759 -1.47152 1 : 0.551819 1.10364 r8mat_expM2(A): Col: 0 1 Row 0 : -0.735759 -1.47152 1 : 0.551819 1.10364 r8mat_expM3(A): Col: 0 1 Row 0 : -0.735759 -1.47152 1 : 0.551819 1.10364 Exact Exponential: Col: 0 1 Row 0 : -0.735759 -1.47152 1 : 0.551819 1.10364 Test #5 This example is due to Moler and Van Loan. This matrix is strictly upper triangular All powers of A are zero beyond some (low) limit. This example will cause problems for Pade approximations. Matrix order N = 4 Matrix: Col: 0 1 2 3 Row 0 : 0 0 0 0 1 : 6 0 0 0 2 : 0 6 0 0 3 : 0 0 6 0 r8mat_expM1(A): Col: 0 1 2 3 Row 0 : 1 0 0 0 1 : 6 1 0 0 2 : 18 6 1 0 3 : 36 18 6 1 r8mat_expM2(A): Col: 0 1 2 3 Row 0 : 1 0 0 0 1 : 6 1 0 0 2 : 18 6 1 0 3 : 36 18 6 1 r8mat_expM3(A): Col: 0 1 2 3 Row 0 : 0 0 0 0 1 : 0 0 0 0 2 : 0 0 0 -5.01042e-293 3 : 0 0 -5.01042e-293 1 Exact Exponential: Col: 0 1 2 3 Row 0 : 1 0 0 0 1 : 6 1 0 0 2 : 18 6 1 0 3 : 36 18 6 1 Test #6 This example is due to Moler and Van Loan. This matrix does not have a complete set of eigenvectors. That means the eigenvector approach will fail. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 1 0 1 : 1 1 r8mat_expM1(A): Col: 0 1 Row 0 : 2.71828 0 1 : 2.71828 2.71828 r8mat_expM2(A): Col: 0 1 Row 0 : 2.71828 0 1 : 2.71828 2.71828 r8mat_expM3(A): Col: 0 1 Row 0 : 3.35054e-32 -3.0179e-16 1 : -3.0179e-16 2.71828 Exact Exponential: Col: 0 1 Row 0 : 2.71828 0 1 : 2.71828 2.71828 Test #7 This example is due to Moler and Van Loan. This matrix is very close to example 5. Mathematically, it has a complete set of eigenvectors. Numerically, however, the calculation will be suspect. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 1 0 1 : 1 1 r8mat_expM1(A): Col: 0 1 Row 0 : 2.71828 0 1 : 2.71828 2.71828 r8mat_expM2(A): Col: 0 1 Row 0 : 2.71828 0 1 : 2.71828 2.71828 r8mat_expM3(A): Col: 0 1 Row 0 : 1.34022e-31 6.0358e-16 1 : 6.0358e-16 2.71828 Exact Exponential: Col: 0 1 Row 0 : 2.71828 0 1 : 2.71828 2.71828 Test #8 This matrix was an example in Wikipedia. Matrix order N = 3 Matrix: Col: 0 1 2 Row 0 : 21 -5 4 1 : 17 -1 4 2 : 6 -6 16 r8mat_expM1(A): Col: 0 1 2 Row 0 : 2.8877e+07 -1.99915e+07 3.55403e+07 1 : 2.8877e+07 -1.99914e+07 3.55403e+07 2 : 4.44275e+06 -4.44275e+06 8.88554e+06 r8mat_expM2(A): Col: 0 1 2 Row 0 : 2.88798e+07 -1.99937e+07 3.55444e+07 1 : 2.88798e+07 -1.99937e+07 3.55444e+07 2 : 4.44303e+06 -4.44303e+06 8.88611e+06 r8mat_expM3(A): Col: 0 1 2 Row 0 : 2.88798e+07 -1.99937e+07 3.55444e+07 1 : 2.88798e+07 -1.99937e+07 3.55444e+07 2 : 4.44303e+06 -4.44303e+06 8.88611e+06 Exact Exponential: Col: 0 1 2 Row 0 : 2.88798e+07 -1.99937e+07 3.55444e+07 1 : 2.88798e+07 -1.99937e+07 3.55444e+07 2 : 4.44303e+06 -4.44303e+06 8.88611e+06 Test #9 This example is due to the NAG Library. It is an example for function F01ECF. Matrix order N = 4 Matrix: Col: 0 1 2 3 Row 0 : 1 3 3 3 1 : 2 1 2 3 2 : 2 1 1 3 3 : 2 2 2 1 r8mat_expM1(A): Col: 0 1 2 3 Row 0 : 740.704 731.251 823.763 998.435 1 : 610.85 603.552 679.426 823.763 2 : 542.274 535.088 603.552 731.251 3 : 549.175 542.274 610.85 740.704 r8mat_expM2(A): Col: 0 1 2 3 Row 0 : 740.704 731.251 823.763 998.435 1 : 610.85 603.552 679.426 823.763 2 : 542.274 535.088 603.552 731.251 3 : 549.175 542.274 610.85 740.704 r8mat_expM3(A): Col: 0 1 2 3 Row 0 : 757.856 863.381 874.291 778.435 1 : 624.999 712.538 721.103 642.297 2 : 554.855 631.964 640.598 569.945 3 : 561.889 640.401 648.379 577.348 Exact Exponential: Col: 0 1 2 3 Row 0 : 740.704 731.251 823.763 998.436 1 : 610.85 603.552 679.426 823.763 2 : 542.274 535.088 603.552 731.251 3 : 549.175 542.274 610.85 740.704 Test #10 This is Ward's example #1. It is defective and nonderogatory. The eigenvalues are 3, 3 and 6. Matrix order N = 3 Matrix: Col: 0 1 2 Row 0 : 4 1 1 1 : 2 4 1 2 : 0 1 4 r8mat_expM1(A): Col: 0 1 2 Row 0 : 147.867 127.781 127.781 1 : 183.765 183.765 163.68 2 : 71.797 91.8826 111.968 r8mat_expM2(A): Col: 0 1 2 Row 0 : 147.867 127.781 127.781 1 : 183.765 183.765 163.68 2 : 71.797 91.8826 111.968 r8mat_expM3(A): Col: 0 1 2 Row 0 : 147.867 127.781 127.781 1 : 183.765 183.765 163.68 2 : 71.797 91.8826 111.968 Exact Exponential: Col: 0 1 2 Row 0 : 147.867 127.781 127.781 1 : 183.765 183.765 163.68 2 : 71.797 91.8826 111.968 Test #11 This is Ward's example #2. It is a symmetric matrix. The eigenvalues are 20, 30, 40. Matrix order N = 3 Matrix: Col: 0 1 2 Row 0 : 29.8794 0.781575 -2.28952 1 : 0.781575 25.7266 8.68074 2 : -2.28952 8.68074 34.394 r8mat_expM1(A): Col: 0 1 2 Row 0 : 6.69885e+12 6.49321e+11 -1.36553e+12 1 : 6.49321e+11 3.51588e+12 5.26861e+12 2 :-1.36553e+12 5.26861e+12 8.7281e+12 r8mat_expM2(A): Col: 0 1 2 Row 0 : 5.49631e+15 -1.82319e+16 -3.04758e+16 1 :-1.82319e+16 6.06052e+16 1.01292e+17 2 :-3.04758e+16 1.01292e+17 1.69294e+17 r8mat_expM3(A): Col: 0 1 2 Row 0 : 5.49631e+15 -1.82319e+16 -3.04758e+16 1 :-1.82319e+16 6.06052e+16 1.01292e+17 2 :-3.04758e+16 1.01292e+17 1.69294e+17 Exact Exponential: Col: 0 1 2 Row 0 : 5.49631e+15 -1.82319e+16 -3.04758e+16 1 :-1.82319e+16 6.06052e+16 1.01292e+17 2 :-3.04758e+16 1.01292e+17 1.69294e+17 Test #12 This is Ward's example #3. Ward's algorithm has difficulty estimating the accuracy of its results. The eigenvalues are -1, -2, -20. Matrix order N = 3 Matrix: Col: 0 1 2 Row 0 : -131 -390 -387 1 : 19 56 57 2 : 18 54 52 r8mat_expM1(A): Col: 0 1 2 Row 0 : -1.50964 -5.63257 -4.93494 1 : 0.367879 1.47152 1.10364 2 : 0.135335 0.406006 0.541341 r8mat_expM2(A): Col: 0 1 2 Row 0 : -1.50964 -5.63257 -4.93494 1 : 0.367879 1.47152 1.10364 2 : 0.135335 0.406006 0.541342 r8mat_expM3(A): Col: 0 1 2 Row 0 : -1.50964 -5.63257 -4.93494 1 : 0.367879 1.47152 1.10364 2 : 0.135335 0.406006 0.541341 Exact Exponential: Col: 0 1 2 Row 0 : -1.50964 -5.63257 -4.93494 1 : 0.367879 1.47152 1.10364 2 : 0.135335 0.406006 0.541341 Test #13 This is Ward's example #4. This is a version of the Forsythe matrix. The eigenvector problem is badly conditioned. Ward's algorithm has difficulty estimating the accuracy of its results for this problem. Matrix order N = 10 Matrix: Col: 0 1 2 3 4 Row 0 : 0 1 0 0 0 1 : 0 0 1 0 0 2 : 0 0 0 1 0 3 : 0 0 0 0 1 4 : 0 0 0 0 0 5 : 0 0 0 0 0 6 : 0 0 0 0 0 7 : 0 0 0 0 0 8 : 0 0 0 0 0 9 : 1e-10 0 0 0 0 Col: 5 6 7 8 9 Row 0 : 0 0 0 0 0 1 : 0 0 0 0 0 2 : 0 0 0 0 0 3 : 0 0 0 0 0 4 : 1 0 0 0 0 5 : 0 1 0 0 0 6 : 0 0 1 0 0 7 : 0 0 0 1 0 8 : 0 0 0 0 1 9 : 0 0 0 0 0 r8mat_expM1(A): Col: 0 1 2 3 4 Row 0 : 1 1 0.5 0.166667 0.0416667 1 : 2.75573e-16 1 1 0.5 0.166667 2 : 2.48016e-15 2.75573e-16 1 1 0.5 3 : 1.98413e-14 2.48016e-15 2.75573e-16 1 1 4 : 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 1 5 : 8.33333e-13 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 6 : 4.16667e-12 8.33333e-13 1.38889e-13 1.98413e-14 2.48016e-15 7 : 1.66667e-11 4.16667e-12 8.33333e-13 1.38889e-13 1.98413e-14 8 : 5e-11 1.66667e-11 4.16667e-12 8.33333e-13 1.38889e-13 9 : 1e-10 5e-11 1.66667e-11 4.16667e-12 8.33333e-13 Col: 5 6 7 8 9 Row 0 : 0.00833333 0.00138889 0.000198413 2.48016e-05 2.75573e-06 1 : 0.0416667 0.00833333 0.00138889 0.000198413 2.48016e-05 2 : 0.166667 0.0416667 0.00833333 0.00138889 0.000198413 3 : 0.5 0.166667 0.0416667 0.00833333 0.00138889 4 : 1 0.5 0.166667 0.0416667 0.00833333 5 : 1 1 0.5 0.166667 0.0416667 6 : 2.75573e-16 1 1 0.5 0.166667 7 : 2.48016e-15 2.75573e-16 1 1 0.5 8 : 1.98413e-14 2.48016e-15 2.75573e-16 1 1 9 : 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 1 r8mat_expM2(A): Col: 0 1 2 3 4 Row 0 : 1 1 0.5 0.166667 0.0416667 1 : 2.75573e-16 1 1 0.5 0.166667 2 : 2.48016e-15 2.75573e-16 1 1 0.5 3 : 1.98413e-14 2.48016e-15 2.75573e-16 1 1 4 : 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 1 5 : 8.33333e-13 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 6 : 4.16667e-12 8.33333e-13 1.38889e-13 1.98413e-14 2.48016e-15 7 : 1.66667e-11 4.16667e-12 8.33333e-13 1.38889e-13 1.98413e-14 8 : 5e-11 1.66667e-11 4.16667e-12 8.33333e-13 1.38889e-13 9 : 1e-10 5e-11 1.66667e-11 4.16667e-12 8.33333e-13 Col: 5 6 7 8 9 Row 0 : 0.00833333 0.00138889 0.000198413 2.48016e-05 2.75573e-06 1 : 0.0416667 0.00833333 0.00138889 0.000198413 2.48016e-05 2 : 0.166667 0.0416667 0.00833333 0.00138889 0.000198413 3 : 0.5 0.166667 0.0416667 0.00833333 0.00138889 4 : 1 0.5 0.166667 0.0416667 0.00833333 5 : 1 1 0.5 0.166667 0.0416667 6 : 2.75573e-16 1 1 0.5 0.166667 7 : 2.48016e-15 2.75573e-16 1 1 0.5 8 : 1.98413e-14 2.48016e-15 2.75573e-16 1 1 9 : 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 1 r8mat_expM3(A): Col: 0 1 2 3 4 Row 0 : 1.0025 1.00125 0.250208 0.0416927 0.00521085 1 : 0.00500625 1.00375 0.500834 0.12513 0.0208495 2 : 1.25104e-05 0.00500834 1.0025 0.500625 0.125118 3 : 2.08464e-08 1.2513e-05 0.00500625 1.0025 0.500784 4 : 2.60569e-11 2.08516e-08 1.2513e-05 0.00500834 1.00365 5 : 5.2105e-14 5.21137e-11 4.16927e-08 2.50208e-05 0.0100115 6 : 2.60569e-13 2.08516e-10 1.2513e-07 5.00834e-05 0.0100365 7 : 2.08464e-12 1.2513e-09 5.00625e-07 0.00010025 5.00784e-05 8 : 1.25104e-11 5.00834e-09 1.0025e-06 5.00625e-07 1.25118e-07 9 : 5.00625e-11 1.00375e-08 5.00834e-09 1.2513e-09 2.08495e-10 Col: 5 6 7 8 9 Row 0 : 0.00052105 5.21085e-05 4.16927e-06 2.50208e-07 1.00125e-08 1 : 0.00260569 0.000208495 1.2513e-05 5.00834e-07 1.00375e-08 2 : 0.0208464 0.00125118 5.00625e-05 1.0025e-06 5.00834e-11 3 : 0.125104 0.00500784 0.00010025 5.00625e-09 1.2513e-13 4 : 0.500625 0.0100365 5.00834e-07 1.2513e-11 2.08525e-16 5 : 1.0025 0.000100115 2.50208e-09 4.16938e-14 4.78663e-19 6 : 0.00500625 0.000100365 5.00834e-09 1.2513e-13 2.08527e-18 7 : 1.25104e-05 5.00784e-07 1.0025e-08 5.00625e-13 1.2513e-17 8 : 2.08464e-08 1.25118e-09 5.00625e-11 1.0025e-12 5.00834e-17 9 : 2.60569e-11 2.08495e-12 1.2513e-13 5.00834e-15 1.00375e-16 Exact Exponential: Col: 0 1 2 3 4 Row 0 : 1 1 0.5 0.166667 0.0416667 1 : 2.75573e-16 1 1 0.5 0.166667 2 : 2.48016e-15 2.75573e-16 1 1 0.5 3 : 1.98413e-14 2.48016e-15 2.75573e-16 1 1 4 : 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 1 5 : 8.33333e-13 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 6 : 4.16667e-12 8.33333e-13 1.38889e-13 1.98413e-14 2.48016e-15 7 : 1.66667e-11 4.16667e-12 8.33333e-13 1.38889e-13 1.98413e-14 8 : 5e-11 1.66667e-11 4.16667e-12 8.33333e-13 1.38889e-13 9 : 1e-10 5e-11 1.66667e-11 4.16667e-12 8.33333e-13 Col: 5 6 7 8 9 Row 0 : 0.00833333 0.00138889 0.000198413 2.48016e-05 2.75573e-06 1 : 0.0416667 0.00833333 0.00138889 0.000198413 2.48016e-05 2 : 0.166667 0.0416667 0.00833333 0.00138889 0.000198413 3 : 0.5 0.166667 0.0416667 0.00833333 0.00138889 4 : 1 0.5 0.166667 0.0416667 0.00833333 5 : 1 1 0.5 0.166667 0.0416667 6 : 2.75573e-16 1 1 0.5 0.166667 7 : 2.48016e-15 2.75573e-16 1 1 0.5 8 : 1.98413e-14 2.48016e-15 2.75573e-16 1 1 9 : 1.38889e-13 1.98413e-14 2.48016e-15 2.75573e-16 1 Test #14 This is Moler's example. This badly scaled matrix caused problems for MATLABs expm(). Matrix order N = 3 Matrix: Col: 0 1 2 Row 0 : 0 -2.00667e+10 66.6667 1 : 1e-08 -3 0 2 : 0 2e+10 -66.6667 r8mat_expM1(A): Col: 0 1 2 Row 0 : 0.446849 -5.74307e+06 0.447723 1 : 1.54044e-09 -0.015283 1.5427e-09 2 : 0.462811 -4.52654e+06 0.463481 r8mat_expM2(A): Col: 0 1 2 Row 0 : 1.26877e+09 6.28159e+18 1.02238e+11 1 : -0.108695 1.27273e+08 13.5195 2 :-6.24778e+07 -4.93546e+17 3.51658e+10 r8mat_expM3(A): Col: 0 1 2 Row 0 : 0.446849 -5.74307e+06 0.447723 1 : 1.54044e-09 -0.015283 1.5427e-09 2 : 0.462811 -4.52654e+06 0.463481 Exact Exponential: Col: 0 1 2 Row 0 : 0.446849 -5.74307e+06 0.447723 1 : 1.54044e-09 -0.015283 1.5427e-09 2 : 0.462811 -4.52654e+06 0.463481 matrix_exponential_test02: expm is MATLAB's matrix exponential function c8mat_expm1 is an equivalent to EXPM c8mat_expm2 uses a Taylor series approach c8mat_expm3 relies on an eigenvalue calculation. Test #1 This matrix is diagonal. The diagonal entries are real. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 1 0i 0 0i 1 : 0 0i 2 0i c8mat_expM1(A): Col: 0 1 Row 0 : 2.71828 0i 0 0i 1 : 0 0i 7.38906 0i Exact Exponential: Col: 0 1 Row 0 : 2.71828 0i 0 0i 1 : 0 0i 7.38906 0i Test #2 This matrix is diagonal. The diagonal entries are pure imaginary. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 0 3i 0 0i 1 : 0 0i -0 -4i c8mat_expM1(A): Col: 0 1 Row 0 : -0.989992 0.14112i 0 0i 1 : 0 0i -0.653644 0.756802i Exact Exponential: Col: 0 1 Row 0 : -0.989992 0.14112i 0 0i 1 : 0 0i -0.653644 0.756802i Test #3 This matrix is diagonal. The diagonal entries are complex. Matrix order N = 2 Matrix: Col: 0 1 Row 0 : 5 6i 0 0i 1 : 0 0i 7 -8i c8mat_expM1(A): Col: 0 1 Row 0 : 142.502 -41.4689i 0 0i 1 : 0 0i -159.56 -1084.96i Exact Exponential: Col: 0 1 Row 0 : 142.502 -41.4689i 0 0i 1 : 0 0i -159.56 -1084.96i matrix_exponential_test: Normal end of execution. Tue Oct 19 12:00:28 2021