Post · 5 min read· pp. 192–194

Rational approximation to the exponential in a complex region

Approximation of the exponential function has many applications, some of which are described in other Chebfun examples. Here we consider approximating eze^z via a rational function in a region in the complex plane, in the context of computing the matrix exponential eAe^A via the scaling and squaring method, the most commonly used method for this purpose, cf. chapter 10 of [2]. Constructions of rational approximations to eze^z on a real interval are described in [3].

In brief, the scaling and squaring method is based on a type (2sm,2sm)(2^sm,2^sm) rational approximation to the exponential in a region in the complex plane that contains the eigenvalues of AA, where ss and mm are suitably chosen integer parameters. It first computes eAe^A by first choosing an integer ss such that A/2sA/2^s has norm of order $1$, then taking a rational (normally type (m,m)(m,m) Pade) approximation r(z)r(z) to eze^z where mm is chosen so that eA/2s≈r(A/2s)e^{A/2^s}\approx r(A/2^s). Then we compute eA≈(r(A/2s))2se^A\approx (r(A/2^s))^{2^s} via repeated squaring of the matrix.

(Note that the letter e in the name Pade should have an accent aigu, but we dispense with this in a Chebfun Example to avoid trouble in some web browsers.)

Suppose AA is diagonalizable and A=X\mboxdiag(λi)X−1A=X\mbox{diag}(\lambda_i)X^{-1}. Then this method approximates

eA=X\mboxdiag(eλi)X−1e^A=X\mbox{diag}(e^{\lambda_i})X^{-1}

by

Y:=X\mboxdiag((r(λi/2s))2s)X−1≈eA,Y:=X\mbox{diag}((r(\lambda_i/2^s))^{2^s})X^{-1}\approx e^A,

and the error satisfies

∣eA−Y∣2≤κ2(X)max⁡z∈D∣(r(z/2s))2s−ez∣,|e^A - Y|_2 \leq \kappa_2(X)\max_{z\in {\cal D}}\left|(r(z/2^s))^{2^s}-e^{z}\right|,

where D\cal{D} is a region in the complex plane that contains the eigenvalues of AA, and κ2(X)=∣X∣2∣X−1∣2\kappa_2(X)=|X|_2 |X^{-1}|_2 is the 2-norm condition number of the eigenvectors. The term max⁡i∣(r(λi/2s))2s−eλi∣\max_i\left|(r(\lambda_i/2^s))^{2^s}-e^{\lambda_i}\right| represents the exact error if AA is a normal matrix: the term κ2(X)\kappa_2(X) can have nontrivial effects on the method for nonnormal AA, but this is outside the scope of this example. Below we investigate the error ∣(r(z/2s))2s−ez∣\left|(r(z/2^s))^{2^s}-e^{z}\right| where zz takes points in the complex plane. If this is small in the whole region D\cal D, then YY is a good approximation to eAe^A.

The type (k,m)(k,m) Pade approximant of the exponential is explicitly known to be r(z)=pk,m(z)/qk,m(z)r(z)=p_{k,m}(z)/q_{k,m}(z), where

pk,m(z)=∑j=0k(k+m−j)!k!(k+m)!(k−j)!zjj!,qk,m(z)=∑j=0m(k+m−j)!m!(k+m)!(m−j)!(−z)jj!.p_{k,m}(z)=\sum_{j=0}^{k}\frac{(k+m-j)!k!}{(k+m)!(k-j)!}\frac{z^j}{j!}, \quad q_{k,m}(z)=\sum_{j=0}^{m}\frac{(k+m-j)!m!}{(k+m)!(m-j)!}\frac{(-z)^j}{j!}.

Alternatively (and in particular for general functions for which Pade approximants are not explicitly known), Pade approximants can be obtained simply and robustly via the Chebfun command padeapprox, see [1].

