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_real_gen_matrix_exp (f01ec)

## Purpose

nag_matop_real_gen_matrix_exp (f01ec) computes the matrix exponential, eA${e}^{A}$, of a real n$n$ by n$n$ matrix A$A$.

## Syntax

[a, ifail] = f01ec(a, 'n', n)
[a, ifail] = nag_matop_real_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, : $:$) – double 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, : $:$) – double 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)$.
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:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail < 0andifail4${\mathbf{ifail}}<0 \text{and} {\mathbf{ifail}}\ge -4$
If ifail = i${\mathbf{ifail}}=-i$, the i$i$th argument had an illegal value.
ifail = 999${\mathbf{ifail}}=-999$
Allocation of memory failed. The integer allocatable memory required is n, and the double allocatable memory required is approximately 6 × n2$6×{{\mathbf{n}}}^{2}$.
ifail = 1${\mathbf{ifail}}=1$
Note: this failure should not occur, and suggests that the function has been called incorrectly.
The linear equations to be solved for the Padé approximant are singular.
ifail = 2${\mathbf{ifail}}=2$
Note: this failure should not occur, and suggests that the function has been called incorrectly.
The linear equations to be solved are nearly singular and the Padé approximant probably has no correct figures.
W ifail = N + 2${\mathbf{ifail}}={\mathbf{N}}+2$
eA${e}^{A}$ has been computed using an IEEE double precision Padé approximant, although the arithmetic precision is higher than IEEE double precision.

## Accuracy

For a normal matrix A$A$ (for which ATA = AAT${A}^{\mathrm{T}}A=A{A}^{\mathrm{T}}$) 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 of Higham (2008).
If estimates of the condition number of the matrix exponential are required then nag_matop_real_gen_matrix_cond_std (f01ja) 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_real_gen_matrix_exp_example
a = [1, 2, 2, 2;
3, 1, 1, 2;
3, 2, 1, 2;
3, 3, 3, 1];
[aOut, ifail] = nag_matop_real_gen_matrix_exp(a)
```
```

aOut =

740.7038  610.8500  542.2743  549.1753
731.2510  603.5524  535.0884  542.2743
823.7630  679.4257  603.5524  610.8500
998.4355  823.7630  731.2510  740.7038

ifail =

0

```
```function f01ec_example
a = [1, 2, 2, 2;
3, 1, 1, 2;
3, 2, 1, 2;
3, 3, 3, 1];
[aOut, ifail] = f01ec(a)
```
```

aOut =

740.7038  610.8500  542.2743  549.1753
731.2510  603.5524  535.0884  542.2743
823.7630  679.4257  603.5524  610.8500
998.4355  823.7630  731.2510  740.7038

ifail =

0

```