F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF01HBF

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

F01HBF 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. It uses reverse communication for evaluating matrix products, so that the matrix $A$ is not accessed explicitly.

## 2  Specification

 SUBROUTINE F01HBF ( IREVCM, N, M, B, LDB, T, TR, B2, LDB2, X, LDX, Y, LDY, P, R, Z, CCOMM, COMM, ICOMM, IFAIL)
 INTEGER IREVCM, N, M, LDB, LDB2, LDX, LDY, ICOMM(2*N+40), IFAIL REAL (KIND=nag_wp) COMM(3*N+14) COMPLEX (KIND=nag_wp) B(LDB,*), T, TR, B2(LDB2,*), X(LDX,*), Y(LDY,*), P(N), R(N), Z(N), CCOMM(N*(M+2))

## 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 ${e}^{tA}B$ without explicitly forming ${e}^{tA}$.
The algorithm does not explicity need to access the elements of $A$; it only requires the result of matrix multiplications of the form $AX$ or ${A}^{\mathrm{H}}Y$. A reverse communication interface is used, in which control is returned to the calling program whenever a matrix product is required.

## 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

Note:  this routine uses reverse communication. Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the parameter IREVCM. Between intermediate exits and re-entries, all parameters other than B2, X, Y, P and R must remain unchanged.
1:     IREVCM – INTEGERInput/Output
On initial entry: must be set to $0$.
On intermediate exit: ${\mathbf{IREVCM}}=1$, $2$, $3$, $4$ or $5$. The calling program must:
 (a) if ${\mathbf{IREVCM}}=1$: evaluate ${B}_{2}=AB$, where ${B}_{2}$ is an $n$ by $m$ matrix, and store the result in B2; if ${\mathbf{IREVCM}}=2$: evaluate $Y=AX$, where $X$ and $Y$ are $n$ by $2$ matrices, and store the result in Y; if ${\mathbf{IREVCM}}=3$: evaluate $X={A}^{\mathrm{H}}Y$ and store the result in X; if ${\mathbf{IREVCM}}=4$: evaluate $p=Az$ and store the result in P; if ${\mathbf{IREVCM}}=5$: evaluate $r={A}^{\mathrm{H}}z$ and store the result in R. (b) call F01HBF again with all other parameters unchanged.
