# Computing the Matrix Logarithm with the Romberg Integration Method
## 3 Numerical Tests
The matrix logarithm of each matrix was computed _\"exactly\"_ according to this protocol, as described in [44]:  
* Compute the eigenvalues of each matrix \(A\) by means of the MATLAB functions vpa and eig. Consequently, matrices \(V\) and \(D\) will be provided, such that \(A=V\times D\times V^{-1}\). Each element of matrix \(D\) that is not strictly greater than 0 is substituted by the sum of its absolute value and a random positive numberless than \(1\), giving place to a new matrix \(\widetilde{D}\). If not, \(\widetilde{D}\) is equivalent to \(D\). Lastly, matrices \(\widetilde{A}=V\times\widetilde{D}\times V^{-1}\) and \(L_{1}=V\times\log(\widetilde{D})\times V^{-1}\) are generated;
2. Approximate the matrix logarithm via functions vpa and logm, i.e., \(L_{2}=logm(\widetilde{A})\);
3. Take into consideration matrix \(\widetilde{A}\), and consequently, its \"_exact_\" logarithm, only if it is satisfied that \[\frac{\left\|L_{1}-L_{2}\right\|_{2}}{\left\|L_{1}\right\|_{2}}\leq u.\]  
For the numerical tests, forty-seven matrices, forty from the MCT and seven from the EMP, were taken into account. The reasons for not considering the rest were as follows:  
* Matrices 17, 18, and 40 belonging to the MCT, and Matrices 7, 9, and 14 contained in the EMP did not successfully pass the above algorithm;
* Due to their ill-conditioning for the matrix logarithm function, the error committed by some of the codes was equal to or greater than 1 for Matrices 2, 4, 6, 9, 35, and 38 of the MCT, and Matrices 1, 4, and 20 of the EMP;
* The code logm_iss_full failed at runtime for Matrices 12, 16, and 26 included in the MCT, and Matrices 10, 15, and 18 incorporated in the EMP. The explanation for this is that the function sqrt_dbp exceeded the maximum number of iterations allowed in the product form of the Denman-Beavers iteration code, in charge of approximating the matrix square roots;
* Matrices 8, 11, 13, and 16 from the EMP are also incorporated in the MCT. The normwise relative error used to test the accuracy of the four codes previously described, hereinafter referred to as \(Er(A)\), was computed for each matrix \(A\) in our test bed as  
\[Er(A)=\frac{\left\|\log(A)-\widetilde{\log}(A)\right\|_{2}}{\left\|\log(A) \right\|_{2}},\]  
where \(\log(A)\) stands for the \"_exact_\" matrix algorithm and \(\widetilde{\log}(A)\) represents the approximate one. All the executions were run on a Microsoft Windows \(11\times 64\) PC equipped with an Intel Core i7-12700H processor and 32 GB of RAM, using MATLAB R2023a. Figures 1-3 show graphically the behavior of the different methods with respect to the matrices that composed each test set, respectively. In fact, Figures 1a-3a depict the normwise relative error \(Er(A)\) committed by all the codes when computing the logarithm of each matrix. The black solid line appearing in these graphs corresponds to function \(k_{log}\times u\), where \(k_{log}\) is the condition number of the logarithm function for each matrix and \(u\) is the unit roundoff. Approximately, the value of the function \(k_{log}*u\) is equivalent to the expected relative error for each matrix calculation. In this sense, it is well known that a code is more stable the closer its results are to these function values, and even more so if they are located below it, which is highly desirable. In view of these results, it seems clear that logm_romberg was the most stable code, generally providing the smallest relative errors. In the case of Set 3, the results of only forty matrices are represented in Figure 3a. The others (Matrices 19, 21, 23, 27, 51, and 52 of the MCT, and Matrix 17 of the EMP) were not considered due to the large condition number of our objective matrix function. These results are consistent with those reported in Table 2, which displays the percentages of matrices in which the relative error incurred by logm_romberg was lower or higher than those of the other codes.