NAG C Library Function Document

nag_matop_real_symm_matrix_fun (f01efc)


nag_matop_real_symm_matrix_fun (f01efc) computes the matrix function, fA, of a real symmetric n by n matrix A. fA must also be a real symmetric matrix.


#include <nag.h>
#include <nagf01.h>
void  nag_matop_real_symm_matrix_fun (Nag_OrderType order, Nag_UploType uplo, Integer n, double a[], Integer pda,
void (*f)(Integer *flag, Integer n, const double x[], double fx[], Nag_Comm *comm),
Nag_Comm *comm, Integer *flag, NagError *fail)


fA is computed using a spectral factorization of A 
A = Q D QT ,  
where D is the diagonal matrix whose diagonal elements, di, are the eigenvalues of A, and Q is an orthogonal matrix whose columns are the eigenvectors of A. fA is then given by
fA = Q fD QT ,  
where fD is the diagonal matrix whose ith diagonal element is fdi. See for example Section 4.5 of Higham (2008). fdi is assumed to be real.


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


1:     order Nag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by order=Nag_RowMajor. See Section in How to Use the NAG Library and its Documentation for a more detailed explanation of the use of this argument.
Constraint: order=Nag_RowMajor or Nag_ColMajor.
2:     uplo Nag_UploTypeInput
On entry: if uplo=Nag_Upper, the upper triangle of the matrix A is stored.
If uplo=Nag_Lower, the lower triangle of the matrix A is stored.
Constraint: uplo=Nag_Upper or Nag_Lower.
3:     n IntegerInput
On entry: n, the order of the matrix A.
Constraint: n0.
4:     a[dim] doubleInput/Output
Note: the dimension, dim, of the array a must be at least pda×n.
On entry: the n by n symmetric matrix A.
If order=Nag_ColMajor, Aij is stored in a[j-1×pda+i-1].
If order=Nag_RowMajor, Aij is stored in a[i-1×pda+j-1].
If uplo=Nag_Upper, the upper triangular part of A must be stored and the elements of the array below the diagonal are not referenced.
If uplo=Nag_Lower, the lower triangular part of A must be stored and the elements of the array above the diagonal are not referenced.
On exit: if fail.code= NE_NOERROR, the upper or lower triangular part of the n by n matrix function, fA.
5:     pda IntegerInput
On entry: the stride separating row or column elements (depending on the value of order) of the matrix A in the array a.
Constraint: pdamax1,n.
6:     f function, supplied by the userExternal Function
The function f evaluates fzi at a number of points zi.
The specification of f is:
void  f (Integer *flag, Integer n, const double x[], double fx[], Nag_Comm *comm)
1:     flag Integer *Input/Output
On entry: flag will be zero.
On exit: flag 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 fx; for instance fx may not be defined, or may be complex. If flag is returned as nonzero then nag_matop_real_symm_matrix_fun (f01efc) will terminate the computation, with fail.code= NE_USER_STOP.
2:     n IntegerInput
On entry: n, the number of function values required.
3:     x[n] const doubleInput
On entry: the n points x1,x2,,xn at which the function f is to be evaluated.
4:     fx[n] doubleOutput
On exit: the n function values. fx[i-1] should return the value fxi, for i=1,2,,n.
5:     comm Nag_Comm *
Pointer to structure of type Nag_Comm; the following members are relevant to f.
userdouble *
iuserInteger *
The type Pointer will be void *. Before calling nag_matop_real_symm_matrix_fun (f01efc) you may allocate memory and initialize these pointers with various quantities for use by f when called from nag_matop_real_symm_matrix_fun (f01efc) (see Section in How to Use the NAG Library and its Documentation).
Note: f should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by nag_matop_real_symm_matrix_fun (f01efc). If your code inadvertently does return any NaNs or infinities, nag_matop_real_symm_matrix_fun (f01efc) is likely to produce unexpected results.
7:     comm Nag_Comm *
The NAG communication argument (see Section in How to Use the NAG Library and its Documentation).
8:     flag Integer *Output
On exit: flag=0, unless you have set flag nonzero inside f, in which case flag will be the value you set and fail will be set to fail.code= NE_USER_STOP.
9:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

Error Indicators and Warnings

If fail.code=i, 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 nag_dsyev (f08fac)).
Dynamic memory allocation failed.
See Section in How to Use the NAG Library and its Documentation for further information.
On entry, argument value had an illegal value.
The computation of the spectral factorization failed to converge.
On entry, n=value.
Constraint: n0.
On entry, pda=value and n=value.
Constraint: pdan.
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
An internal error occurred when computing the spectral factorization. Please contact NAG.
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
flag was set to a nonzero value in f.


Provided that fD 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

nag_matop_real_symm_matrix_fun (f01efc) is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
nag_matop_real_symm_matrix_fun (f01efc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Further Comments

The Integer allocatable memory required is n, and the double allocatable memory required is approximately n+nb+4×n, where nb is the block size required by nag_dsyev (f08fac).
The cost of the algorithm is On3 plus the cost of evaluating fD. If λ^i is the ith computed eigenvalue of A, then the user-supplied function f will be asked to evaluate the function f at fλ^i, i=1,2,,n.
For further information on matrix functions, see Higham (2008).
nag_matop_complex_herm_matrix_fun (f01ffc) can be used to find the matrix function fA for a complex Hermitian matrix A.


This example finds the matrix cosine, cosA, of the symmetric matrix
A= 1 2 3 4 2 1 2 3 3 2 1 2 4 3 2 1 .  

Program Text

Program Text (f01efce.c)

Program Data

Program Data (f01efce.d)

Program Results

Program Results (f01efce.r)