Here is a contour plot of the logarithm of max⁡z∈D∣(r(z/2s))2s−ez∣\max_{z\in {\cal D}}\left|(r(z/2^s))^{2^s}-e^{z}\right| for the case s=2s=2 and m=8m=8:

text
s = 2; m = 8;
f = [1 , 1./cumprod(1:50)]; % or f = @(z)exp(z);
[r,a,b] = padeapprox(f,m,m,0);
xgrid = linspace(-100,100,140);
[x,y] = meshgrid(xgrid,xgrid);
z = x + 1i*y;
contourf(x,y,log10(abs(exp(z) - r(z/(2^s)).^(2^s))+eps),[-16:2:0])
colorbar

Since we are using a Pade approximation centered at the origin, the error is zero at the origin and is expected to grow with ∣z∣|z|. However, notice that the plot is highly nonsymmetric about the imaginary axis: the error is large for large \mboxRe(z)>0\mbox{Re}(z)>0 and small for \mboxRe(z)<0\mbox{Re}(z)<0. In particular, the region in which the error is O(10−14)O(10^{-14}) stretches much farther into the left complex plane than the right, reaching \mboxRe(z)≈−65\mbox{Re}(z)\approx -65. This is perhaps not surprising because eze^z (literally) grows exponentially with \mboxRe(z)\mbox{Re}(z), so for \mboxRe(z)≪0\mbox{Re}(z)\ll 0 we have ∣ez∣=e\mboxRe(z)≈0|e^z|=e^{\mbox{Re}(z)}\approx 0 and the error is essentially just ∣(r(z/2s))2s∣\left|(r(z/2^s))^{2^s}\right|, which is itself small for moderately large ss provided that ∣(r(z/2s))∣<1|(r(z/2^s))| < 1.

The relative error 1∣ez∣∣(r(z/2s))2s−ez∣\frac{1}{|e^{z}|}\left|(r(z/2^s))^{2^s}-e^{z}\right|, on the other hand, looks completely different:

text
contourf(x,y,log10(abs(exp(z) - r(z/(2^s)).^(2^s))./abs(exp(z))),[-16:2:16])
colorbar

The graph shows that (r(z/2s))2s(r(z/2^s))^{2^s} has no digits of relative accuracy except in the blue region.

The two plots illustrate for example that around the point z=−50z = -50, the relative accuracy is terrible but the absolute accuracy is of order unit roundoff. Hence (r(z/2s))2s(r(z/2^s))^{2^s} is a good approximant near z=−50z=-50 if we are concerned with absolute accuracy instead of relative accuracy.

In the context of the matrix exponential, the forward error is measured by the quantity ∣eA−Y∣2/∣eA∣2|e^A- Y|_2/|e^A|_2, which for normal AA reduces to

max⁡i∣(r(λi/2s))2s−eλi∣/emax⁡i\mboxRe(λi)≤max⁡z∈D∣(r(z/2s))2s−ez∣/emax⁡i\mboxRe(λi).\max_i\left|(r(\lambda_i/2^s))^{2^s}-e^{\lambda_i}\right|/e^{\max_i{\mbox{Re}(\lambda_i)}}\leq \max_{z\in {\cal D}}\left|(r(z/2^s))^{2^s}-e^{z}\right|/e^{\max_i{\mbox{Re}(\lambda_i)}}.

Since the denominator is constant (when zz varies in D\cal D), this means the absolute error is indeed the appropriate metric of error in the eAe^A context. The implication is that eAe^A is well-approximated by YY if the eigenvalues of AA lie inside the dark-blue region in the first plot.

References

  1. P. Gonnet, S. Guettel, and L. N. Trefethen: Robust Pade approximation via SVD. SIAM Review, 55 (2013), 101-117.
  2. N. J. Higham. Functions of Matrices: Theory and Computation. SIAM, Philadelphia, 2008.
  3. L. N. Trefethen, J. A. C. Weideman, and T. Schmelzer: Talbot quadratures and rational approximations. BIT Numerical Mathematics, 46 (2006), pp. 653-670.