1. Introduction
Quite often mathematical models of physical systems require the solution of a system of differential equations of the form
under the initial condition
, where
is a constant
matrix, and
is an
vector. The analytical solution of this system of equations is
. Using its basic definition,
can be written as an infinite series; however, it is known that truncating the series to compute the matrix exponential can yield erroneous results, and hence is very unreliable. Alternatively, an exact expression can be derived for the matrix exponential in terms of projections and nilpotent tensors (Equation (40) in Reference [
1]). However, finding the projections and nilpotent components of a given matrix is computationally demanding, and thus, although the explicit formula is theoretically interesting, it does not yield an efficient algorithm for numerically computing the matrix exponential. Thus, as we now discuss in greater detail in the following paragraph, finding
in a computational framework is quite challenging. In this work, we propose a new algorithm that carries out this computation.
Perhaps the most detailed survey of various methods to compute the matrix exponential is the one by Moler and van Loan [
2]. In this survey, the authors have discussed various methods such as scaling and squaring, Chebyshev rational approximation, ordinary differential equations approach, polynomial methods, etc. While discussing the differential equations, they write the following:
The scaling and squaring methods of Section 3 and some of the matrix decomposition methods of Section 6 require on the order of 10 to 20 flops and they obtain higher accuracies than those obtained with 200 or more flops for the o.d.e. solvers. This excessive cost is due to the fact that the programs are not taking advantage of the linear, constant coefficient nature of the differential equation. They must repeatedly call for the multiplication of various vectors by the matrix because, as far as they know, the matrix may have changed since the last multiplication.
It is precisely this constant coefficient nature of the differential equations that we exploit in the proposed approach in this work. Thus, the proposed algorithm needs to solve an system of equations with n right hand sides just once at the beginning of the program, and during each time step, it needs to multiply this precomputed matrix with the value of the exponential matrix at that time step to obtain the exponential matrix at the next time step.
But more than the efficiency, our emphasis in this work is on the
robustness and generalizability of the algorithm since so many standard methods are known to fail when
is either ill-conditioned, or when it does not have a linearly independent set of eigenvectors etc. (this is also evident from the title of Reference [
2]: ‘Nineteen
dubious ways …’). Our method is based on the time finite element method which, similar to the continuum setting, is known to conserve the energy exactly even in the discrete setting for conservative systems [
3]. This property is extremely important since this leads to an unconditionally stable algorithm (allowing for arbitrarily large time steps) from an energy perspective. Even if the system is non-conservative, the time finite element method has been demonstrated to yield very reliable results even for chaotic systems such as the Duffing oscillator or the Lorenz system [
4]. Thus, the time finite element method is an extremely robust method for the solution of a system of ordinary linear or nonlinear differential equations (in the sense that, for example, it does not fail to compute
accurately even when
is ill-conditioned), and this feature will be brought out in
Section 3 on a set of challenging examples.
Most of the literature, both classical and recent, seems to prefer the scaling and squaring method [
5,
6,
7,
8]. There is a class of methods known as exponential integrators [
9], but even these algorithms seem to be based on scaling and squaring algorithms for approximating the matrix exponential. Reference [
10] compute the matrix exponential approximation using Pade approximations, while References [
11,
12] use approximations based on Taylor and Euler polynomials, respectively. To the best of our knowledge, there is no algorithm that is based on computing the matrix exponential based on the solution of the governing differential equation,
and which exploits the fact that is constant to improve the efficiency of the algorithm.
While solving a dynamical system, one is, ideally speaking, interested in finding the evolution of the solution as a function of time in a given interval, or within a numerical framework, at several discrete time steps in that interval, and in many cases when the matrix
is time dependent and there is, in addition, a forcing function as in Equation (
7). The proposed algorithm, since it is based on time-stepping, addresses precisely this need in an efficient manner by using the information from the previous time step. Scaling and squaring algorithms such as the ones implemented as the expm() function in MATLAB [
13] are extremely robust, efficient, and are highly accurate in computing the exponential of a matrix when
is constant. However, they are not easily generalized to the case given in Equation (
7) since the solution may not even be in the form of the exponential of a matrix. We now proceed to describe our algorithm.
2. Formulation
Given a constant matrix
, we are interested in numerically finding a good approximation to
which can be written as the solution of
subject to the initial condition
, where
is an
matrix. We use the time finite element method to carry out the solution of the differential equation in Equation (
1). In case we are interested in finding
, we partition the interval
into a number of time finite elements of size
, where
. Starting from the prescribed initial conditions at
, we find the solution at time
, then at time
using the solution obtained at time
, and so on until time
T is reached (quite obviously, we simply set
if we are interested in computing
). Thus, the key advantage of using the time finite element method is that one obtains not only
, but also the entire evolution of the solution for
. As discussed in the Introduction, among the numerous time-stepping schemes on the interval
, the time-finite element method is one the most robust strategies that conserves energy even in the discrete setting in the case of conservative systems.
The time finite element is basically a weighted-residual method in time, which uses a piecewise polynomial approximation over each time interval for the variable being computed (
in our case), and with the weighing functions being polynomials that are one-order lower than those used for approximating
[
3]. In this work, we formulate quadratic, cubic and quartic time finite element methods.
Let
,
,
,
,
,
and
. With the midnode located at the center of the element, an application of the quadratic time finite element to Equation (
1) results in the set of equations
Equation (
2d) leads to
Solving the above set of equations we get
which on substituting into any of Equation (3) finally leads to
where
Similar to the above derivation, an application of the cubic and quartic time finite element methods leads to
where
Note that since
is a constant matrix in any of the above methods, and if we use time intervals of equal length, then the matrix to be inverted in the expression for
is a constant matrix. This solution of the
system of equations with
n right hand sides to find
is carried out only once at the beginning of the algorithm. Starting with
, we march forward in time until the time instant
is reached. After each time step calculation (which involves only the multiplication of the pre-calculated
with
), we assign
, and proceed to the next time step.
Even if is singular or close to singular, the invertibility of in the quadratic time finite element method, and the corresponding matrices in the cubic and quartic methods is not affected due to the presence of the identity matrix. Note also that the algorithm is not dependent on any special structure of the matrix such as diagonalizable, Jordan canonical form, or one having linearly independent eigenvectors, etc., and is thus applicable for any matrix . Since T can be chosen arbitrarily by the user, the above algorithm actually yields for any choice of T, and, moreover, it yields for every subinterval that the domain is divided into.
Once
is computed, other related functions can be computed as
The proposed method also works for complex matrices
with the only change being that a complex solver is now used to compute
. In fact, we can compute the cosine, sine and tangent of a matrix as
The method is easily modified to solve the set of differential equations
with
, where
is now a
vector; in place of Equation (
4), we now get
with
, with
calculated only once at
as in the case of Equation (
4) or Equation (
5), and with the assignment
at the end of each time step.
The method is also even easily extended to the case where the matrix
is a function of time, and, in addition, there is a forcing function, i.e., we now have
with
. As an example, to formulate the quadratic time finite element for this case, let
,
,
,
,
,
,
and
, and let
where the ‘
t’ in Equation (
8d) is given by Equation (
8a). Depending on
and
, the integrals in Equation (
8d) have to be evaluated for
,
, and, given
, one then solves these two equations for
on the interval
with
. Of course, this now involves inverting a matrix at every time step (as opposed to the constant
case, where a matrix has to be inverted only once at the beginning of the program), and, as expected, will thus be computationally more expensive compared to the constant
case that we have dealt with in this work. The formulation of the cubic and quartic finite element methods is similar to the above formulation.
There is a dramatic increase in accuracy and a corresponding reduction in the run time (for a given level of accuracy) as one progresses from the quadratic to the cubic, and from the cubic to the quartic time finite element method. The only additional cost is in constructing and in the two methods (which is negligible since this is carried out only once at the beginning of the program). One and two additional arrays, respectively, are required over and above those in the quadratic time finite element method.
3. Numerical Examples
We now illustrate the good performance of the algorithm on examples from the literature where certain algorithms fail, and on some new examples as well. All results are presented using the quartic time finite element method. So far we have not come across an example where an algorithm from the literature works, while the proposed algorithm fails. Since the solution approaches the exact solution as
, one can obtain any desired level of accuracy simply by decreasing
. The precise value of
that is to be used of course depends on the matrix
, but extensive numerical experimentation with large or ill-conditioned matrices
indicates that a value of
of
or
yields extremely accurate results in most cases. Thus, keeping in view that the proposed algorithm is efficient (only one system of equations with multiple right hand sides to be solved at
, followed by matrix multiplications at each time step; see the runtime for an example stated below), we have focused more on presenting examples where computing
accurately is important, rather than focusing on examples where the size of
is large, although we do present such as example as well. The runs for both the proposed and a Fortran implementation of the scaling and squaring algorithm were carried out on stand-alone I7-6700@3.40 GHz Intel-based PC (Intel Corporation, Santa Clara, CA, USA), with no parallelization of the Fortran codes. To give an idea of the efficiency of the algorithm, the runtime for the
matrix
with
is shown by the system as
s (which means that it is less that
s even on a relatively old desktop, and with no parallelization). Similar to the proposed algorithm, the scaling and squaring algorithm such as the expm() function in MATLAB [
13] also yields extremely accurate results in negligible time for the small matrix examples, so that we claim no superiority of our algorithm over the expm() function in terms of run time. However, as explained in detail in the Introduction, the scaling and squaring method is not easily generalizable to the case given by Equation (
7). The runtimes for the large matrix example with both algorithms are stated in the example itself. In addition to the memory required for storing
and
, our algorithm requires five
arrays for the quartic case, while the implementations of the scaling and squaring algorithm that we have come across require six to eight additional
arrays.
Wherever presented, the relative error is calculated using the Frobenium norm as
where the reference solution is obtained using Mathematica [
14] (which in some cases is the analytical solution).
This example shows that using a truncated version of the infinite series expansion of
can lead to inaccurate results [
2]. The matrix and the result obtained to 8 decimal places using the proposed algorithm with
are
which agrees with the solution in the mentioned reference, and with the error as given in
Table 1.
This example is again from [
2]. The matrix and the analytical solution are
An almost perfect match is found between the solution from the proposed algorithm with , and the above analytical solution with a deviation only in the 14th or 15th decimal place for some of the entries.
If
is nearly defective, then methods based on eigenvectors can yield erroneous results [
2]. An example of such a matrix, and the analytical solution for its exponential are given by
For
and
, the error norm is
showing the high accuracy of the proposed algorithm even with a relatively large
. Another similar example is presented in Reference [
15], where, again, the proposed algorithm yields the correct solution.
If
is in the form of a Jordan block, say with the form given below, then we have [
2]
Once again with , the proposed algorithm yields the above analytical solution almost perfectly with an error norm of around .
This is a challenging example due to the highly ill-conditioned matrix
, where one of the older versions of the function expm(.) in MATLAB [
13] yielded an erroneous result (note, however, that the current version does yield the correct result) [
16]. With
,
,
,
,
, the matrix and the result obtained using the proposed algorithm with
are as follows:
The error norms are as shown in
Table 2, and again demonstrate the high accuracy of the proposed algorithm.
Consider
to be a skew-symmetric matrix; in which case, we know that
is an orthogonal matrix [
17]. As an example,
The error norms with the proposed algorithm are as shown in
Table 3.
Note that a very fine is required to capture the very high frequency oscillation of the solution with time. The expm() function yields a solution with an error norm of 5.5 × , and is thus much more effective than the proposed algorithm both in terms of accuracy and computational time on this particular example. This is because our algorithm is based on time-stepping, and errors accumulate from one time step to another.
This is again an example of an extremely ill-conditioned matrix, which makes it very challenging to find its matrix exponential. The matrix and the result that we obtain with
are
Note the dramatic variations in the entries of
. The above result agrees very closely with the one obtained using the expm(.) function in MATLAB [
13]. The function expmdemo3 in MATLAB [
13] which is based on eigenvalues/eigenvectors yields an incorrect result (after giving a warning that the results may be inaccurate due to the ill-conditioning of
). The error norms are as shown in
Table 4.
This example shows that the proposed algorithm can compute the cosine or sine of a matrix accurately. Let
be as in Example 2. The analytical solutions are
An almost perfect match with the above analytical solutions is obtained with .
This example is challenging since the matrix
is both large and singular. Consider a
matrix
with all entries as 1. Only one eigenvalue of
is nonzero with a value of 100. The diagonal elements of
are given by
(which is approximately
), while the off-diagonal elements are
. A Fortran implementation of the scaling and squaring algorithm gives a diagonal value of
with a run time of
s, while the proposed algorithm yields diagonal values of
and
with run times of
s (
) and
s (
), respectively, showing the extremely high accuracy of the proposed method even for large and singular matrices. The result obtained with the expm() function of MATLAB [
13] is
. Although the run time with the scaling and squaring algorithm may appear to be smaller compared to that of the proposed method, obtaining the solution at all the intermediate 1000 time steps (which is what is generally of interest) as in our algorithm would involve either 1000 runs or matrix multiplications in order to obtain the complete dynamical solution.