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_frcht_exp (f01jh)

## Purpose

nag_matop_real_gen_matrix_frcht_exp (f01jh) computes the Fréchet derivative $L\left(A,E\right)$ of the matrix exponential of a real $n$ by $n$ matrix $A$ applied to the real $n$ by $n$ matrix $E$. The matrix exponential ${e}^{A}$ is also returned.

## Syntax

[a, e, ifail] = f01jh(a, e, 'n', n)
[a, e, ifail] = nag_matop_real_gen_matrix_frcht_exp(a, e, 'n', n)

## Description

The Fréchet derivative of the matrix exponential of $A$ is the unique linear mapping $E⟼L\left(A,E\right)$ such that for any matrix $E$
 $eA+E - e A - LA,E = oE .$
The derivative describes the first-order effect of perturbations in $A$ on the exponential ${e}^{A}$.
nag_matop_real_gen_matrix_frcht_exp (f01jh) uses the algorithms of Al–Mohy and Higham (2009a) and Al–Mohy and Higham (2009b) to compute ${e}^{A}$ and $L\left(A,E\right)$. The matrix exponential ${e}^{A}$ is computed using a Padé approximant and the scaling and squaring method. The Padé approximant is then differentiated in order to obtain the Fréchet derivative $L\left(A,E\right)$.

## References

Al–Mohy A H and Higham N J (2009a) A new scaling and squaring algorithm for the matrix exponential SIAM J. Matrix Anal. 31(3) 970–989
Al–Mohy A H and Higham N J (2009b) Computing the Fréchet derivative of the matrix exponential, with an application to condition number estimation SIAM J. Matrix Anal. Appl. 30(4) 1639–1657
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$.
2:     $\mathrm{e}\left(\mathit{lde},:\right)$ – double array
The first dimension of the array e must be at least ${\mathbf{n}}$.
The second dimension of the array e must be at least ${\mathbf{n}}$.
The $n$ by $n$ matrix $E$

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the arrays a, e. (An error is raised if these dimensions are not equal.)
$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{e}\left(\mathit{lde},:\right)$ – double array
The first dimension of the array e will be ${\mathbf{n}}$.
The second dimension of the array e will be ${\mathbf{n}}$.
The Fréchet derivative $L\left(A,E\right)$
3:     $\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:
${\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$
${e}^{A}$ has been computed using an IEEE double precision Padé approximant, although the arithmetic precision is higher than IEEE double precision.
${\mathbf{ifail}}=3$
${\mathbf{ifail}}=-1$
Constraint: ${\mathbf{n}}\ge 0$.
${\mathbf{ifail}}=-3$
Constraint: $\mathit{lda}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=-5$
Constraint: $\mathit{lde}\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 Section 10.3 of Higham (2008), Al–Mohy and Higham (2009a) and Al–Mohy and Higham (2009b) for details and further discussion.

The cost of the algorithm is $O\left({n}^{3}\right)$ and the real allocatable memory required is approximately $9{n}^{2}$; see Al–Mohy and Higham (2009a) and Al–Mohy and Higham (2009b).
If the matrix exponential alone is required, without the Fréchet derivative, then nag_matop_real_gen_matrix_exp (f01ec) should be used.
If the condition number of the matrix exponential is required then nag_matop_real_gen_matrix_cond_exp (f01jg) should be used.
As well as the excellent book Higham (2008), the classic reference for the computation of the matrix exponential is Moler and Van Loan (2003).

## Example

This example finds the matrix exponential ${e}^{A}$ and the Fréchet derivative $L\left(A,E\right)$, where
 $A = 1 2 2 2 3 1 1 2 3 2 1 2 3 3 3 1 and E = 1 0 1 2 0 0 0 1 4 2 1 2 0 3 2 1 .$
```function f01jh_example

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

% Exponential of matrix A and Frechet derivative of exp(A)E.

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

e = [ 1 0 1 2;
0 0 0 1;
4 2 1 2;
0 3 2 1];

[expa, lae, ifail] = f01jh(a,e);

[ifail] = x04ca('General', ' ', expa, 'exp(A):');
disp(' ');
[ifail] = x04ca('General', ' ', lae, 'L_exp(A,E):');

```
```f01jh example results

exp(A):
1          2          3          4
1    740.7038   610.8500   542.2743   549.1753
2    731.2510   603.5524   535.0884   542.2743
3    823.7630   679.4257   603.5524   610.8500
4    998.4355   823.7630   731.2510   740.7038

L_exp(A,E):
1          2          3          4
1   3571.5724  2989.2581  2652.3449  2818.7416
2   3202.0590  2684.2631  2381.4500  2542.7976
3   4341.3950  3628.9329  3219.3516  3408.1831
4   4821.2945  4035.9700  3580.0124  3804.4690
```