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_herm_matrix_fun (f01ff)

## Purpose

nag_matop_complex_herm_matrix_fun (f01ff) computes the matrix function, f(A)$f\left(A\right)$, of a complex Hermitian n$n$ by n$n$ matrix A$A$. f(A)$f\left(A\right)$ must also be a complex Hermitian matrix.

## Syntax

[a, user, iflag, ifail] = f01ff(uplo, a, f, 'n', n, 'user', user)
[a, user, iflag, ifail] = nag_matop_complex_herm_matrix_fun(uplo, a, f, 'n', n, 'user', user)

## Description

f(A)$f\left(A\right)$ is computed using a spectral factorization of A$A$
 A = Q D QH , $A = Q D QH ,$
where D$D$ is the real diagonal matrix whose diagonal elements, di${d}_{i}$, are the eigenvalues of A$A$, Q$Q$ is a unitary matrix whose columns are the eigenvectors of A$A$ and QH${Q}^{\mathrm{H}}$ is the conjugate transpose of Q$Q$. f(A)$f\left(A\right)$ is then given by
 f(A) = Q f(D) QH , $f(A) = Q f(D) QH ,$
where f(D)$f\left(D\right)$ is the diagonal matrix whose i$i$th diagonal element is f(di)$f\left({d}_{i}\right)$. See for example Section 4.5 of Higham (2008). f(di)$f\left({d}_{i}\right)$ is assumed to be real.

## References

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

## Parameters

### Compulsory Input Parameters

1:     uplo – string (length ≥ 1)
If uplo = 'U'${\mathbf{uplo}}=\text{'U'}$, the upper triangle of the matrix A$A$ is stored.
If uplo = 'L'${\mathbf{uplo}}=\text{'L'}$, the lower triangle of the matrix A$A$ is stored.
Constraint: uplo = 'U'${\mathbf{uplo}}=\text{'U'}$ or 'L'$\text{'L'}$.
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$ Hermitian matrix A$A$.
• If uplo = 'U'${\mathbf{uplo}}=\text{'U'}$, the upper triangular part of a$a$ must be stored and the elements of the array below the diagonal are not referenced.
• If uplo = 'L'${\mathbf{uplo}}=\text{'L'}$, the lower triangular part of a$a$ must be stored and the elements of the array above the diagonal are not referenced.
3:     f – function handle or string containing name of m-file
The function f evaluates f(zi)$f\left({z}_{i}\right)$ at a number of points zi${z}_{i}$.
[iflag, fx, user] = f(iflag, n, x, user)

Input Parameters

1:     iflag – int64int32nag_int scalar
iflag will be zero.
2:     n – int64int32nag_int scalar
n$n$, the number of function values required.
3:     x(n) – double array
The n$n$ points x1,x2,,xn${x}_{1},{x}_{2},\dots ,{x}_{n}$ at which the function f$f$ is to be evaluated.
4:     user – Any MATLAB object
f is called from nag_matop_complex_herm_matrix_fun (f01ff) with the object supplied to nag_matop_complex_herm_matrix_fun (f01ff).

Output Parameters

1:     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(x)$f\left(x\right)$; for instance f(x)$f\left(x\right)$ may not be defined, or may be complex. If iflag is returned as nonzero then nag_matop_complex_herm_matrix_fun (f01ff) will terminate the computation, with ${\mathbf{ifail}}=-{\mathbf{6}}$.
2:     fx(n) – double array
The n$n$ function values. fx(i)${\mathbf{fx}}\left(\mathit{i}\right)$ should return the value f(xi)$f\left({x}_{\mathit{i}}\right)$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
3:     user – Any MATLAB object

### 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$.
2:     user – Any MATLAB object
user is not used by nag_matop_complex_herm_matrix_fun (f01ff), 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.

lda iuser ruser