On final exit: ${\mathbf{IREVCM}}=0$.
2:     N – INTEGERInput
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{N}}\ge 0$.
3:     M – INTEGERInput
On entry: the number of columns of the matrix $B$.
Constraint: ${\mathbf{M}}\ge 0$.
4:     B(LDB,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array B must be at least ${\mathbf{M}}$.
On initial entry: the $n$ by $m$ matrix $B$.
On intermediate exit: if ${\mathbf{IREVCM}}=1$, contains the $n$ by $m$ matrix $B$.
On intermediate re-entry: must not be changed.
On final exit: the $n$ by $m$ matrix ${e}^{tA}B$.
5:     LDB – INTEGERInput
On entry: the first dimension of the array B as declared in the (sub)program from which F01HBF is called.
Constraint: ${\mathbf{LDB}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
6:     T – COMPLEX (KIND=nag_wp)Input
On entry: the scalar $t$.
7:     TR – COMPLEX (KIND=nag_wp)Input
On entry: the trace of $A$. If this is not available then any number can be supplied ($0$ is a reasonable default); however, in the trivial case, $n=1$, the result ${e}^{{\mathbf{TR}}t}B$ is immediately returned in the first row of $B$. See Section 8.
8:     B2(LDB2,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array B2 must be at least ${\mathbf{M}}$.
On initial entry: need not be set.
On intermediate re-entry: if ${\mathbf{IREVCM}}=1$, must contain $AB$.
On final exit: the array is undefined.
9:     LDB2 – INTEGERInput
On initial entry: the first dimension of the array B2 as declared in the (sub)program from which F01HBF is called.
Constraint: ${\mathbf{LDB2}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
10:   X(LDX,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array X must be at least $2$.
On initial entry: need not be set.
On intermediate exit: if ${\mathbf{IREVCM}}=2$, contains the current $n$ by $2$ matrix $X$.
On intermediate re-entry: if ${\mathbf{IREVCM}}=3$, must contain ${A}^{\mathrm{H}}Y$.
On final exit: the array is undefined.
11:   LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which F01HBF is called.
Constraint: ${\mathbf{LDX}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
12:   Y(LDY,$*$) – COMPLEX (KIND=nag_wp) arrayInput/Output
Note: the second dimension of the array Y must be at least $2$.
On initial entry: need not be set.
On intermediate exit: if ${\mathbf{IREVCM}}=3$, contains the current $n$ by $2$ matrix $Y$.
On intermediate re-entry: if ${\mathbf{IREVCM}}=2$, must contain $AX$.
On final exit: the array is undefined.
13:   LDY – INTEGERInput
On entry: the first dimension of the array Y as declared in the (sub)program from which F01HBF is called.
Constraint: ${\mathbf{LDY}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
14:   P(N) – COMPLEX (KIND=nag_wp) arrayInput/Output
On initial entry: need not be set.
On intermediate re-entry: if ${\mathbf{IREVCM}}=4$, must contain $Az$.
On final exit: the array is undefined.
15:   R(N) – COMPLEX (KIND=nag_wp) arrayInput/Output
On initial entry: need not be set.
On intermediate re-entry: if ${\mathbf{IREVCM}}=5$, must contain ${A}^{\mathrm{H}}z$.
On final exit: the array is undefined.
16:   Z(N) – COMPLEX (KIND=nag_wp) arrayInput/Output
On initial entry: need not be set.
On intermediate exit: if ${\mathbf{IREVCM}}=4$ or $5$, contains the vector $z$.
On intermediate re-entry: must not be changed.
On final exit: the array is undefined.
17:   CCOMM(${\mathbf{N}}×\left({\mathbf{M}}+2\right)$) – COMPLEX (KIND=nag_wp) arrayCommunication Array
18:   COMM($3×{\mathbf{N}}+14$) – REAL (KIND=nag_wp) arrayCommunication Array
19:   ICOMM($2×{\mathbf{N}}+40$) – INTEGER arrayCommunication Array
20:   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 estimating a matrix norm.
${\mathbf{IFAIL}}=2$
${\mathbf{IFAIL}}=-1$
On initial entry, ${\mathbf{IREVCM}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{IREVCM}}=0$.
On intermediate re-entry, ${\mathbf{IREVCM}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{IREVCM}}=1$, $2$, $3$, $4$ or $5$.
${\mathbf{IFAIL}}=-2$
On initial entry, ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{N}}\ge 0$.
${\mathbf{IFAIL}}=-3$
On initial entry, ${\mathbf{M}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{M}}\ge 0$.
${\mathbf{IFAIL}}=-5$
On initial 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}}=-9$
On initial entry, ${\mathbf{LDB2}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDB2}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
${\mathbf{IFAIL}}=-11$
On initial entry, ${\mathbf{LDX}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDX}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.
${\mathbf{IFAIL}}=-13$
On initial entry, ${\mathbf{LDY}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{N}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{LDY}}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}\right)$.

## 7  Accuracy

For an 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.1  Use of $Tr\left(A\right)$

The elements of $A$ are not explicitly required by F01HBF. However, the trace of $A$ is used in the preprocessing phase of the algorithm. If $Tr\left(A\right)$ is not available to the calling subroutine then any number can be supplied ($0$ is recommended). This will not affect the stability of the algorithm, but it may reduce its efficiency.

### 8.2  When to use F01HBF

F01HBF is designed to be used when $A$ is large and sparse. Whenever a matrix multiplication is required, the routine will return control to the calling program so that the multiplication can be done in the most efficient way possible. Note that ${e}^{tA}B$ will not, in general, be sparse even if $A$ is sparse.
If $A$ is small and dense then F01HAF can be used to compute ${e}^{tA}B$ without the use of a reverse communication interface.
The real analog of F01HBF is F01GBF.

### 8.3  Use in Conjunction with NAG Library Routines

To compute ${e}^{tA}B$, the following skeleton code can normally be used:
```revcm: Do
Call F01HBF(IREVCM,N,M,B,LDB,T,TR,B2,LDB2,X,LDX,Y,LDX,P,R,Z, &
CCOMM,COMM,ICOMM,IFAIL)
If (IREVCM == 0) Then
Exit revcm
Else If (IREVCM == 1) Then
.. Code to compute B2=AB ..
Else If (IREVCM == 2) Then
.. Code to compute Y=AX ..
Else If (IREVCM == 3) Then
.. Code to compute X=A^H Y ..
Else If (IREVCM == 4) Then
.. Code to compute P=AZ ..
Else If (IREVCM == 5) Then
.. Code to compute R=A^H Z ..
End If
End Do revcm
```
The code used to compute the matrix products will vary depending on the way $A$ is stored. If all the elements of $A$ are stored explicitly, then F06ZAF (ZGEMM) can be used. If $A$ is triangular then F06ZFF (ZTRMM) should be used. If $A$ is Hermitian, then F06ZCF (ZHEMM) should be used. If $A$ is symmetric, then F06ZTF (ZSYMM) should be used. For sparse $A$ stored in coordinate storage format F11XNF and F11XSF can be used.

## 9  Example

This example computes ${e}^{tA}B$ where
 $A = 0.7+0.8i -0.2+0.0i 1.0+0.0i 0.6+0.5i 0.3+0.7i 0.7+0.0i 0.9+3.0i 1.0+0.8i 0.3+3.0i -0.7+0.0i 0.2+0.6i 0.7+0.5i 0.0+0.9i 4.0+0.0i 0.0+0.0i 0.2+0.0i ,$
 $B = 0.1+0.0i 1.2+0.1i 1.3+0.9i -0.2+2.0i 4.0+0.6i -1.0+0.8i 0.4+0.0i -0.9+0.0i$
and
 $t=1.1 .$

### 9.1  Program Text

Program Text (f01hbfe.f90)

### 9.2  Program Data

Program Data (f01hbfe.d)

### 9.3  Program Results

Program Results (f01hbfe.r)