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_fun_std (f01fk)

## Purpose

nag_matop_complex_gen_matrix_fun_std (f01fk) computes the matrix exponential, sine, cosine, sinh or cosh, of a complex n$n$ by n$n$ matrix A$A$ using the Schur–Parlett algorithm.

## Syntax

[a, ifail] = f01fk(fun, a, 'n', n)
[a, ifail] = nag_matop_complex_gen_matrix_fun_std(fun, a, 'n', n)

## Description

f(A)$f\left(A\right)$, where f$f$ is either the exponential, sine, cosine, sinh or cosh, is computed using the Schur–Parlett algorithm described in Higham (2008) and Davies and Higham (2003).

## References

Davies P I and Higham N J (2003) A Schur–Parlett algorithm for computing matrix functions. SIAM J. Matrix Anal. Appl. 25(2) 464–485
Higham N J (2008) Functions of Matrices: Theory and Computation SIAM, Philadelphia, PA, USA

## Parameters

### Compulsory Input Parameters

1:     fun – string
Indicates which matrix function will be computed.
fun = 'exp'${\mathbf{fun}}=\text{'exp'}$
The matrix exponential, eA${e}^{A}$, will be computed.
fun = 'sin'${\mathbf{fun}}=\text{'sin'}$
The matrix sine, sin(A)$\mathrm{sin}\left(A\right)$, will be computed.
fun = 'cos'${\mathbf{fun}}=\text{'cos'}$
The matrix cosine, cos(A)$\mathrm{cos}\left(A\right)$, will be computed.
fun = 'sinh'${\mathbf{fun}}=\text{'sinh'}$
The hyperbolic matrix sine, sinh(A)$\mathrm{sinh}\left(A\right)$, will be computed.
fun = 'cosh'${\mathbf{fun}}=\text{'cosh'}$
The hyperbolic matrix cosine, cosh(A)$\mathrm{cosh}\left(A\right)$, will be computed.
Constraint: fun = 'exp'${\mathbf{fun}}=\text{'exp'}$, 'sin'$\text{'sin'}$, 'cos'$\text{'cos'}$, 'sinh'$\text{'sinh'}$ or 'cosh'$\text{'cosh'}$.
2:     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)$.
The n$n$ by n$n$ matrix, f(A)$f\left(A\right)$.
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$
A Taylor series failed to converge.
ifail = 2${\mathbf{ifail}}=2$
ifail = 3${\mathbf{ifail}}=3$
There was an error whilst reordering the Schur form of A$A$.
Note:  this failure should not occur and suggests that the function has been called incorrectly.
ifail = 4${\mathbf{ifail}}=4$
The function was unable to compute the Schur decomposition of A$A$.
Note:  this failure should not occur and suggests that the function has been called incorrectly.
ifail = 5${\mathbf{ifail}}=5$
ifail = 6${\mathbf{ifail}}=6$
The linear equations to be solved are nearly singular and the Padé approximant used to compute the exponential may have no correct figures.
Note:  this failure should not occur and suggests that the function has been called incorrectly.
ifail = 1${\mathbf{ifail}}=-1$
Input argument number _$_$ is invalid.
ifail = 2${\mathbf{ifail}}=-2$
Input argument number _$_$ is invalid.
ifail = 4${\mathbf{ifail}}=-4$
On entry, parameter lda is invalid.
Constraint: ldan$\mathit{lda}\ge {\mathbf{n}}$.
ifail = 999${\mathbf{ifail}}=-999$
Allocation of memory failed.

## Accuracy

For a normal matrix A$A$ (for which AHA = AAH${A}^{\mathrm{H}}A=A{A}^{\mathrm{H}}$), the Schur decomposition is diagonal and the algorithm reduces to evaluating f$f$ at the eigenvalues of A$A$ and then constructing f(A)$f\left(A\right)$ using the Schur vectors. This should give a very accurate result. In general, however, no error bounds are available for the algorithm.
For further discussion of the Schur–Parlett algorithm see Section 9.4 of Higham (2008).

The integer allocatable memory required is n$n$, and the complex allocatable memory required is approximately 9n2$9{n}^{2}$.
The cost of the Schur–Parlett algorithm depends on the spectrum of A$A$, but is roughly between 28n3$28{n}^{3}$ and n4 / 3${n}^{4}/3$ floating point operations; see Algorithm 9.6 of Higham (2008).
If the matrix exponential is required then it is recommended that nag_matop_complex_gen_matrix_exp (f01fc) be used. nag_matop_complex_gen_matrix_exp (f01fc) uses an algorithm which is, in general, more accurate than the Schur–Parlett algorithm used by nag_matop_complex_gen_matrix_fun_std (f01fk).
If estimates of the condition number of the matrix function are required then nag_matop_complex_gen_matrix_cond_std (f01ka) should be used.
nag_matop_real_gen_matrix_fun_std (f01ek) can be used to find the matrix exponential, sin, cos, sinh or cosh of a real matrix A$A$.

## Example

```function nag_matop_complex_gen_matrix_fun_std_example
a =  [1.0+1.0i, 0.0+0.0i, 1.0+3.0i, 0.0+0.0i;
0.0+0.0i, 2.0+0.0i, 0.0+0.0i, 1.0+2.0i;
3.0+1.0i, 0.0+4.0i, 1.0+1.0i, 0.0+0.0i;
1.0+1.0i, 0.0+2.0i, 0.0+0.0i, 1.0+0.0i];
% Compute sinh(a)
[a, ifail] = nag_matop_complex_gen_matrix_fun_std('sinh', a)
```
```

a =

-4.3015 - 1.8117i  -1.4918 - 8.7793i  -4.4242 - 1.3925i   1.4438 - 6.5287i
-1.7976 - 0.2935i   1.4211 - 0.1993i  -1.2712 - 1.9931i   1.2118 + 2.8506i
-4.4968 - 0.1964i  -5.7934 - 4.7166i  -4.3015 - 1.8117i  -3.0082 - 4.1821i
-2.1506 - 0.3911i  -0.6103 - 1.4408i  -1.5163 - 1.9317i   0.0385 - 0.2847i

ifail =

0

```
```function f01fk_example
a =  [1.0+1.0i, 0.0+0.0i, 1.0+3.0i, 0.0+0.0i;
0.0+0.0i, 2.0+0.0i, 0.0+0.0i, 1.0+2.0i;
3.0+1.0i, 0.0+4.0i, 1.0+1.0i, 0.0+0.0i;
1.0+1.0i, 0.0+2.0i, 0.0+0.0i, 1.0+0.0i];
% Compute sinh(a)
[a, ifail] = f01fk('sinh', a)
```
```

a =

-4.3015 - 1.8117i  -1.4918 - 8.7793i  -4.4242 - 1.3925i   1.4438 - 6.5287i
-1.7976 - 0.2935i   1.4211 - 0.1993i  -1.2712 - 1.9931i   1.2118 + 2.8506i
-4.4968 - 0.1964i  -5.7934 - 4.7166i  -4.3015 - 1.8117i  -3.0082 - 4.1821i
-2.1506 - 0.3911i  -0.6103 - 1.4408i  -1.5163 - 1.9317i   0.0385 - 0.2847i

ifail =

0

```

Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013