﻿ f01ef Method
f01ef computes the matrix function, $f\left(A\right)$, of a real symmetric $n$ by $n$ matrix $A$. $f\left(A\right)$ must also be a real symmetric matrix.

# Syntax

C#
```public static void f01ef(
string uplo,
int n,
double[,] a,
F01..::..F01EF_F f,
out int iflag,
out int ifail
)```
Visual Basic
```Public Shared Sub f01ef ( _
uplo As String, _
n As Integer, _
a As Double(,), _
f As F01..::..F01EF_F, _
<OutAttribute> ByRef iflag As Integer, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void f01ef(
String^ uplo,
int n,
array<double,2>^ a,
F01..::..F01EF_F^ f,
[OutAttribute] int% iflag,
[OutAttribute] int% ifail
)```
F#
```static member f01ef :
uplo : string *
n : int *
a : float[,] *
f : F01..::..F01EF_F *
iflag : int byref *
ifail : int byref -> unit
```

#### Parameters

uplo
Type: System..::..String
On entry: if ${\mathbf{uplo}}=\text{"U"}$, the upper triangle of the matrix $A$ is stored.
If ${\mathbf{uplo}}=\text{"L"}$, the lower triangle of the matrix $A$ is stored.
Constraint: ${\mathbf{uplo}}=\text{"U"}$ or $\text{"L"}$.
n
Type: System..::..Int32
On entry: $n$, the order of the matrix $A$.
Constraint: ${\mathbf{n}}\ge 0$.
a
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, dim2]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}\right)$
Note: the second dimension of the array a must be at least ${\mathbf{n}}$.
On entry: the $n$ by $n$ symmetric matrix $A$.
• If ${\mathbf{uplo}}=\text{"U"}$, the upper triangular part of $A$ must be stored and the elements of the array below the diagonal are not referenced.
• If ${\mathbf{uplo}}=\text{"L"}$, the lower triangular part of $A$ must be stored and the elements of the array above the diagonal are not referenced.
On exit: if ${\mathbf{ifail}}={0}$, the upper or lower triangular part of the $n$ by $n$ matrix function, $f\left(A\right)$.
f
Type: NagLibrary..::..F01..::..F01EF_F
The method f evaluates $f\left({z}_{i}\right)$ at a number of points ${z}_{i}$.

A delegate of type F01EF_F.

iflag
Type: System..::..Int32%
On exit: ${\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}}={-}{6}$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

$f\left(A\right)$ is computed using a spectral factorization of $A$
 $A=QDQT,$
where $D$ is the diagonal matrix whose diagonal elements, ${d}_{i}$, are the eigenvalues of $A$, and $Q$ is an orthogonal matrix whose columns are the eigenvectors of $A$. $f\left(A\right)$ is then given by
 $fA=QfDQT,$
where $f\left(D\right)$ is the diagonal matrix whose $i$th diagonal element is $f\left({d}_{i}\right)$. See for example Section 4.5 of Higham (2008). $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

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDA) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
If ${\mathbf{ifail}}={-}{i}$, the $i$th argument had an illegal value.
${\mathbf{ifail}}=-6$
iflag has been set nonzero by the user.
${\mathbf{ifail}}=-999$
Internal memory allocation failed.
The integer allocatable memory required is n, and the real allocatable memory required is approximately $\left({\mathbf{n}}+\mathit{nb}+4\right)×{\mathbf{n}}$, where nb is the block size required by f08fa.
${\mathbf{ifail}}=i \text{and} {\mathbf{ifail}}>0$
The algorithm to compute the spectral factorization failed to converge; $i$ off-diagonal elements of an intermediate tridiagonal form did not converge to zero (see f08fa).
Note:  this failure is unlikely to occur.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

Provided that $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.

# Parallelism and Performance

None.

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

# Example

This example finds the matrix cosine, $\mathrm{cos}\left(A\right)$, of the symmetric matrix
 $A=1234212332124321.$

Example program (C#): f01efe.cs

Example program data: f01efe.d

Example program results: f01efe.r