### 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)$.
If ${\mathbf{ifail}}={\mathbf{0}}$, the upper or lower triangular part of the n$n$ by n$n$ matrix function, f(A)$f\left(A\right)$.
2:     user – Any MATLAB object
3:     iflag – int64int32nag_int scalar
iflag = 0${\mathbf{iflag}}=0$, unless you have set iflag nonzero inside f, in which case iflag will be the value you set and ifail will be set to ${\mathbf{ifail}}=-{\mathbf{6}}$.
4:     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 > 0${\mathbf{ifail}}>0$
The computation of the spectral factorization failed to converge.
ifail = 1${\mathbf{ifail}}=-1$
Constraint: uplo = 'L'${\mathbf{uplo}}=\text{'L'}$ or 'U'$\text{'U'}$.
ifail = 2${\mathbf{ifail}}=-2$
Constraint: n0${\mathbf{n}}\ge 0$.
ifail = 3${\mathbf{ifail}}=-3$
ifail = 4${\mathbf{ifail}}=-4$
Constraint: ldan$\mathit{lda}\ge {\mathbf{n}}$.
ifail = 6${\mathbf{ifail}}=-6$
iflag was set to a nonzero value in f.
ifail = 999${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Provided that f(D)$f\left(D\right)$ can be computed accurately then the computed matrix function will be close to the exact matrix function. See Section 10.2 of Higham (2008) for details and further discussion.

The cost of the algorithm is O(n3)$O\left({n}^{3}\right)$ plus the cost of evaluating f(D)$f\left(D\right)$. If λ̂i${\stackrel{^}{\lambda }}_{\mathit{i}}$ is the i$\mathit{i}$th computed eigenvalue of A$A$, then the user-supplied function f will be asked to evaluate the function f$f$ at f(λ̂i)$f\left({\stackrel{^}{\lambda }}_{\mathit{i}}\right)$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
For further information on matrix functions, see Higham (2008).
nag_matop_real_symm_matrix_fun (f01ef) can be used to find the matrix function f(A)$f\left(A\right)$ for a real symmetric matrix A$A$.

## Example

```function nag_matop_complex_herm_matrix_fun_example
uplo = 'u';
a = [1,  2 + 1i,  3 + 2i,  4 + 3i;
0,              1 + 0i,  2 + 1i,  3 + 2i;
0,             0,              1 + 0i,  2 + 1i;
0,             0,             0,              1 + 0i];
% Compute f(a)
[aOut, user, iflag, ifail] = nag_matop_complex_herm_matrix_fun(uplo, a, @f);
% Display results
[ifail] = nag_file_print_matrix_complex_gen(uplo, 'n', aOut, 'Hermitian f(a)')

function [iflag, fx, user] = f(iflag, n, x, user)
fx = cos(x);
```
```
Hermitian f(a)
1       2       3       4
1   0.0904 -0.3377 -0.1009 -0.1092
0.0000 -0.0273 -0.0594 -0.1586

2           0.4265 -0.3139 -0.1009
0.0000 -0.0273 -0.0594

3                   0.4265 -0.3377
0.0000 -0.0273

4                           0.0904
0.0000

ifail =

0

```
```function f01ff_example
uplo = 'u';
a = [1,  2 + 1i,  3 + 2i,  4 + 3i;
0,              1 + 0i,  2 + 1i,  3 + 2i;
0,             0,              1 + 0i,  2 + 1i;
0,             0,             0,              1 + 0i];
% Compute f(a)
[aOut, user, iflag, ifail] = f01ff(uplo, a, @f);
% Display results
[ifail] = x04da(uplo, 'n', aOut, 'Hermitian f(a)')

function [iflag, fx, user] = f(iflag, n, x, user)
fx = cos(x);
```
```
Hermitian f(a)
1       2       3       4
1   0.0904 -0.3377 -0.1009 -0.1092
0.0000 -0.0273 -0.0594 -0.1586

2           0.4265 -0.3139 -0.1009
0.0000 -0.0273 -0.0594

3                   0.4265 -0.3377
0.0000 -0.0273

4                           0.0904
0.0000

ifail =

0

```