Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_matop_complex_gen_matrix_exp (f01fc)

## Purpose

nag_matop_complex_gen_matrix_exp (f01fc) computes the matrix exponential, eA${e}^{A}$, of a complex n$n$ by n$n$ matrix A$A$.

## Syntax

[a, ifail] = f01fc(a, 'n', n)
[a, ifail] = nag_matop_complex_gen_matrix_exp(a, 'n', n)

## Description

eA${e}^{A}$ is computed using a Padé approximant and the scaling and squaring method described in Higham (2005) and Higham (2008).
If A$A$ has a full set of eigenvectors V$V$ then A$A$ can be factorized as
 A = V D V − 1 , $A = V D V-1 ,$
where D$D$ is the diagonal matrix whose diagonal elements, di${d}_{i}$, are the eigenvalues of A$A$. eA${e}^{A}$ is then given by
 eA = V eD V − 1 , $eA = V eD V-1 ,$
where eD${e}^{D}$ is the diagonal matrix whose i$i$th diagonal element is edi${e}^{{d}_{i}}$.
Note that eA${e}^{A}$ is not computed this way as to do so would, in general, be unstable.

## References

Higham N J (2005) The scaling and squaring method for the matrix exponential revisited SIAM J. Matrix Anal. Appl. 26(4) 1179–1193
Higham N J (2008) Functions of Matrices: Theory and Computation SIAM, Philadelphia, PA, USA
Moler C B and Van Loan C F (2003) Nineteen dubious ways to compute the exponential of a matrix, twenty-five years later SIAM Rev. 45 3–49

## Parameters

### Compulsory Input Parameters

1:     a(lda, : $:$) – complex array
The first dimension of the array a must be at least max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array must be at least n${\mathbf{n}}$
The n$n$ by n$n$ matrix A$A$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The first dimension of the array a.
n$n$, the order of the matrix A$A$.
Constraint: n0${\mathbf{n}}\ge 0$.

lda

### Output Parameters

1:     a(lda, : $:$) – complex array
The first dimension of the array a will be max (1,n)$\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
The second dimension of the array will be n${\mathbf{n}}$
ldamax (1,n)$\mathit{lda}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$.
With ${\mathbf{ifail}}={\mathbf{0}}$, the n$n$ by n$n$ matrix exponential eA${e}^{A}$.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
The linear equations to be solved for the Padé approximant are singular; it is likely that this function has been called incorrectly.
ifail = 2${\mathbf{ifail}}=2$
The linear equations to be solved are nearly singular and the Padé approximant probably has no correct figures; it is likely that this function has been called incorrectly.
ifail = 3${\mathbf{ifail}}=3$
The arithmetic precision is higher than that used for the Padé approximant computed matrix exponential.
ifail = 4${\mathbf{ifail}}=4$
ifail = 1${\mathbf{ifail}}=-1$
Constraint: n0${\mathbf{n}}\ge 0$.
ifail = 2${\mathbf{ifail}}=-2$
ifail = 3${\mathbf{ifail}}=-3$
Constraint: ldan$\mathit{lda}\ge {\mathbf{n}}$.
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

For a normal matrix A$A$ (for which AHA = AAH${A}^{\mathrm{H}}A=A{A}^{\mathrm{H}}$) the computed matrix, eA${e}^{A}$, is guaranteed to be close to the exact matrix, that is, the method is forward stable. No such guarantee can be given for non-normal matrices. See Section 10.3 of Higham (2008) for details and further discussion.
For discussion of the condition of the matrix exponential see Section 10.2 of Higham (2008).

The cost of the algorithm is O(n3)$O\left({n}^{3}\right)$; see Algorithm 10.20 in Higham (2008).
If estimates of the condition number of the matrix exponential are required then nag_matop_complex_gen_matrix_cond_std (f01ka) should be used.
As well as the excellent book cited above, the classic reference for the computation of the matrix exponential is Moler and Van Loan (2003).

## Example

```function nag_matop_complex_gen_matrix_exp_example
a = [ 1 + 1i,  2 + 1i,  2 + 1i,  2 + 1i;
3 + 2i,  1 + 0i,  1 + 0i,  2 + 1i;
3 + 2i,  2 + 1i,  1 + 0i,  2 + 1i;
3 + 2i,  3 + 2i,  3 + 2i,  1 + 1i];
% Compute exp(a)
[aOut, ifail] = nag_matop_complex_gen_matrix_exp(a);
% Display results
[ifail] = nag_file_print_matrix_complex_gen('g', ' ', aOut, 'Exp(a)')
```
```
Exp(a)
1          2          3          4
1   -157.9003  -194.6526  -186.5627  -155.7669
-754.3717  -555.0507  -475.4533  -520.1876

2   -206.8899  -225.4985  -212.4414  -186.5627
-694.7443  -505.3938  -431.0611  -475.4533

3   -208.7476  -238.4962  -225.4985  -194.6526
-808.2090  -590.8045  -505.3938  -555.0507

4   -133.3958  -208.7476  -206.8899  -157.9003
-1085.5496  -808.2090  -694.7443  -754.3717

ifail =

0

```
```function f01fc_example
a = [ 1 + 1i,  2 + 1i,  2 + 1i,  2 + 1i;
3 + 2i,  1 + 0i,  1 + 0i,  2 + 1i;
3 + 2i,  2 + 1i,  1 + 0i,  2 + 1i;
3 + 2i,  3 + 2i,  3 + 2i,  1 + 1i];
% Compute exp(a)
[aOut, ifail] = f01fc(a);
% Display results
[ifail] = x04da('g', ' ', aOut, 'Exp(a)')
```
```
Exp(a)
1          2          3          4
1   -157.9003  -194.6526  -186.5627  -155.7669
-754.3717  -555.0507  -475.4533  -520.1876

2   -206.8899  -225.4985  -212.4414  -186.5627
-694.7443  -505.3938  -431.0611  -475.4533

3   -208.7476  -238.4962  -225.4985  -194.6526
-808.2090  -590.8045  -505.3938  -555.0507

4   -133.3958  -208.7476  -206.8899  -157.9003
-1085.5496  -808.2090  -694.7443  -754.3717

ifail =

0

```