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, ${e}^{A}$, of a real $n$ by $n$ matrix $A$.

## Syntax

[a, ifail] = f01ec(a, 'n', n)
[a, ifail] = nag_matop_real_gen_matrix_exp(a, 'n', n)

## Description

${e}^{A}$ is computed using a Padé approximant and the scaling and squaring method described in Al–Mohy and Higham (2009).

## References

Al–Mohy A H and Higham N J (2009) A new scaling and squaring algorithm for the matrix exponential SIAM J. Matrix Anal. 31(3) 970–989
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:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a must be at least ${\mathbf{n}}$.
The second dimension of the array a must be at least ${\mathbf{n}}$.
The $n$ by $n$ matrix $A$.

### Optional Input Parameters

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

### Output Parameters

1:     $\mathrm{a}\left(\mathit{lda},:\right)$ – double array
The first dimension of the array a will be ${\mathbf{n}}$.
The second dimension of the array a will be ${\mathbf{n}}$.
The $n$ by $n$ matrix exponential ${e}^{A}$.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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.

${\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.
${\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.
W  ${\mathbf{ifail}}=3$
${e}^{A}$ has been computed using an IEEE double precision Padé approximant, although the arithmetic precision is higher than IEEE double precision.
${\mathbf{ifail}}=4$
${\mathbf{ifail}}=-1$
Constraint: ${\mathbf{n}}\ge 0$.
${\mathbf{ifail}}=-3$
Constraint: $\mathit{lda}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

For a normal matrix $A$ (for which ${A}^{\mathrm{T}}A=A{A}^{\mathrm{T}}$) the computed matrix, ${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 Al–Mohy and Higham (2009) and Section 10.3 of Higham (2008) for details and further discussion.
If estimates of the condition number of the matrix exponential are required then nag_matop_real_gen_matrix_cond_exp (f01jg) should be used.

The integer allocatable memory required is n, and the double allocatable memory required is approximately $6×{{\mathbf{n}}}^{2}$.
The cost of the algorithm is $O\left({n}^{3}\right)$; see Section 5 of of Al–Mohy and Higham (2009). The real allocatable memory required is approximately $6×{n}^{2}$.
If the Fréchet derivative of the matrix exponential is required then nag_matop_real_gen_matrix_frcht_exp (f01jh) 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

This example finds the matrix exponential of the matrix
 $A = 1 2 2 2 3 1 1 2 3 2 1 2 3 3 3 1 .$
```function f01ec_example

fprintf('f01ec example results\n\n');

a = [1, 2, 2, 2;
3, 1, 1, 2;
3, 2, 1, 2;
3, 3, 3, 1];

[expa, ifail] = f01ec(a);

disp('Exp(A)');
disp(expa);

```
```f01ec example results

Exp(A)
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

```