F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF01HAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

F01HAF computes the action of the matrix exponential ${e}^{tA}$, on the matrix $B$, where $A$ is a complex $n$ by $n$ matrix, $B$ is a complex $n$ by $m$ matrix and $t$ is a complex scalar.

## 2  Specification

 SUBROUTINE F01HAF ( N, M, A, LDA, B, LDB, T, IFAIL)
 INTEGER N, M, LDA, LDB, IFAIL COMPLEX (KIND=nag_wp) A(LDA,*), B(LDB,*), T

## 3  Description

${e}^{tA}B$ is computed using the algorithm described in Al–Mohy and Higham (2011) which uses a truncated Taylor series to compute the product ${e}^{tA}B$ without explicitly forming ${e}^{tA}$.

## 4  References

Al–Mohy A H and Higham N J (2011) Computing the action of the matrix exponential, with an application to exponential integrators SIAM J. Sci. Statist. Comput. 33(2) 488-511
Higham N J (2008) Functions of Matrices: Theory and Computation SIAM, Philadelphia, PA, USA

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{N}}\ge 0$.
2:     M – INTEGERInput
On entry: $m$, the number of columns of the matrix $B$.
Constraint: ${\mathbf{M}}\ge 0$.
3:     A(LDA,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array A must be at least ${\mathbf{N}}$.
On entry: the $n$ by $n$ matrix $A$.
On exit: $A$ is overwritten during the computation.
4:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F01HAF is called.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
5:     B(LDB,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array B must be at least ${\mathbf{M}}$.
On entry: the $n$ by $m$ matrix $B$.
On exit: the $n$ by $m$ matrix ${e}^{tA}B$.
6:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F01HAF is called.
Constraint: ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
7:     T – COMPLEX (KIND=nag_wp)Input
On entry: the scalar $t$.
8:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
Note:  this failure should not occur, and suggests that the routine has been called incorrectly. An unexpected internal error occurred when trying to balance the matrix $A$.
${\mathbf{IFAIL}}=2$
${\mathbf{IFAIL}}=-1$
On entry, ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{N}}\ge 0$.
${\mathbf{IFAIL}}=-2$
On entry, ${\mathbf{M}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{M}}\ge 0$.
${\mathbf{IFAIL}}=-4$
On entry, ${\mathbf{LDA}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDA}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
${\mathbf{IFAIL}}=-6$
On entry, ${\mathbf{LDB}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
${\mathbf{IFAIL}}=-999$
Allocation of memory failed.

## 7  Accuracy

For a Hermitian matrix $A$ (for which ${A}^{\mathrm{H}}=A$) the computed matrix ${e}^{tA}B$ is guaranteed to be close to the exact matrix, that is, the method is forward stable. No such guarantee can be given for non-Hermitian matrices. See Section 4 of Al–Mohy and Higham (2011) for details and further discussion.

## 8  Further Comments

The matrix ${e}^{tA}B$ could be computed by explicitly forming ${e}^{tA}$ using F01FCF and multiplying $B$ by the result. However, experiments show that it is usually both more accurate and quicker to use F01HAF.
The cost of the algorithm is $\mathit{O}\left({n}^{2}m\right)$. The precise cost depends on $A$ since a combination of balancing, shifting and scaling is used prior to the Taylor series evaluation.
Approximately ${n}^{2}+\left(2m+8\right)n$ of complex allocatable memory is required by F01HAF.
F01GAF can be used to compute ${e}^{tA}B$ for real $A$, $B$, and $t$. F01HBF provides an implementation of the algorithm with a reverse communication interface, which returns control to the user when matrix multiplications are required. This should be used if $A$ is large and sparse.

## 9  Example

This example computes ${e}^{tA}B$, where
 $A = 0.5+0.0i -0.2+0.0i 1.0+0.1i 0.0+0.4i 0.3+0.0i 0.5+1.2i 3.1+0.0i 1.0+0.2i 0.0+2.0i 0.1+0.0i 1.2+0.2i 0.5+0.0i 1.0+0.3i 0.0+0.2i 0.0+0.9i 0.5+0.0i ,$
 $B = 0.4+0.0i 1.2+0.0i 1.3+0.0i -0.2+0.1i 0.0+0.3i 2.1+0.0i 0.4+0.0i -0.9+0.0i$
and
 $t=-0.5 .$

### 9.1  Program Text

Program Text (f01hafe.f90)

### 9.2  Program Data

Program Data (f01hafe.d)

### 9.3  Program Results

Program Results (f01hafe.r)