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_cond_usd (f01kc)

## Purpose

nag_matop_complex_gen_matrix_cond_usd (f01kc) computes an estimate of the absolute condition number of a matrix function $f$ of a complex $n$ by $n$ matrix $A$ in the $1$-norm, using analytical derivatives of $f$ you have supplied.

## Syntax

[a, user, iflag, conda, norma, normfa, ifail] = f01kc(a, f, 'n', n, 'user', user)
[a, user, iflag, conda, norma, normfa, ifail] = nag_matop_complex_gen_matrix_cond_usd(a, f, 'n', n, 'user', user)

## Description

The absolute condition number of $f$ at $A$, ${\mathrm{cond}}_{\mathrm{abs}}\left(f,A\right)$ is given by the norm of the Fréchet derivative of $f$, $L\left(A\right)$, which is defined by
 $LX := maxE≠0 LX,E E ,$
where $L\left(X,E\right)$ is the Fréchet derivative in the direction $E$. $L\left(X,E\right)$ is linear in $E$ and can therefore be written as
 $vec LX,E = KX vecE ,$
where the $\mathrm{vec}$ operator stacks the columns of a matrix into one vector, so that $K\left(X\right)$ is ${n}^{2}×{n}^{2}$. nag_matop_complex_gen_matrix_cond_usd (f01kc) computes an estimate $\gamma$ such that $\gamma \le {‖K\left(X\right)‖}_{1}$, where ${‖K\left(X\right)‖}_{1}\in \left[{n}^{-1}{‖L\left(X\right)‖}_{1},n{‖L\left(X\right)‖}_{1}\right]$. The relative condition number can then be computed via
 $cond rel f,A = cond abs f,A A1 fA 1 .$
The algorithm used to find $\gamma$ is detailed in Section 3.4 of Higham (2008).

## References

Higham N J (2008) Functions of Matrices: Theory and Computation SIAM, Philadelphia, PA, USA

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{a}\left(\mathit{lda},:\right)$ – complex 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{f}$ – function handle or string containing name of m-file
Given an integer $m$, the function f evaluates ${f}^{\left(m\right)}\left({z}_{i}\right)$ at a number of points ${z}_{i}$.
[iflag, fz, user] = f(m, iflag, nz, z, user)

Input Parameters

1:     $\mathrm{m}$int64int32nag_int scalar
The order, $m$, of the derivative required.
If ${\mathbf{m}}=0$, $f\left({z}_{i}\right)$ should be returned. For ${\mathbf{m}}>0$, ${f}^{\left(m\right)}\left({z}_{i}\right)$ should be returned.
2:     $\mathrm{iflag}$int64int32nag_int scalar
iflag will be zero.
3:     $\mathrm{nz}$int64int32nag_int scalar
${n}_{z}$, the number of function or derivative values required.
4:     $\mathrm{z}\left({\mathbf{nz}}\right)$ – complex array
The ${n}_{z}$ points ${z}_{1},{z}_{2},\dots ,{z}_{{n}_{z}}$ at which the function $f$ is to be evaluated.
5:     $\mathrm{user}$ – Any MATLAB object
f is called from nag_matop_complex_gen_matrix_cond_usd (f01kc) with the object supplied to nag_matop_complex_gen_matrix_cond_usd (f01kc).

Output Parameters

1:     $\mathrm{iflag}$int64int32nag_int scalar
iflag should either be unchanged from its entry value of zero, or may be set nonzero to indicate that there is a problem in evaluating the function $f\left(z\right)$; for instance $f\left(z\right)$ may not be defined. If iflag is returned as nonzero then nag_matop_complex_gen_matrix_cond_usd (f01kc) will terminate the computation, with ${\mathbf{ifail}}={\mathbf{3}}$.
2:     $\mathrm{fz}\left({\mathbf{nz}}\right)$ – complex array
The ${n}_{z}$ function or derivative values. ${\mathbf{fz}}\left(\mathit{i}\right)$ should return the value ${f}^{\left(m\right)}\left({z}_{\mathit{i}}\right)$, for $\mathit{i}=1,2,\dots ,{n}_{z}$.
3:     $\mathrm{user}$ – Any MATLAB object

### 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$.
2:     $\mathrm{user}$ – Any MATLAB object
user is not used by nag_matop_complex_gen_matrix_cond_usd (f01kc), but is passed to f. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use user.

