# Advances in the Approximation of the Matrix Hyperbolic Tangent

^{1}

^{2}

^{3}

^{4}

^{*}

## Abstract

**:**

## 1. Introduction and Notation

#### 1.1. The Matrix Exponential Function-Based Approach

#### 1.2. The Taylor Series-Based Approach

## 2. Algorithms for Computing the Matrix Hyperbolic Tangent Function

#### 2.1. The Matrix Exponential Function-Based Algorithm

Algorithm 1: Given a matrix $A\in {\mathbb{C}}^{n\times n}$, this algorithm computes $T=tanh\left(A\right)$ by means of the matrix exponential function. |

1$B=2A$2 Calculate the scaling factor $s\in \mathbb{N}\cup \left\{0\right\}$, the order of Taylor polynomial ${m}_{k}\in \{2,4,6,9,12,16,20,25,30\}$ and compute ${e}^{{2}^{-s}B}$ by using the Taylor approximation /*$\phantom{(}$ Phase I (see Algorithm 2 from [26])$\phantom{(}$ */3 $T={\left(\right)}^{{e}^{{2}^{-s}B}}-1$ /*$\phantom{(}$ Phase II: Work out $tanh\left({2}^{-s}B\right)$ by (3)$\phantom{(}$ */4 for $i=1$ to s do /*$\phantom{(}$ Phase III: Recover $tanh\left(A\right)$ by (5)$\phantom{(}$ */ $\phantom{(}$5 $\hspace{1em}B=I+{T}^{2}$6 Solve for X the system of linear equations $BX=2T$7 $\hspace{1em}T=X$8 end $\phantom{(}$ |

Algorithm 2: Given a matrix $A\in {\mathbb{C}}^{n\times n}$, this algorithm computes T = tanh(A) by means of the Taylor approximation Equation (8) and the Paterson–Stockmeyer method. |

1 Calculate the scaling factor $s\in \mathbb{N}\cup \left\{0\right\}$, the order of Taylor approximation ${m}_{k}\in \left(\right)open="\{"\; close="\}">2,4,6,9,12,16,20,25,30$, ${2}^{-s}A$ and the required matrix powers of ${4}^{-s}B$ /*$\phantom{(}$ Phase I (Algorithm 4)$\phantom{(}$ */2 $T={2}^{-s}A{P}_{{m}_{k}}\left({4}^{-s}B\right)$ /*$\phantom{(}$ Phase II: Compute Equation (8)$\phantom{(}$ */3 for $i=1$ to s do
/*$\phantom{(}$ Phase III: Recover $tanh\left(A\right)$ by Equation (5)$\phantom{(}$ */ $\phantom{(}$4 $\hspace{1em}B=I+{T}^{2}$5 Solve for X the system of linear equations $BX=2T$>6 $\hspace{1em}T=X$7 end $\phantom{(}$ |

#### 2.2. Taylor Approximation-Based Algorithms

**Proposition**

**1.**

- $|{\lambda}_{i}|<\pi /2$.
- $|{\lambda}_{i}|=\pi /2$ and the series ${f}^{({n}_{i}-1)}\left(\lambda \right)$, where $f\left(z\right)$ is given by Equation (6) and ${n}_{i}$ is the index of ${\lambda}_{i}$, is convergent at the point $\lambda ={\lambda}_{i}$, $i=1,\dots ,t$.

Algorithm 3: Given a matrix $A\in {\mathbb{C}}^{n\times n}$, this algorithm computes $T=tanh\left(A\right)$ by means of the Taylor approximation Equation (8) and the Sastre formulas. |

1 Calculate the scaling factor $s\in \mathbb{N}\cup \left\{0\right\}$, the order of Taylor approximation ${m}_{k}\in \left(\right)open="\{"\; close="\}">2,4,8,14,21$, ${2}^{-s}A$ and the required matrix powers of ${4}^{-s}B$ /*$\phantom{(}$ Phase I (Algorithm 5)$\phantom{(}$ */2 $T={2}^{-s}A{P}_{{m}_{k}}\left({4}^{-s}B\right)$ /*$\phantom{(}$ Phase II: Compute Equation (8)$\phantom{(}$ */ 3 for $i=1$ to s do/*$\phantom{(}$ Phase III: Recover $tanh\left(A\right)$ by Equation (5)$\phantom{(}$ */ $\phantom{(}$4 $\hspace{1em}B=I+{T}^{2}$5 Solve for X the system of linear equations $BX=2T$6 $\hspace{1em}T=X$7 end $\phantom{(}$ |

`vpasolve`function (https://es.mathworks.com/help/symbolic/vpasolve.html, accessed on 7 March 2020) from the MATLAB Symbolic Computation Toolbox with variable precision arithmetic. For the case of $m=21+$, the random option of

`vpasolve`has been used, which allowed us to obtain different solutions for the coefficients, after running it 1000 times. From all the sets of real solutions provided, we selected the most stable ones according to the stability check proposed in [28] (Ex. 3.2).

#### 2.3. Polynomial Order m and Scaling Value s Calculation

Algorithm 4: Given a matrix $A\in {\mathbb{C}}^{n\times n}$, the values $\mathsf{\Theta}$ from Table 1, a minimum order ${m}_{lower}\in \mathbb{M}$, a maximum order ${m}_{upper}\in \mathbb{M}$, with $\mathbb{M}=\left(\right)open="\{"\; close="\}">2,4,6,9,12,16,20,25,30$, and a tolerance $tol$, this algorithm computes the order of Taylor approximation $m\in \mathbb{M}$, ${m}_{lower}\le {m}_{k}\le {m}_{upper}$, and the scaling factor s, together with ${2}^{-s}A$ and the necessary powers of ${4}^{-s}B$ for computing ${P}_{{m}_{k}}\left({4}^{-s}B\right)$ from (9). |

1${B}_{1}={A}^{2}$; $k=lower$; $q=\lceil \sqrt{{m}_{k}}\rceil $; $f=0$2for $j=2$toqdo3$\hspace{1em}{B}_{j}={B}_{j-1}{B}_{1}$4end$\phantom{(}$5 Compute ${\beta}_{k}\approx {\left(\right)}^{{B}^{{m}_{k}+1}}1/({m}_{k}+1)$ from ${B}_{1}$ and ${B}_{q}$; /* see [30]$\phantom{(}$ */6 while $f=0$ and $k<upper$ do7 $\hspace{1em}k=k+1$8 if $\phantom{\rule{3.33333pt}{0ex}}mod\phantom{\rule{0.277778em}{0ex}}(k,2)=1$ then9 $\hspace{1em}\hspace{1em}q=\u2308\sqrt{{m}_{k}}\u2309$10 $\hspace{1em}\hspace{1em}{B}_{q}={B}_{q-1}{B}_{1}$11 end $\phantom{(}$ 12 Compute ${\beta}_{k}\approx {\left(\right)}^{{B}^{{m}_{k+1}}}1/\left({m}_{k+1}\right)$ from ${B}_{1}$ and ${B}_{q}$; /* see [30]$\phantom{(}$ */13
if $|{\beta}_{k}-{\beta}_{k-1}|<tol$ and ${\beta}_{k}<{\mathsf{\Theta}}_{k}$ then $\phantom{(}$14 $\hspace{1em}\hspace{1em}f=1$15 end $\phantom{(}$16 end $\phantom{(}$17 $s=max\left(\right)open="("\; close=")">0,\left(\right)open="\lceil "\; close="\rceil ">{\frac{1}{2}log}_{2}({\beta}_{k}/{\mathsf{\Theta}}_{k})$18 if $s>0$ then $\phantom{(}$19 $\hspace{1em}{s}_{0}=max\left(\right)open="("\; close=")">0,\left(\right)open="\lceil "\; close="\rceil ">{\frac{1}{2}log}_{2}({\beta}_{k-1}/{\mathsf{\Theta}}_{k-1})$20 if ${s}_{0}=s$ then $\phantom{(}$21 $\hspace{1em}\hspace{1em}k=k-1$22 $\hspace{1em}\hspace{1em}q=\u2308\sqrt{{m}_{k}}\u2309$23 end $\phantom{(}$24 $\hspace{1em}A={2}^{-s}A$25 for $j=1$ toq do26 $\hspace{1em}\hspace{1em}{B}_{j}={4}^{-sj}{B}_{j}$27 end $\phantom{(}$28 end $\phantom{(}$29 $m={m}_{k}$ |

Algorithm 5: Given a matrix $A\in {\mathbb{C}}^{n\times n}$, the values $\mathsf{\Theta}$ from Table 2, $\mathbb{M}=\left(\right)open="\{"\; close="\}">2,4,8,14,21$ and a tolerance $tol$, this algorithm computes the order of Taylor approximation ${m}_{k}\in \mathbb{M}$ and the scaling factor s, together with ${2}^{-s}A$ and the necessary powers of ${4}^{-s}B$ for computing ${2}^{-s}A{P}_{{m}_{k}}\left({4}^{-s}B\right)$ from (10), (11) or (12). |

1${B}_{1}=-{A}^{2}$; ${B}_{2}={B}_{1}^{2}$2 Compute ${\beta}_{1}\approx {\left(\right)}^{{B}^{3}}1/{3}_{}$ from ${B}_{1}$ and ${B}_{2}$3 $f=0$; $k=1$4 while $f=0$ and $k<5$ do5 $\hspace{1em}k=k+1$6 if $k<5$ then $\phantom{(}$ 7 Compute ${\beta}_{k}\approx {\left(\right)}^{{B}^{{m}_{k+1}}}1/\left({m}_{k+1}\right)$ from ${B}_{1}$ and ${B}_{2}$8 else $\phantom{(}$9 $\hspace{1em}\hspace{1em}{B}_{3}={B}_{1}{B}_{2}$10 Compute ${\beta}_{5}\approx {\left(\right)}^{{B}^{22}}1/22$ from ${B}_{1}$ and ${B}_{3}$11 end $\phantom{(}$12 if $|{\beta}_{k}-{\beta}_{k-1}|<tol$and ${\beta}_{k}<{\mathsf{\Theta}}_{k}$ then $\phantom{(}$13 $\hspace{1em}\hspace{1em}f=1$; $s=0$14 end $\phantom{(}$15 end $\phantom{(}$16 if $f=0$ then $\phantom{(}$17 $\hspace{1em}s=max\left(\right)open="("\; close=")">0,\left(\right)open="\lceil "\; close="\rceil ">{\frac{1}{2}log}_{2}({\beta}_{k}/{\mathsf{\Theta}}_{k})$18 end $\phantom{(}$19 if $s>0$ then $\phantom{(}$20 $\hspace{1em}{s}_{0}=max\left(\right)open="("\; close=")">0,\left(\right)open="\lceil "\; close="\rceil ">{\frac{1}{2}log}_{2}({\beta}_{k-1}/{\mathsf{\Theta}}_{k-1})$21 if ${s}_{0}=s$ then $\phantom{(}$22 $\hspace{1em}\hspace{1em}k=k-1$23 end $\phantom{(}$24 $\hspace{1em}A={2}^{-s}A$25 $\hspace{1em}{B}_{1}={4}^{-s}{B}_{1}$26 $\hspace{1em}{B}_{2}={16}^{-s}{B}_{2}$27 if $k=5$ then $\phantom{(}$28$\hspace{1em}\hspace{1em}{B}_{3}={64}^{-s}{B}_{3}$29 end $\phantom{(}$30 end $\phantom{(}$31 $m={m}_{k}$ |

## 3. Numerical Experiments

`tanh_expm`: this code corresponds to the implementation of Algorithm 1. For obtaining $m\in \left(\right)open="\{"\; close="\}">2,4,6,9,12,16,20,25,30$ and s and computing ${e}^{2A}$, it uses function`exptaynsv3`(see [26]).`tanh_tayps`: this development, based on Algorithm 2, incorporates Algorithm 4 for computing m and s, where m takes values in the same set than the`tanh_expm`code. The Paterson–Stockmeyer method is considered to evaluate the Taylor matrix polynomials.`tanh_pol`: this function, corresponding to Algorithm 3, employs Algorithm 5 in the m and s calculation, where $m\in \left(\right)open="\{"\; close="\}">2,4,8,14,21$. The Taylor matrix polynomials are evaluated by means of Sastre formulas.

`vpa`(variable-precision floating-point arithmetic) function. The test battery featured the following three sets:

- (a)
- Diagonalizable complex matrices: one hundred diagonalizable $128\times 128$ complex matrices obtained as the result of $A=V\xb7D\xb7{V}^{-1}$, where D is a diagonal matrix (with real and complex eigenvalues) and matrix V is an orthogonal matrix, $V=H/\sqrt{n}$, being H a Hadamard matrix and n is the matrix order. As 1-norm, we have that $2.56\le {\u2225A\u2225}_{1}\le 256$. The matrix hyperbolic tangent was calculated “exactly” as $tanh\left(A\right)=V\xb7tanh\left(D\right)\xb7{V}^{T}$ using the
`vpa`function. - (b)
- Non-diagonalizable complex matrices: one hundred non-diagonalizable $128\times 128$ complex matrices computed as $A=V\xb7J\xb7{V}^{-1}$, where J is a Jordan matrix with complex eigenvalues whose modules are less than 5 and the algebraic multiplicity is randomly generated between 1 and 4. V is an orthogonal random matrix with elements in the interval $[-0.5,0.5]$. As 1-norm, we obtained that $45.13\le {\u2225A\u2225}_{1}\le 51.18$. The “exact” matrix hyperbolic tangent was computed as $tanh\left(A\right)=V\xb7tanh\left(J\right)\xb7{V}^{-1}$ by means of the
`vpa`function. - (c)
- Matrices from the Matrix Computation Toolbox (MCT) [31] and from the Eigtool MATLAB Package (EMP) [32]: fifty-three matrices with a dimension lower than or equal to 128 were chosen because of their highly different and significant characteristics from each other. We decided to scale these matrices so that they had 1-norm not exceeding 512. As a result, we obtained that $1\le {\u2225A\u2225}_{1}\le 489.3$. The “exact” matrix hyperbolic tangent was calculated by using the two following methods together and the
`vpa`function:- Find a matrix V and a diagonal matrix D so that $A=VD{V}^{-1}$ by using the MATLAB function
`eig`. In this case, ${T}_{1}=Vtanh\left(D\right){V}^{-1}$. - Compute the Taylor approximation of the hyperbolic tangent function (${T}_{2}$), with different polynomial orders (m) and scaling parameters (s). This procedure is finished when the obtained result is the same for the distinct values of m and s in IEEE double precision.

The “exact” matrix hyperbolic tangent is considered only if$$\frac{\left(\right)}{{T}_{1}-{T}_{2}}\left(\right)open="\parallel "\; close="\parallel ">{T}_{1}u.$$

`tanh_expm`are lower than, greater than, or equal to those of

`tanh_tayps`and

`tanh_pol`. These normwise relative errors were obtained as

`tanh_tayps`outperformed

`tanh_expm`in 68% of the matrices for Test 1 and 100% and 77.36% of them for Tests 2 and 3. On the other hand,

`tanh_pol`obtained slightly more modest results with improvement percentages equal to 56%, 100%, and 69.81% for Tests 1, 2, and 3, respectively.

`tanh_expm`.

`tanh_expm`, followed by

`tanh_pol`and

`tanh_tayps`. For example,

`tanh_expm`demanded 1810 matrix products to compute the matrices belonging to Test 1, compared to 1847 by

`tanh_pol`and 2180 by

`tanh_tayps`.

`tanh_tayps`always achieved the results with the highest accuracy, followed closely by

`tanh_pol`. For Tests 1 and 2, Figure 1b and Figure 2b indicate that the results provided by them are very similar, although the difference in favour of

`tanh_tayps`is more remarkable in Test 3. As expected from the percentages given in Table 3,

`tanh_expm`computed the hyperbolic tangent function with the worst accuracy, most notably for the matrices from Tests 2 and 3.

`tanh_tayps`)/Er(

`tanh_expm`). This factor is less than 1 for the great majority of the matrices, which indicates that

`tanh_tayps`and

`tanh_pol`are more accurate codes than

`tanh_expm`for estimating the hyperbolic tangent function.

`tanh_tayps`exhibited the smallest relative error in 44% of the matrices for Test 1 and in 47% of them for Test 3, followed by

`tanh_pol`in 29% and 36% of the cases, respectively. For all the other cases,

`tanh_expm`was the most reliable method. For Test 2,

`tanh_pol`was the most accurate code in 53% of the matrices, and

`tanh_tayps`was the most accurate in 47% of them. In line with these results,

`tanh_expm`was found to be the approach that led to the largest relative errors in 51% of the cases in Test 1, in 100% of them in Test 2, and in 64% for Test 3.

`tanh_expm`proved to be the most inaccurate code, it is also evident that its computational cost was usually the lowest one, as Table 4 and Figure 1e, Figure 2e and Figure 3e reported. The ratio between the number of

`tanh_tayps`and

`tanh_expm`matrix products ranged from 0.82 to 1.43 for Test 1, was equal to 1.20 for Test 2, and ranged from 0.82 to 1.8 for Test 3. Regarding

`tanh_pol`and

`tanh_expm`, this quotient varied from 0.82 to 1.13 for Test 1, from 0.68 to 1.2 for Test 3, and was equal to 1 for Test 2.

`tanh_expm`and

`tanh_tayps`and between 2 and 21 for

`tanh_pol`. As we can see, the average value of m that was typically used varied from 25 and 30 for

`tanh_expm`. It was around 25 for

`tanh_tayps`, and it ranged from 14 to 21 for

`tanh_pol`.

`tanh_tayps`and

`tanh_pol`, the Taylor series-based codes that returned the best accuracy in the results. Table 6 presents the percentage of cases in which

`tanh_tayps`gave place to relative errors that were lower than, greater than, or equal to those of

`tanh_pol`. According to the exposed values, both methods provided very similar results, and the percentage of cases in which each method was more accurate than the other was approximately equal to 50% for the different tests.

`tanh_tayps`and

`tanh_pol`. The graphs corresponding to the performance profiles and the polynomial orders are not included now since the results match with those already shown in the previous figures. All this information is also complemented by Table 7, which collects, respectively for each test, the minimum, maximum, and average relative errors incurred by both methods to be analysed, together with the standard deviation.

`tanh_tayps`slightly improved on

`tanh_pol`in the percentage of matrices in which the relative error committed was lower, although it is true that the difference between the results provided by the two methods was small in most cases. However, when such a difference occurred, it was more often in favour of

`tanh_tayps`than the other way around, in quantitative terms.

`tanh_pol`were lower than those of

`tanh_tayps`. For matrices that were part of Test 2, the numerical results achieved by both methods were almost identical, and the differences between them were not significant.

`tanh_tayps`performed between 1 and $1.43$ more matrix products compared with

`tanh_pol`for Test 1, $1.2$ more for Test 2, and between $1.06$ and $1.5$ more for Test 3. Therefore,

`tanh_pol`computed the matrix tangent function with a very similar accuracy in the results compared to

`tanh_tayps`but with a considerably lower computational cost.

## 4. Conclusions

`tanh_expm`,

`tanh_tayps`, and

`tanh_pol`), which were evaluated on a complete testbed populated with matrices of three different types.

`tanh_tayps`implementation. One idea to reduce this problem is to use Sastre formulas, as we did in our

`tanh_pol`code, resulting in an efficient alternative that significantly reduced the number of matrix operations without affecting the accuracy.

`tanh_pol`implementation proposed here offered the best ratio of accuracy/computational cost and proved to be an excellent method for the computation of the matrix hyperbolic tangent.

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Conflicts of Interest

## References

- Constantine, A.; Muirhead, R. Partial differential equations for hypergeometric functions of two argument matrices. J. Multivar. Anal.
**1972**, 2, 332–338. [Google Scholar] [CrossRef] [Green Version] - James, A.T. Special functions of matrix and single argument in statistics. In Theory and Application of Special Functions; Academic Press: Cambridge, MA, USA, 1975; pp. 497–520. [Google Scholar]
- Hochbruck, M.; Ostermann, A. Exponential integrators. Acta Numer.
**2010**, 19, 209–286. [Google Scholar] [CrossRef] [Green Version] - Higham, N.J. Functions of Matrices: Theory and Computation; Society for Industrial and Applied Mathematics: Philadelphia, PA, USA, 2008; p. 425. [Google Scholar]
- Rinehart, R. The Equivalence of Definitions of a Matrix Function. Am. Math. Mon.
**1955**, 62, 395–414. [Google Scholar] [CrossRef] - Estrada, E.; Higham, D.J.; Hatano, N. Communicability and multipartite structures in complex networks at negative absolute temperatures. Phys. Rev. E
**2008**, 78, 026102. [Google Scholar] [CrossRef] [PubMed] [Green Version] - Jódar, L.; Navarro, E.; Posso, A.; Casabán, M. Constructive solution of strongly coupled continuous hyperbolic mixed problems. Appl. Numer. Math.
**2003**, 47, 477–492. [Google Scholar] [CrossRef] - Defez, E.; Sastre, J.; Ibáñez, J.; Peinado, J.; Tung, M.M. A method to approximate the hyperbolic sine of a matrix. Int. J. Complex Syst. Sci.
**2014**, 4, 41–45. [Google Scholar] - Defez, E.; Sastre, J.; Ibáñez, J.; Peinado, J. Solving engineering models using hyperbolic matrix functions. Appl. Math. Model.
**2016**, 40, 2837–2844. [Google Scholar] [CrossRef] - Defez, E.; Sastre, J.; Ibáñez, J.; Ruiz, P. Computing hyperbolic matrix functions using orthogonal matrix polynomials. In Progress in Industrial Mathematics at ECMI 2012; Springer: Berlin/Heidelberg, Germany, 2014; pp. 403–407. [Google Scholar]
- Defez, E.; Sastre, J.; Ibánez, J.; Peinado, J.; Tung, M.M. On the computation of the hyperbolic sine and cosine matrix functions. Model. Eng. Hum. Behav.
**2013**, 1, 46–59. [Google Scholar] - Efimov, G.V.; Von Waldenfels, W.; Wehrse, R. Analytical solution of the non-discretized radiative transfer equation for a slab of finite optical depth. J. Quant. Spectrosc. Radiat. Transf.
**1995**, 53, 59–74. [Google Scholar] [CrossRef] - Lehtinen, A. Analytical Treatment of Heat Sinks Cooled by Forced Convection. Ph.D. Thesis, Tampere University of Technology, Tampere, Finland, 2005. [Google Scholar]
- Lampio, K. Optimization of Fin Arrays Cooled by Forced or Natural Convection. Ph.D. Thesis, Tampere University of Technology, Tampere, Finland, 2018. [Google Scholar]
- Hilscher, R.; Zemánek, P. Trigonometric and hyperbolic systems on time scales. Dyn. Syst. Appl.
**2009**, 18, 483. [Google Scholar] - Zemánek, P. New Results in Theory of Symplectic Systems on Time Scales. Ph.D. Thesis, Masarykova Univerzita, Brno, Czech Republic, 2011. [Google Scholar]
- Estrada, E.; Silver, G. Accounting for the role of long walks on networks via a new matrix function. J. Math. Anal. Appl.
**2017**, 449, 1581–1600. [Google Scholar] [CrossRef] [Green Version] - Cieśliński, J.L. Locally exact modifications of numerical schemes. Comput. Math. Appl.
**2013**, 65, 1920–1938. [Google Scholar] [CrossRef] - Cieśliński, J.L.; Kobus, A. Locally Exact Integrators for the Duffing Equation. Mathematics
**2020**, 8, 231. [Google Scholar] [CrossRef] [Green Version] - Golub, G.H.; Loan, C.V. Matrix Computations, 3rd ed.; Johns Hopkins Studies in Mathematical Sciences; The Johns Hopkins University Press: Baltimore, MD, USA, 1996. [Google Scholar]
- Moler, C.; Van Loan, C. Nineteen Dubious Ways to Compute the Exponential of a Matrix, Twenty-Five Years Later. SIAM Rev.
**2003**, 45, 3–49. [Google Scholar] [CrossRef] - Sastre, J.; Ibáñez, J.; Defez, E. Boosting the computation of the matrix exponential. Appl. Math. Comput.
**2019**, 340, 206–220. [Google Scholar] [CrossRef] - Sastre, J.; Ibáñez, J.; Defez, E.; Ruiz, P. Efficient orthogonal matrix polynomial based method for computing matrix exponential. Appl. Math. Comput.
**2011**, 217, 6451–6463. [Google Scholar] [CrossRef] [Green Version] - Sastre, J.; Ibáñez, J.; Defez, E.; Ruiz, P. New scaling-squaring Taylor algorithms for computing the matrix exponential. SIAM J. Sci. Comput.
**2015**, 37, A439–A455. [Google Scholar] [CrossRef] - Defez, E.; Ibánez, J.; Alonso-Jordá, P.; Alonso, J.; Peinado, J. On Bernoulli matrix polynomials and matrix exponential approximation. J. Comput. Appl. Math.
**2020**, 113207. [Google Scholar] [CrossRef] - Ruiz, P.; Sastre, J.; Ibáñez, J.; Defez, E. High perfomance computing of the matrix exponential. J. Comput. Appl. Math.
**2016**, 291, 370–379. [Google Scholar] [CrossRef] - Paterson, M.S.; Stockmeyer, L.J. On the Number of Nonscalar Multiplications Necessary to Evaluate Polynomials. SIAM J. Comput.
**1973**, 2, 60–66. [Google Scholar] [CrossRef] [Green Version] - Sastre, J. Efficient evaluation of matrix polynomials. Linear Algebra Appl.
**2018**, 539, 229–250. [Google Scholar] [CrossRef] - Al-Mohy, A.H.; Higham, N.J. A New Scaling and Squaring Algorithm for the Matrix Exponential. SIAM J. Matrix Anal. Appl.
**2009**, 31, 970–989. [Google Scholar] [CrossRef] [Green Version] - Higham, N.J. FORTRAN Codes for Estimating the One-norm of a Real or Complex Matrix, with Applications to Condition Estimation. ACM Trans. Math. Softw.
**1988**, 14, 381–396. [Google Scholar] [CrossRef] - Higham, N.J. The Matrix Computation Toolbox. 2002. Available online: http://www.ma.man.ac.uk/~higham/mctoolbox (accessed on 7 March 2020).
- Wright, T.G. Eigtool, Version 2.1. 2009. Available online: http://www.comlab.ox.ac.uk/pseudospectra/eigtool (accessed on 7 March 2020).
- Corwell, J.; Blair, W.D. Industry Tip: Quick and Easy Matrix Exponentials. IEEE Aerosp. Electron. Syst. Mag.
**2020**, 35, 49–52. [Google Scholar] [CrossRef]

**Table 1.**Values of ${\mathsf{\Theta}}_{{m}_{k}}$, $1\le k\le 9,$ for polynomial evaluation by means of the Paterson–Stockmeyer method.

${m}_{1}=2$ | $1.1551925093100\times {10}^{-3}$ |

${m}_{2}=4$ | $2.8530558816082\times {10}^{-2}$ |

${m}_{3}=6$ | $9.7931623314428\times {10}^{-2}$ |

${m}_{4}=9$ | $2.3519926145338\times {10}^{-1}$ |

${m}_{5}=12$ | $3.7089935615781\times {10}^{-1}$ |

${m}_{6}=16$ | $5.2612365603423\times {10}^{-1}$ |

${m}_{7}=20$ | $6.5111831924355\times {10}^{-1}$ |

${m}_{8}=25$ | $7.73638541973549\times {10}^{-1}$ |

${m}_{9}=30$ | $8.68708923627294\times {10}^{-1}$ |

**Table 2.**Values of ${\mathsf{\Theta}}_{{m}_{k}}$, $1\le k\le 5,$ for polynomial evaluation using the Sastre formulas.

${m}_{1}=2$ | $1.1551925093100\times {10}^{-3}$ |

${m}_{2}=4$ | $2.8530558816082\times {10}^{-2}$ |

${m}_{3}=8$ | $1.88126704493647\times {10}^{-1}$ |

${m}_{4}=14+$ | $4.65700446893510\times {10}^{-1}$ |

${m}_{5}=21+$ | $6.84669656651721\times {10}^{-1}$ |

**Table 3.**The relative error comparison, for the three tests, between

`tanh_expm`vs.

`tanh_tayps`and

`tanh_expm`vs

`tanh_pol`.

Test 1 | Test 2 | Test 3 | |
---|---|---|---|

Er(tanh_expm)<Er(tanh_tayps) | 32% | 0% | 22.64% |

Er(tanh_expm)>Er(tanh_tayps) | 68% | 100% | 77.36% |

Er(tanh_expm)=Er(tanh_tayps) | 0% | 0% | 0% |

Er(tanh_expm)<Er(tanh_pol) | 44% | 0% | 30.19% |

Er(tanh_expm)>Er(tanh_pol) | 56% | 100% | 69.81% |

Er(tanh_expm)=Er(tanh_pol) | 0% | 0% | 0% |

**Table 4.**Matrix products (P) corresponding to the

`tanh_expm`,

`tanh_tayps`, and

`tanh_pol`functions for Tests 1–3.

Test 1 | Test 2 | Test 3 | |
---|---|---|---|

P(tanh_expm) | 1810 | 1500 | 848 |

P(tanh_tayps) | 2180 | 1800 | 1030 |

P(tanh_pol) | 1847 | 1500 | 855 |

m | s | |||||
---|---|---|---|---|---|---|

Min. | Max. | Average | Min. | Max. | Average | |

tanh_expm | 16 | 30 | 27.41 | 0 | 5 | 3.55 |

tanh_tayps | 9 | 30 | 25.09 | 0 | 6 | 4.65 |

tanh_pol | 14 | 21 | 15.47 | 0 | 6 | 4.83 |

tanh_expm | 30 | 30 | 30.00 | 2 | 2 | 2.00 |

tanh_tayps | 25 | 25 | 25.00 | 3 | 3 | 3.00 |

tanh_pol | 21 | 21 | 21.00 | 3 | 3 | 3.00 |

tanh_expm | 2 | 30 | 26.23 | 0 | 8 | 2.77 |

tanh_tayps | 9 | 30 | 24.38 | 0 | 9 | 3.74 |

tanh_pol | 4 | 21 | 15.36 | 0 | 9 | 3.87 |

Test 1 | Test 2 | Test 3 | |
---|---|---|---|

Er(tanh_tayps)<Er(tanh_pol) | 56% | 47% | 50.94% |

Er(tanh_tayps)>Er(tanh_pol) | 44% | 53% | 45.28% |

Er(tanh_tayps)=Er(tanh_pol) | 0% | 0% | 3.77% |

**Table 7.**The minimum, maximum, and average values and the standard deviation of the relative errors committed by

`tanh_tayps`and

`tanh_pol`for Tests 1–3.

Minimum | Maximum | Average | Standard Deviation | |
---|---|---|---|---|

tanh_tayps | $4.84\times {10}^{-16}$ | $6.45\times {10}^{-12}$ | $1.22\times {10}^{-13}$ | $7.40\times {10}^{-13}$ |

tanh_pol | $4.55\times {10}^{-16}$ | $3.64\times {10}^{-12}$ | $8.48\times {10}^{-14}$ | $4.69\times {10}^{-13}$ |

tanh_tayps | $9.71\times {10}^{-16}$ | $9.06\times {10}^{-14}$ | $1.25\times {10}^{-14}$ | $1.41\times {10}^{-14}$ |

tanh_pol | $9.92\times {10}^{-16}$ | $9.35\times {10}^{-14}$ | $1.26\times {10}^{-14}$ | $1.47\times {10}^{-14}$ |

tanh_tayps | $1.09\times {10}^{-254}$ | $1.10\times {10}^{-10}$ | $2.26\times {10}^{-12}$ | $1.52\times {10}^{-11}$ |

tanh_pol | $1.09\times {10}^{-254}$ | $1.16\times {10}^{-11}$ | $4.10\times {10}^{-13}$ | $1.96\times {10}^{-12}$ |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2021 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/).

## Share and Cite

**MDPI and ACS Style**

Ibáñez, J.; Alonso, J.M.; Sastre, J.; Defez, E.; Alonso-Jordá, P.
Advances in the Approximation of the Matrix Hyperbolic Tangent. *Mathematics* **2021**, *9*, 1219.
https://doi.org/10.3390/math9111219

**AMA Style**

Ibáñez J, Alonso JM, Sastre J, Defez E, Alonso-Jordá P.
Advances in the Approximation of the Matrix Hyperbolic Tangent. *Mathematics*. 2021; 9(11):1219.
https://doi.org/10.3390/math9111219

**Chicago/Turabian Style**

Ibáñez, Javier, José M. Alonso, Jorge Sastre, Emilio Defez, and Pedro Alonso-Jordá.
2021. "Advances in the Approximation of the Matrix Hyperbolic Tangent" *Mathematics* 9, no. 11: 1219.
https://doi.org/10.3390/math9111219