Abstract
If the matrix function posses the properties of , then the recurrence formula , can be established. Here, . This provides an algorithm for computing the matrix function . By specifying the calculation accuracy p, a method is presented to determine m and N in a way that minimizes the time of the above algorithm, thus providing a fast algorithm for . It is important to note that m only depends on the calculation accuracy p and is independent of the matrix A and t. Therefore, has a fixed calculation format that is easily computed. On the other hand, N depends not only on A, but also on t. This provides a means to select t such that N is equal to 0, a property of significance. In summary, the algorithm proposed in this article enables users to establish a desired level of accuracy and then utilize it to select the appropriate values for m and N to minimize computation time. This approach ensures that both accuracy and efficiency are addressed concurrently. We develop a general algorithm, then apply it to the exponential, trigonometric, and logarithmic matrix functions, and compare the performance with that of the internal system functions of Mathematica and Pade approximation. In the last section, an example is provided to illustrate the rapid computation of numerical solutions for linear differential equations.
MSC:
68W25; 68U99
1. Introduction
Matrix exponent functions plays a crucial role in various fields, including ordinary differential equations and control theory. In particular, they are instrumental in analyzing general structural dynamic systems, represented by the initial value problem:
where , and K are n by n square matrices, and denotes the external force applied. The introduction of dual variables of a Hamiltonian system,
results in the following system:
where
The solution of (3) is provided as follows:
When a problem is oscillatory, the formal solution often involves both the sine and cosine of a matrix. Famous examples include the Schrdinger equation in quantum mechanics:
where is a Hermitian operator and is a complex wave function. If is a real and constant matrix, the solution of (6) is as follows:
There are other examples where the computation of the sine and cosine of a matrix can be of interest. Wave equations provided by the generic second order system are written as follows:
where the solution is provided by the variation of the constant method:
where If A is invertible, then (9) can be written as follows:
For (5), providing as accurately as possible is a concern for engineers and mathematicians, where is called the step. The specific method for this problem is as follows:
Similarly, for (10), providing the algorithm as accurately as possible involves introducing vectors and the following algorithm:
To improve the accuracy of and , it is essential to develop an algorithm with high accuracy for computing and and the integral containing these matrix functions. This paper improves the algorithms developed for the computation of and in the existing literature, see [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15], and also discusses the computation of other trigonometric, hyperbolic, logarithmic, and related inverse triangular and inverse hyperbolic matrices.
2. The General Theorem of the Fast Algorithm for Matrix Functions
In [16], we addressed the challenge of rapidly calculating elementary functions with specified precision. The implementation method involves an analytic function specifying property,
If is an approximation as close as possible to with N as a positive integer, for example,
or being the Padé approximation of then the following calculations are performed:
Completing (14) and (15), is obtained. This method is also applicable to the calculation of matrix functions, where the variable x is replaced by the n by n square matrix Now, we have the following:
or is the Padé approximation of Our objective is to determine m and N to minimize the computation time under the condition that the truncation error and computational precision are . For the matrix function calculation, the coefficient calculation of (14) can be ignored, mainly focusing on the multiplication calculation of the matrix in (16) and (15). If the number of multiplications to complete is K, then the total number of times to complete (16) and (15) is roughly
where is the number of times to complete one multiplication of the n by n matrix. Based on the above discussion, we present a fast algorithm for the matrix function as follows.
Theorem 1.
Let be an integer close to the minimum point of , where
and
(1) , where or is a Padé approximation of
(2) for() and
The above algorithm is a fast algorithm for the general matrix function.
Proof.
With a truncation error of , for (16) to be satisfied,
where is a norm of So,
From (17), we obtain the following:
Note that the minimum point of has nothing to do with . By making as small as possible, the algorithm obtained by (1) and (2) is a fast algorithm, thus completing the proof of the theorem. □
Remark 1.
In the specific calculation, can be replaced by the approximate eigenvalue with the maximum modulus in this paper.
3. Fast Algorithm for and
Suppose is a norm for A. If we let then . From (19), we can obtain the following:
In order to reduce the length of the article, the algorithms for several matrix functions are compiled into a table.
Theorem 2.
For , and we devised the following fast algorithm using Theorem 1.
Remark 2.
It is worth noting that in Table 1 only depends on the calculation accuracy p and the matrix function, and is independent of matrix A.
Table 1.
The fast algorithm for .
Now, we utilize the general fast algorithm to specifically demonstrate the correctness of the algorithms in Table 1. The algorithms in Table 1 are straightforward; they involve placing the specific functions f and g into the general algorithm, and the tricky part lies in deriving the formulas of and We calculate the formulas for and for the function for here. In fact, the graphing of the function of supports our results for all values of The derivation of and for the other functions is very similar.
(1) For the function we have and
Using Sterling’s approximation formula, we obtain the following:
Now, implementing it into (25), we obtain the following:
Let
Taking its derivative with respect to one obtains
To determine extreme values, we set it to 0 and multiply both sides by
Using simple algebra, we obtain the following:
Using we obtain a lower bound for
Thus, we have a lower bound for m: We also can solve the quadratic equation to get
Now, using the smallest value for m obtained and we can obtain our first upper bound:
We can again use the values of m and to update the lower bound of m as follows:
Now, our new lower bound for m is 7. With this small range of values for m, by inspecting the formula for the values of m, we can see that the value of m is very close to , and we can safely claim that m . Our following numerical calculation supports this claim completely.
Case (a): Using the formula obtained by the quadratic formula and the upper bound , we obtain a new lower bound: Using the formula obtained by the quadratic formula and lower bound we can also obtain the upper bound: Using our claim we obtain This clearly matches the lower and upper bound quite well.
Case (b): Using the formula obtained by the quadratic formula and the upper bound , we obtain a new lower bound: Using the formula obtained by the quadratic formula and lower bound we can also obtain the upper bound: Using our claim we obtain These values match very well for taking the closest integer.
Case (c): Using the formula obtained by the quadratic formula and the upper bound , we obtain a new lower bound: Using the formula obtained by the quadratic formula and lower bound we can also obtain the upper bound: Using our claim we obtain
Case (d): Using the formula obtained by the quadratic formula and the upper bound , we obtain a new lower bound: Using the formula obtained by the quadratic formula and lower bound we can also obtain the upper bound: Using our claim we obtain
Using we can obtain
(2) For we have and
In this case, for and 32, the corresponding integer points for to achieve its minimum value are and 6. Again, it can be estimated that
(3) For there are two cases:
Case (I): and (29) hold. Compared to I, the values in the second part of are very small, so we may replace N with , and with .
Case (II): and
Similarly, for and 32, the corresponding integer points for to achieve its minimum value are and 7. Consequently, we can determine the following:
The effectiveness of the algorithms is displayed in Table 1 by implementing numerical computations in Mathematica. and are replaced with in Table 1, defined correspondingly by
where one has and
For comparison, let A take the following form:
where U is a randomly generated n by n matrix, is a randomly generated n by n diagonal matrix with , so In all the examples in this paper, we agree on the relative error as follows:
Let be M matrices produced by (32). From Figure 1, it is evident that the calculation accuracy is essentially the same for , but provides the highest efficiency. The double-angle formula is notably more efficient and accurate than the triple-angle formula for . Henceforth, we will exclude the case that utilizes the triple-angle formula for .
Figure 1.
Error comparison of the algorithms in Table 1 for .
Now let us juxtapose the algorithms presented in Table 1 with the internal functions and commonly used algorithms found in mathematical software. For ease of reference, let denote the calculation error of matrix function , where a blank g implies the utilization of the algorithms in Table 1, Table 2 and Table 3 of this article. If , , it signifies calculation according to the internal function, Padé approximation, respectively. When for respectively. We denote the Padé approximation of as and the Padé approximation of and as In Table 1, the Padé approximation of is as follows:
Table 2.
The fast algorithms for , and .
Table 3.
The fast algorithms for and .
For the algorithms in Table 1, the of random matrix from order 1 to 800 is as follows.
It is evident from Figure 2 that, for and , the accuracy obtained by the three methods is essentially the same. However, when the matrix order is relatively high, the Taylor expansion method presented in Table 1 outperforms the others. In particular, for cos and , the calculation time of the internal functions is approximately eight times longer than that of the algorithms in Table 1. Numerical calculations demonstrate that while the calculation speed of and using the internal functions and is faster than that of the internal functions and , their calculation accuracy is relatively poor.
Figure 2.
Error of for three algorithms.
For and , the internal functions can be calculated by utilizing the following equation:
Our experiment provides the following results for of random matrices with orders from 1 to
It is evident from Figure 3 that using (35) not only doubles the calculation time but also makes the calculation error substantial. Furthermore, by observing Figure 2 and Figure 3, it becomes apparent that the algorithms in Table 1 outperform the Padé approximation algorithm.
Figure 3.
Error of for three algorithms.
4. Fast Algorithm for , and
Now let us contemplate the swift computation of , , and . Although these matrix functions can be computed using the following approach, we aim to directly compute them, as demonstrated in the previous section.
While the Padé approximation significantly contributes to matrix function computation, the numerical results in the previous section indicate that, based on the algorithm presented in this paper, neither the calculation accuracy nor the calculation speed is predominant. Therefore, this section does not adopt it.
Theorem 3.
For , and we have the following fast algorithm based on Theorem 1.
Using the algorithms in Table 2, our experiments generated the following data for the of random matrices from order 1 to 200.
Here, indicates that matrix functions , , , and sech expressed by , , and respectively, are computed using the internal functions. As observed in Figure 4, the algorithm’s computation speed in Table 2 surpasses that of the internal function, particularly for and , where the speed is increased by 8–11 times compared to the internal function, while maintaining consistent accuracy is consistent. When the order n of the matrix is relatively large, for and the calculation speed is twice that of the internal function, yet the precision remains the same as the internal function.
Figure 4.
Error of the for two algorithms.
Let us consider implementing our algorithms for calculating the functions , , and cschA. By
we see that when is small, the norm of the inverse of A will be large, so the calculation using (38) will produce large errors. Therefore, we must utilize the following method:
where
Theorem 4.
Using Theorem 1, we have the following algorithm for and .
Implementation of the algorithms in Table 3 provides the following results for the matrix functions in (39).
Here, signifies that matrix functions , , , and are calculated using the internal functions with the regular formulas , , , and respectively. The results in Figure 5 are essentially consistent with the corresponding results in Figure 2.
Figure 5.
Error of .
5. Fast Algorithm for Logarithmic Matrix Function and Some Related Functions
People consider various algorithms [17,18,19,20,21,22] for logarithmic matrix function One of the most effective methods we noticed was the following algorithm. The standard way of dealing with this problem is to use the square root operator repeatedly to bring A near the identity:
As k increases, , so for sufficiently large k, we can apply a direct method to This procedure for the logarithm was introduced by Kenney and Laub [19]. The specific method is to choose k such that
and usually, k is selected from 8. We slightly optimize the method as follows:
and
where k is usually selected from 4.
For , the algorithm that converges faster is
where For , we have
where Applying the Euler–Abel transformation [21], we obtain the following accelerated series:
where We can use the following Padé approximation of [20].
where We also provide some numerical results for the matrix function
Based on (41)–(44) we also provide some numerical results of using (46)–(48). It can be seen from Figure 6 that through optimization (43), the calculation accuracy of (46)–(48) is significantly improved, and the calculation speed of (46)–(48) is more than twice as fast as the inner function. The calculation speed advantage of the Padé approximation is obvious.
Figure 6.
Error of for the several algorithms.
We used the following identities to implement our general algorithm for the computations of the inverse trigonometric and hyperbolic functions. To control the length of the paper, we will not display the results here.
For arcsinh arctanh under certain conditions, we can use the following identity.
6. Improved Calculation Formula for Initial Value Problems (3) and (8)
Now, let us consider the calculation of the integral in (11), i.e.,
If numerical integration is used to calculate this integral, it is quite time-consuming, and the calculation accuracy cannot be guaranteed. We adopt the following method here. For , there is the following relationship:
where
can be calculated by the following method:
So, (53) can be written as follows:
so we can convert the integral of the product of matrix exponential function and vector function into the integral of pure vector function.
The improved calculation formula for (3) is as follows:
where is calculated by the algorithm in Table 1, and are calculated by (55) and (56).
For
the following two algorithms can be used.
(1) Integrable function method If is the algebraic sum of functions of the following types:
then (58) can be expressed in analytical form, so can also be expressed in analytical form. In this way, the calculation of (57) can be completed.
(2) Gauss three-point integral formula
Note that, under 16-bit calculation accuracy,
and the algebraic accuracy of the Gauss three-point integral formula is 5. Using the Gauss three-point integral formula,
where to approximate (58) with high accuracy. So, (57) can be replaced by the following algorithm.
Algorithm 1.
Numerical solution algorithm of initial value problem (3): for
Remark 3.
Note that, in (63) and (65) only needs to be calculated once, and is independent of , which is not only efficient but also easy to program.
Now let us consider the numerical solution of the initial value problem (8). If it is converted to the initial value problem (3), then
By
where
and (68), we obtain the following algorithm.
and
where and are determined using (31).
Algorithm 2.
Algorithm 3.
Numerical solution algorithm of initial value problem (8):
If A is reversible, then
Therefore, (75) can be written in the form of complex function as follows:
or
where
We first provide an examples to illustrate the effectiveness of Algorithms 1. Although we skip examples of Algorithm 2, we then include an example for the effectiveness of Algorithm 3.
Example 1.
In (8), let
The analytic solution of the initial value problem (8) is
Let where are the numerical solutions of the initial value problem (8) determined by Algorithm 1 and Algorithm 3, respectively. where is the numerical solution obtained by calling the function in Mathematica. The numerical results of are as follows.
It can be seen from Figure 7 that the calculation accuracy of Algorithm 1 is higher than that of Algorithm 3 but the calculation speed of Algorithm 3 is three times that of Algorithm 1. However, the error of numerical results of Mathematica internal functions is far greater than the error of Algorithms 1 and 3. In particular, the collapse is calculated at . After this point, the error increases exponentially with time t. However, Algorithms 1 and 3 are quite stable. For example, the calculation error in is still very small.
Figure 7.
Error of numerical solution (8) for several algorithms ( is calculated according to (64)).
In Algorithms 1 and 3, let , where is calculated according to (64). The numerical results are as follows.
Compared with Figure 7 and Figure 8, when , the calculation accuracy is not reduced by much, and the calculation speed is almost doubled. For Algorithms 1 and 3, the calculation accuracy is still high, and the calculation speed is 10 times higher than that in Figure 8.
Figure 8.
Error of numerical solution (8) for several algorithms.
Example 2.
In (8), let be a tridiagonal matrix. , , , , and they are randomly generated and satisfy the following conditions:
In Figure 9, (1)–(4), the left is the first two components of the numerical solution, and the right is the difference between the numerical solutions obtained by the two algorithms. It is noted that sometimes is close to the frequency of the solution, and flutter or resonance may occur. However, the values obtained by the two algorithms are still very close.
Figure 9.
Numerical solutions and errors of two algorithms.
7. Conclusions
In this paper, we established algorithms for the computation of matrix exponential functions, matrix trigonometric functions, and matrix hyperbolic functions. Our numerical results show that these algorithms are faster with higher accuracy compared to existing algorithms and the system algorithms in Mathematica. In the series expansion of matrix function, the number of expanded items is only related to the requirement of calculation accuracy, and has nothing to do with the matrix itself. However, the number of times in the iterative process is not only related to the matrix itself but also closely related to When (), , the calculation of the matrix function becomes an algebraic operation, so the integral in (9)–(12) becomes an easy integral to compute. In brief, our algorithm allows users to set a required level of accuracy and then use it to choose appropriate values for parameters m and N to minimize computation time. In this manner, both accuracy and efficiency are addressed simultaneously.
Author Contributions
Conceptulation, H.Q. and Y.L.; mehtodology, H.Q. and Y.L.; software, H.Q.; validation, H.Q. and Y.L.; formal analysis, H.Q. and Y.L.; investigation, H.Q. and Y.L.; visualization, H.Q.; supervision, H.Q.; project administration, Y.L. All authors have read and agreed to the publication version of the manuscript.
Funding
This research received no external funding.
Institutional Review Board Statement
Not applicable.
Informed Consent Statement
Not applicable.
Data Availability Statement
Data are contained within the article.
Conflicts of Interest
The authors declare no conflict of interest.
References
- Ruiz, P.; Sastre, J.; Ibáñeza, J.; Defez, E. High performance computing of the matrix exponential. J. Comput. Applied Math. 2015, 291, 370–379. [Google Scholar] [CrossRef]
- Molert, C.; Loans, C.V. Nineteen dubious ways to compute the exponential of a matrix. SIAM Rev. Soc. Ind. Applied Math. 1978, 20, 801–836. [Google Scholar]
- Higham, N.J. Functions of Matrices: Theory and Computation; SIAM: Philadelphia, PA, USA, 2008. [Google Scholar]
- Al-Mohy, A.H.; Higham, N.J. Computing the Action of the Matrix Exponential, with an Application to Exponential Integrators. SIAM J. Sci. Comput. 2011, 33, 488–511. [Google Scholar] [CrossRef]
- Higham, N.J. The scaling and squaring method for the matrix exponential resisted. SIAM J. Matrix Anal. Appl. 2005, 26, 1179–1193. [Google Scholar] [CrossRef]
- Bader, P.; Blanes, S.; Casas, F. Computing the Matrix Exponential with an Optimized Taylor Polynomial approximation. Mathematics 2019, 7, 1174. [Google Scholar] [CrossRef]
- Seydaoglu, K.M.; Bader, P.; Blanes, S.; Casas, F. Computing the matrix sine and cosine simultaneously with a reduced number of products. arXiv 2020, arXiv:2010.00465v1. [Google Scholar] [CrossRef]
- Hargreaves, G.I.; Higham, N.J. Efficient algorithms for the matrix cosine and sine. Numer. Algorithms 2005, 40, 383–400. [Google Scholar] [CrossRef]
- Alonso, P.; Ibáñez, J.; Sastre, J.; Peinado, J.; Defez, E. Efficient and accurate algorithms for computing matrix trigonometric functions. J. Comput. Appl. Math. 2017, 309, 325–332. [Google Scholar] [CrossRef]
- Alonso, P.; Peinado, J.; Ibáñez, J.; Sastre, J.; Defez, E. Computing Matrix Trigonometric Functions with GPUs through Matlab. J. Supercomput. 2019, 75, 1227–1240. [Google Scholar] [CrossRef]
- Al-Mohy, A.H.; Higham, N.J.; Relton, S.D. New Algorithms for Computing the Matrix Sine and Cosine Separately or Simultaneously. SIAM J. Sci. Comput. 2015, 37, A456–A487. [Google Scholar] [CrossRef]
- Serbin, S.M.; Blalock, S.A. An algorithm for computing the matrix cosine. SIAM J. Sci. Statist. Comput. 1980, 1, 198–204. [Google Scholar] [CrossRef]
- Cooper, B.L.; Bingulac, S. Computational improvement in the calculation of the natural log of a square matrix. Electron. Lett. 1990, 26, 861–862. [Google Scholar] [CrossRef]
- Wu, F.; Zhu, L.; Shi, Q. Efficient Computational method for matrix function in dynamic problems. Acta Mech. Sin. 2023, 39, 522451. [Google Scholar] [CrossRef]
- Cardoso, J.R.; Sadeghi, A. A technique for improving the computation of functions of triangular matrices. Int. J. Comput. Math. 2022, 99, 2449–2465. [Google Scholar] [CrossRef]
- Jiang, Y.; He, C.; Qin, H. An accelerated algorithm for high precision and fast calculation of basic elementary functions. Math. Pract. Theory 2017, 47, 238–246. [Google Scholar]
- Fasi, M.; Higham, N.J. Multiprecision algorithm for Computing matrix logarithm. SIAM J. Matrixanal. Appl. 2018, 39, 472–491. [Google Scholar] [CrossRef]
- Ibáñez, J.; Sastre, J.; Ruiz, P.; Alonso, J.M.; Defez, E. An Improved Taylor Algorithm for Computing the Matrix Logarithm. Mathematics 2021, 9, 2018. [Google Scholar] [CrossRef]
- Cheng, S.H.; Higham, N.J.; Kenney, C.S.; Laub, A.J. Approximating the Logarithm of a Matrix to Specified Accuracy. SIAM J. Matrix Anal. Appl. 2001, 22, 1112–1125. [Google Scholar] [CrossRef]
- Kenney, C.; Laub, A.J. Condition estimates for matrix functions. SIAM J. Matrix Anal. Appl. 1989, 10, 191–209. [Google Scholar] [CrossRef]
- Kenney, C.; Laub, A.J. Padé error estimates for the logarithm of a matrix. Internat. J. Control. 1989, 50, 707–730. [Google Scholar] [CrossRef]
- Milovanović, G.V.; Rančić, S.L. Some improvements in calculation of the natural log of a square matrix. In Proceedings of the Third International Conference on Functional Analysis and Approximation Theory, Aquafredda di Maratea, Potenza, Italy, 23–28 September 1996; Issue 52. Volume II. [Google Scholar]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).