### Output Parameters

1:     $\mathrm{a}\left(\mathit{lda},:\right)$ – complex 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, $f\left(A\right)$.
2:     $\mathrm{user}$ – Any MATLAB object
3:     $\mathrm{iflag}$int64int32nag_int scalar
${\mathbf{iflag}}=0$, unless iflag has been set nonzero inside f, in which case iflag will be the value set and ifail will be set to ${\mathbf{ifail}}={\mathbf{3}}$.
4:     $\mathrm{conda}$ – double scalar
An estimate of the absolute condition number of $f$ at $A$.
5:     $\mathrm{norma}$ – double scalar
The $1$-norm of $A$.
6:     $\mathrm{normfa}$ – double scalar
The $1$-norm of $f\left(A\right)$.
7:     $\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$
An internal error occurred when estimating the norm of the Fréchet derivative of $f$ at $A$. Please contact NAG.
${\mathbf{ifail}}=2$
An internal error occurred when evaluating the matrix function $f\left(A\right)$. You can investigate further by calling nag_matop_complex_gen_matrix_fun_usd (f01fm) with the matrix $A$ and the function $f$.
${\mathbf{ifail}}=3$
iflag has been set nonzero by the user-supplied function.
${\mathbf{ifail}}=-1$
On entry, ${\mathbf{n}}<0$.
${\mathbf{ifail}}=-3$
On entry, argument lda is invalid.
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

nag_matop_complex_gen_matrix_cond_usd (f01kc) uses the norm estimation function nag_linsys_complex_gen_norm_rcomm (f04zd) to estimate a quantity $\gamma$, where $\gamma \le {‖K\left(X\right)‖}_{1}$ and ${‖K\left(X\right)‖}_{1}\in \left[{n}^{-1}{‖L\left(X\right)‖}_{1},n{‖L\left(X\right)‖}_{1}\right]$. For further details on the accuracy of norm estimation, see the documentation for nag_linsys_complex_gen_norm_rcomm (f04zd).

Approximately $6{n}^{2}$ of complex allocatable memory is required by the routine, in addition to the memory used by the underlying matrix function routine nag_matop_complex_gen_matrix_fun_usd (f01fm).
nag_matop_complex_gen_matrix_cond_usd (f01kc) returns the matrix function $f\left(A\right)$. This is computed using nag_matop_complex_gen_matrix_fun_usd (f01fm). If only $f\left(A\right)$ is required, without an estimate of the condition number, then it is far more efficient to use nag_matop_complex_gen_matrix_fun_usd (f01fm) directly.
The real analogue of this function is nag_matop_real_gen_matrix_cond_usd (f01jc).

## Example

This example estimates the absolute and relative condition numbers of the matrix function ${e}^{3A}$ where
 $A= 1.0+1.0i 0.0+1.0i 1.0+0.0i 2.0+0.0i 0.0+0.0i 2.0+0.0i 0.0+2.0i 1.0+0.0i 0.0+1.0i 0.0+1.0i 0.0+0.0i 2.0+0.0i 1.0+0.0i 0.0+1.0i 1.0+0.0i 0.0+1.0i .$
```function f01kc_example

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

a = [1+1i, 0+1i, 1+0i, 2+0i;
0+0i, 2+0i, 0+2i, 1+0i;
0+1i, 0+1i, 0+0i, 2+0i;
1+0i, 0+1i, 1+0i, 0+1i];

% Find absolute condition number estimate
[a, user, iflag, conda, norma, normfa, ifail] = ...
f01kc(a, @fexp3);

fprintf('\nf(A) = exp(3A)\n');
fprintf('Estimated absolute condition number is: %7.2f\n', conda);

%  Find relative condition number estimate
eps = x02aj;
if normfa > eps
cond_rel = conda*norma/normfa;
fprintf('Estimated relative condition number is: %7.2f\n', cond_rel);
else
fprintf('The estimated norm of f(A) is effectively zero;\n');
fprintf('the relative condition number is therefore undefined.\n');
end

function [iflag, fz, user] = fexp3(m, iflag, nz, z, user)
fz = 3^double(m)*exp(3*z);
```
```f01kc example results

f(A) = exp(3A)
Estimated absolute condition number is: 9474.43
Estimated relative condition number is:   13.74
```