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_log (f01ej)

## Purpose

nag_matop_real_gen_matrix_log (f01ej) computes the principal matrix logarithm, log(A)$\mathrm{log}\left(A\right)$, of a real n$n$ by n$n$ matrix A$A$, with no eigenvalues on the closed negative real line.

## Syntax

[a, imnorm, ifail] = f01ej(a, 'n', n)
[a, imnorm, ifail] = nag_matop_real_gen_matrix_log(a, 'n', n)

## Description

Any nonsingular matrix A$A$ has infinitely many logarithms. For a matrix with no eigenvalues on the closed negative real line, the principal logarithm is the unique logarithm whose spectrum lies in the strip {z : π < Im(z) < π}$\left\{z:-\pi <\mathrm{Im}\left(z\right)<\pi \right\}$.
log(A)$\mathrm{log}\left(A\right)$ is computed using the Schur–Parlett algorithm for the matrix logarithm 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:     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 second 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$ principal matrix logarithm, log(A)$\mathrm{log}\left(A\right)$.
2:     imnorm – double scalar
imnorm = 0${\mathbf{imnorm}}=0$. This parameter is no longer required by nag_matop_real_gen_matrix_log (f01ej).
3:     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$
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 = 2${\mathbf{ifail}}=2$
A$A$ is singular so the logarithm cannot be computed.
ifail = 3${\mathbf{ifail}}=3$
The routine 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 = 4${\mathbf{ifail}}=4$
A$A$ was found to have eigenvalues on the closed, negative real line. The principal logarithm is not defined in this case, so a non-principal logarithm was returned.
ifail = 5${\mathbf{ifail}}=5$
ifail = 6${\mathbf{ifail}}=6$
The linear equations to be solved are nearly singular and the Padé approximant may have no correct figures.
Note:  this failure should not occur and suggests that the function has been called incorrectly.
There was a problem obtaining the weights and nodes from the Gaussian quadrature function nag_quad_1d_gauss_wgen (d01bc).
ifail = 1${\mathbf{ifail}}=-1$
Input parameter number _$_$ is invalid.
ifail = 3${\mathbf{ifail}}=-3$
On entry, parameter lda is invalid.
Constraint: ldan$\mathit{lda}\ge {\mathbf{n}}$.
ifail = 999${\mathbf{ifail}}=-999$
Allocation of memory failed. If A$A$ has real eigenvalues then up to 4 × N2$4×{N}^{2}$ of double allocatable memory may be required. Otherwise up to 4 × N2$4×{N}^{2}$ of complex allocatable memory may be required.

## Accuracy

For a normal matrix A$A$ (for which ATA = AAT${A}^{\mathrm{T}}A=A{A}^{\mathrm{T}}$), the Schur decomposition is diagonal and the algorithm reduces to evaluating the logarithm of the eigenvalues of A$A$ and then constructing log(A)$\mathrm{log}\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. See Section 9.4 of Higham (2008) for details and further discussion.
For discussion of the condition of the matrix logarithm see Section 11.2 of Higham (2008). In particular, the condition number of the matrix logarithm at A$A$, κlog (A) ${\kappa }_{\mathrm{log}}\left(A\right)$, which is a measure of the sensitivity of the computed logarithm to perturbations in the matrix A$A$, satisfies
 κlog (A) ≥ (κ(A))/(‖log(A)‖) , $κ log (A) ≥ κ(A) ‖log(A)‖ ,$
where κ(A)$\kappa \left(A\right)$ is the condition number of A$A$. Further, the sensitivity of the computation of log(A)$\mathrm{log}\left(A\right)$ is worst when A$A$ has an eigenvalue of very small modulus, or has a complex conjugate pair of eigenvalues lying close to the negative real axis.

If A$A$ has real eigenvalues then up to 4n2$4{n}^{2}$ of double allocatable memory may be required. Otherwise up to 4n2$4{n}^{2}$ of complex allocatable memory may be required.
The cost of the algorithm is O(n3)$O\left({n}^{3}\right)$ floating point operations. The exact cost depends on the eigenvalue distribution of A$A$; see Algorithm 11.11 of Higham (2008).
If estimates of the condition number of the matrix logarithm are required then nag_matop_real_gen_matrix_cond_std (f01ja) should be used.
nag_matop_complex_gen_matrix_log (f01fj) can be used to find the principal logarithm of a complex matrix. It can also be used to return a complex, non-principal logarithm if a real matrix has no principal logarithm due to the presence of negative eigenvalues.

## Example

```function nag_matop_real_gen_matrix_log_example
a =  [3, -3,  1,  1;
2,  1, -2,  1;
1,  1,  3, -1;
2,  0,  2,  0];
% Compute log(a)
[a, imnorm, ifail] = nag_matop_real_gen_matrix_log(a)
```
```

a =

1.1957   -1.2076   -0.5802    1.0872
0.8464    1.0133   -0.5985   -0.1641
0.4389    0.6701    1.8449   -1.2111
1.2792    0.6177    2.1448   -1.9743

imnorm =

5.4895e-16

ifail =

0

```
```function f01ej_example
a =  [3, -3,  1,  1;
2,  1, -2,  1;
1,  1,  3, -1;
2,  0,  2,  0];
% Compute log(a)
[a, imnorm, ifail] = f01ej(a)
```
```

a =

1.1957   -1.2076   -0.5802    1.0872
0.8464    1.0133   -0.5985   -0.1641
0.4389    0.6701    1.8449   -1.2111
1.2792    0.6177    2.1448   -1.9743

imnorm =

5.4895e-16

ifail =

0

```