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 Chapter IntroductionF01 — Matrix Operations, Including Inversion

## Scope of the Chapter

This chapter provides facilities for four types of problem:
 (i) Matrix Inversion (ii) Matrix Factorizations (iii) Matrix Arithmetic and Manipulation (iv) Matrix Functions
These problems are discussed separately in Section [Matrix Inversion], Section [Matrix Factorizations], Section [Matrix Arithmetic and Manipulation] and Section [Matrix Functions].

## Background to the Problems

### Matrix Inversion

(i) Nonsingular square matrices of order n$n$.
If A$A$, a square matrix of order n$n$, is nonsingular (has rank n$n$), then its inverse X$X$ exists and satisfies the equations AX = XA = I$AX=XA=I$ (the identity or unit matrix).
It is worth noting that if AXI = R$AX-I=R$, so that R$R$ is the ‘residual’ matrix, then a bound on the relative error is given by R$‖R‖$, i.e.,
 (‖X − A − 1‖)/(‖A − 1‖) ≤ ‖R‖. $‖X-A-1‖ ‖A-1‖ ≤‖R‖.$
(ii) General real rectangular matrices.
A real matrix A$A$ has no inverse if it is square (n$n$ by n$n$) and singular (has rank < n$\text{}), or if it is of shape (m$m$ by n$n$) with mn$m\ne n$, but there is a Generalized or Pseudo-inverse A+${A}^{+}$ which satisfies the equations
 AA+A = A,  A+AA+ = A+,  (AA+)T = AA+,  (A+A)T = A+A $AA+A=A, A+AA+=A+, (AA+)T=AA+, (A+A)T=A+A$
(which of course are also satisfied by the inverse X$X$ of A$A$ if A$A$ is square and nonsingular).
(a) if mn$m\ge n$ and rank(A) = n$\mathrm{rank}\left(A\right)=n$ then A$A$ can be factorized using a QR$\mathbit{Q}\mathbit{R}$ factorization, given by
A = Q
 ( R ) 0
,
$A=Q R 0 ,$
where Q$Q$ is an m$m$ by m$m$ orthogonal matrix and R$R$ is an n$n$ by n$n$, nonsingular, upper triangular matrix. The pseudo-inverse of A$A$ is then given by
 A+ = R − 1Q̃T, $A+=R-1Q~T,$
where $\stackrel{~}{Q}$ consists of the first n$n$ columns of Q$Q$.
(b) if mn$m\le n$ and rank(A) = m$\mathrm{rank}\left(A\right)=m$ then A$A$ can be factorized using an RQ factorization, given by
 A = (R 0)QT $A=(R 0)QT$
where Q$Q$ is an n$n$ by n$n$ orthogonal matrix and R$R$ is an m$m$ by m$m$, nonsingular, upper triangular matrix. The pseudo-inverse of A$A$ is then given by
 A+ = Q̃R − 1 , $A+ = Q~R-1 ,$
where $\stackrel{~}{Q}$ consists of the first m$m$ columns of Q$Q$.
(c) if mn$m\ge n$ and rank(A) = rn$\mathrm{rank}\left(A\right)=r\le n$ then A$A$ can be factorized using a QR$QR$ factorization, with column interchanges, as
A = Q
 ( R ) 0
PT,
$A=Q R 0 PT,$
where Q$Q$ is an m$m$ by m$m$ orthogonal matrix, R$R$ is an r$r$ by n$n$ upper trapezoidal matrix and P$P$ is an n$n$ by n$n$ permutation matrix. The pseudo-inverse of A$A$ is then given by
 A+ = PRT(RRT) − 1Q̃T, $A+=PRT(RRT)-1Q~T,$
where $\stackrel{~}{Q}$ consists of the first r$r$ columns of Q$Q$.
(d) if rank(A) = rk = min (m,n)$\mathrm{rank}\left(A\right)=r\le k=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$, then A$A$ can be factorized as the singular value decomposition
 A = UΣVT, $A=UΣVT,$
where U$U$ is an m$m$ by m$m$ orthogonal matrix, V$V$ is an n$n$ by n$n$ orthogonal matrix and Σ$\Sigma$ is an m$m$ by n$n$ diagonal matrix with non-negative diagonal elements σ$\sigma$. The first k$k$ columns of U$U$ and V$V$ are the left- and right-hand singular vectors of A$A$ respectively and the k$k$ diagonal elements of Σ$\Sigma$ are the singular values of A$A$. Σ$\Sigma$ may be chosen so that
 σ1 ≥ σ2 ≥ ⋯ ≥ σk ≥ 0 $σ1≥σ2≥⋯≥σk≥0$
and in this case if rank(A) = r$\mathrm{rank}\left(A\right)=r$ then
 σ1 ≥ σ2 ≥ ⋯ ≥ σr > 0,  σr + 1 = ⋯ = σk = 0. $σ1≥σ2≥⋯≥σr>0, σr+1=⋯=σk=0.$
If $\stackrel{~}{U}$ and $\stackrel{~}{V}$ consist of the first r$r$ columns of U$U$ and V$V$ respectively and Σ̃$\stackrel{~}{\Sigma }$ is an r$r$ by r$r$ diagonal matrix with diagonal elements σ1,σ2,,σr${\sigma }_{1},{\sigma }_{2},\dots ,{\sigma }_{r}$ then A$A$ is given by
 A = ŨΣ̃ṼT $A=U~Σ~V~T$
and the pseudo-inverse of A$A$ is given by
 A+ = ṼΣ̃ − 1ŨT. $A+=V~Σ~-1U~T.$
Notice that
 ATA = V(ΣTΣ)VT $ATA=V(ΣTΣ)VT$
which is the classical eigenvalue (spectral) factorization of ATA${A}^{\mathrm{T}}A$.
(e) if A$A$ is complex then the above relationships are still true if we use ‘unitary’ in place of ‘orthogonal’ and conjugate transpose in place of transpose. For example, the singular value decomposition of A$A$ is
 A = UΣVH, $A=UΣVH,$
where U$U$ and V$V$ are unitary, VH${V}^{\mathrm{H}}$ the conjugate transpose of V$V$ and Σ$\Sigma$ is as in (d) above.

### Matrix Factorizations

The functions in this section perform matrix factorizations which are required for the solution of systems of linear equations with various special structures. A few functions which perform associated computations are also included.
Other functions for matrix factorizations are to be found in Chapters F07, F08 and F11.
This section also contains a few functions associated with eigenvalue problems (see Chapter F02). (Historical note: this section used to contain many more such functions, but they have now been superseded by functions in Chapter F08.)

### Matrix Arithmetic and Manipulation

The intention of functions in this section (sub-chapters F01C, F01V and F01Z) is to cater for some of the commonly occurring operations in matrix manipulation, e.g., transposing a matrix or adding part of one matrix to another, and for conversion between different storage formats, e.g., conversion between rectangular band matrix storage and packed band matrix storage. For vector or matrix-vector or matrix-matrix operations refer to Chapter F16.

### Matrix Functions

Given a square matrix A$A$, the matrix function f(A)$f\left(A\right)$ is a matrix with the same dimensions as A$A$ which provides a generalization of the scalar function f$f$.
If A$A$ has a full set of eigenvectors V$V$ then A$A$ can be factorized as
 A = V D V − 1 , $A = V D V-1 ,$
where D$D$ is the diagonal matrix whose diagonal elements, di${d}_{i}$, are the eigenvalues of A$A$. f(A)$f\left(A\right)$ is given by
 f(A) = V f(D) V − 1 , $f(A) = V f(D) V-1 ,$
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)$.
In general, A$A$ may not have a full set of eigenvectors. The matrix function can then be defined via a Cauchy integral. For An × n$A\in {ℂ}^{n×n}$,
 f(A) = 1/(2π i) ∫Γ f(z) (zI − A) − 1 dz , $f(A) = 1 2π i ∫ Γ f(z) (zI-A)-1 dz ,$
where Γ$\Gamma$ is a closed contour surrounding the eigenvalues of A$A$, and f$f$ is analytic within Γ$\Gamma$.
Algorithms for computing matrix functions are usually tailored to a specific function. Currently Chapter F01 contains routines for calculating the exponential, logarithm, sine, cosine, sinh and cosh of both real and complex matrices. In addition there are routines to compute a general function of real symmetric and complex Hermitian matrices and a general function of general real and complex matrices.
The condition number of a matrix function is a measure of its sensitivity to perturbations in the data. Chapter F01 contains functions for estimating the condition number of the matrix exponential, logarithm, sine, cosine, sinh or cosh for real or complex matrices. It also contains functions for estimating the condition number of a general function of a real or complex matrix.

## Recommendations on Choice and Use of Available Functions

### Matrix Inversion

Note:  before using any function for matrix inversion, consider carefully whether it is really needed.
Although the solution of a set of linear equations Ax = b$Ax=b$ can be written as x = A1b$x={A}^{-1}b$, the solution should never be computed by first inverting A$A$ and then computing A1b${A}^{-1}b$; the functions in Chapters F04 or F07 should always be used to solve such sets of equations directly; they are faster in execution, and numerically more stable and accurate. Similar remarks apply to the solution of least squares problems which again should be solved by using the functions in Chapters F04 and F08 rather than by computing a pseudo-inverse.
 (a) Nonsingular square matrices of order n$n$ This chapter describes techniques for inverting a general real matrix A$A$ and matrices which are positive definite (have all eigenvalues positive) and are either real and symmetric or complex and Hermitian. It is wasteful and uneconomical not to use the appropriate function when a matrix is known to have one of these special forms. A general function must be used when the matrix is not known to be positive definite. In most functions the inverse is computed by solving the linear equations Axi = ei$A{x}_{\mathit{i}}={e}_{\mathit{i}}$, for i = 1,2, … ,n$\mathit{i}=1,2,\dots ,n$, where ei${e}_{i}$ is the i$i$th column of the identity matrix. Functions are given for calculating the approximate inverse, that is solving the linear equations just once, and also for obtaining the accurate inverse by successive iterative corrections of this first approximation. The latter, of course, are more costly in terms of time and storage, since each correction involves the solution of n$n$ sets of linear equations and since the original A$A$ and its LU$LU$ decomposition must be stored together with the first and successively corrected approximations to the inverse. In practice the storage requirements for the ‘corrected’ inverse functions are about double those of the ‘approximate’ inverse functions, though the extra computer time is not prohibitive since the same matrix and the same LU$LU$ decomposition is used in every linear equation solution. Despite the extra work of the ‘corrected’ inverse functions they are superior to the ‘approximate’ inverse functions. A correction provides a means of estimating the number of accurate figures in the inverse or the number of ‘meaningful’ figures relating to the degree of uncertainty in the coefficients of the matrix. The residual matrix R = AX − I$R=AX-I$, where X$X$ is a computed inverse of A$A$, conveys useful information. Firstly ‖R‖$‖R‖$ is a bound on the relative error in X$X$ and secondly ‖R‖ < (1/2) $‖R‖<\frac{1}{2}$ guarantees the convergence of the iterative process in the ‘corrected’ inverse functions. The decision trees for inversion show which functions in Chapter F04 and Chapter F07 should be used for the inversion of other special types of matrices not treated in the chapter. (b) General real rectangular matrices For real matrices nag_lapack_dgeqrf (f08ae) and nag_matop_real_gen_rq (f01qj) return QR$QR$ and RQ$RQ$ factorizations of A$A$ respectively and nag_lapack_dgeqp3 (f08bf) returns the QR$QR$ factorization with column interchanges. The corresponding complex functions are nag_lapack_zgeqrf (f08as), nag_matop_complex_gen_rq (f01rj) and nag_lapack_zgeqp3 (f08bt) respectively. Functions are also provided to form the orthogonal matrices and transform by the orthogonal matrices following the use of the above functions. nag_matop_real_trapez_rq (f01qg) and nag_matop_complex_trapez_rq (f01rg) form the RQ$RQ$ factorization of an upper trapezoidal matrix for the real and complex cases respectively. nag_matop_real_gen_pseudinv (f01bl) uses the QR$QR$ factorization as described in Section [Matrix Inversion](ii)(a) and is the only function that explicitly returns a pseudo-inverse. If m ≥ n$m\ge n$, then the function will calculate the pseudo-inverse A+${A}^{+}$ of the matrix A$A$. If m < n$m, then the n$n$ by m$m$ matrix AT${A}^{\mathrm{T}}$ should be used. The function will calculate the pseudo-inverse Z = (AT)+ = (A+)T$Z={\left({A}^{\mathrm{T}}\right)}^{+}={\left({A}^{+}\right)}^{\mathrm{T}}$ of AT${A}^{\mathrm{T}}$ and the required pseudo-inverse will be ZT${Z}^{\mathrm{T}}$. The function also attempts to calculate the rank, r$r$, of the matrix given a tolerance to decide when elements can be regarded as zero. However, should this function fail due to an incorrect determination of the rank, the singular value decomposition method (described below) should be used. nag_lapack_dgesvd (f08kb) and nag_lapack_zgesvd (f08kp) compute the singular value decomposition as described in Section [Background to the Problems] for real and complex matrices respectively. If A$A$ has rank r ≤ k = min (m,n)$r\le k=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,n\right)$ then the k − r$k-r$ smallest singular values will be negligible and the pseudo-inverse of A$A$ can be obtained as A+ = VΣ − 1UT${A}^{+}=V{\Sigma }^{-1}{U}^{\mathrm{T}}$ as described in Section [Background to the Problems]. If the rank of A$A$ is not known in advance it can be estimated from the singular values (see Section [The Rank of a Matrix] in the F04 Chapter Introduction). In the real case with m ≥ n$m\ge n$, nag_eigen_real_gen_qu_svd (f02wd) provides details of the QR$QR$ factorization or the singular value decomposition depending on whether or not A$A$ is of full rank and for some problems provides an attractive alternative to nag_lapack_dgesvd (f08kb). For large sparse matrices, leading terms in the singular value decomposition can be computed using functions from Chapter F12.

### Matrix Factorizations

Each of these functions serves a special purpose required for the solution of sets of simultaneous linear equations or the eigenvalue problem. For further details you should consult Sections [Recommendations on Choice and Use of Available Functions] or [Decision Trees] in the F02 Chapter Introduction or Sections [Recommendations on Choice and Use of Available Functions] or [Decision Trees] in the F04 Chapter Introduction.
nag_matop_real_gen_sparse_lu (f01br) and nag_matop_real_gen_sparse_lu_reuse (f01bs) are provided for factorizing general real sparse matrices. A more recent algorithm for the same problem is available through nag_sparse_direct_real_gen_lu (f11me). For factorizing real symmetric positive definite sparse matrices, see nag_sparse_real_symm_precon_ichol (f11ja). These functions should be used only when A$A$ is not banded and when the total number of nonzero elements is less than 10% of the total number of elements. In all other cases either the band functions or the general functions should be used.

### Matrix Arithmetic and Manipulation

The functions in the F01C section are designed for the general handling of m$m$ by n$n$ matrices. Emphasis has been placed on flexibility in the parameter specifications and on avoiding, where possible, the use of internally declared arrays. They are therefore suited for use with large matrices of variable row and column dimensions. Functions are included for the addition and subtraction of sub-matrices of larger matrices, as well as the standard manipulations of full matrices. Those functions involving matrix multiplication may use additional-precision arithmetic for the accumulation of inner products. See also .
The functions in the F01V (LAPACK) and F01Z section are designed to allow conversion between full storage format and one of the packed storage schemes required by some of the functions in Chapters F02, F04, F07 and F08.

#### NAG Names and LAPACK Names

Functions with NAG name beginning F01V may be called either by their NAG names or by their LAPACK names. When using the NAG Library, the double precision form of the LAPACK name must be used (beginning with D- or Z-).
References to Chapter F01 functions in the manual normally include the LAPACK double precision names, for example, nag_matop_dtrttf (f01ve).
The LAPACK function names follow a simple scheme (which is similar to that used for the BLAS in ). Most names have the structure XYYTZZ, where the components have the following meanings:
– the initial letter, X, indicates the data type (real or complex) and precision:
• S – real, single precision (in Fortran, 4 byte length REAL)
• D – real, double precision (in Fortran, 8 byte length REAL)
• C – complex, single precision (in Fortran, 8 byte length COMPLEX)
• Z – complex, double precision (in Fortran, 16 byte length COMPLEX)
– the fourth letter, T, indicates that the function is performing a storage scheme transformation (conversion)
– the letters YY indicate the original storage scheme used to store a triangular part of the matrix A$A$, while the letters ZZ indicate the target storage scheme of the conversion (YY cannot equal ZZ since this would do nothing):
• TF – Rectangular Full Packed Format (RFP)
• TP – Packed Format
• TR – Full Format

### Matrix Functions

nag_matop_real_gen_matrix_exp (f01ec) and nag_matop_complex_gen_matrix_exp (f01fc) compute the matrix exponential, eA${e}^{A}$, of a real and complex square matrix A$A$ respectively. If estimates of the condition number of the matrix exponential are required then nag_matop_real_gen_matrix_cond_std (f01ja) and nag_matop_complex_gen_matrix_cond_std (f01ka) should be used.
nag_matop_real_symm_matrix_exp (f01ed) and nag_matop_complex_herm_matrix_exp (f01fd) compute the matrix exponential, eA${e}^{A}$, of a real symmetric and complex Hermitian matrix respectively. If the matrix is real symmetric, or complex Hermitian then it is recommended that nag_matop_real_symm_matrix_exp (f01ed), or nag_matop_complex_herm_matrix_exp (f01fd) be used as they are more efficient and, in general, more accurate than nag_matop_real_gen_matrix_exp (f01ec) and nag_matop_complex_gen_matrix_exp (f01fc).
nag_matop_real_gen_matrix_log (f01ej) and nag_matop_complex_gen_matrix_log (f01fj) compute the principal matrix logarithm, log(A)$\mathrm{log}\left(A\right)$, of a real and complex square matrix A$A$ respectively. If estimates of the condition number of the matrix logarithm are required then nag_matop_real_gen_matrix_cond_std (f01ja) and nag_matop_complex_gen_matrix_cond_std (f01ka) should be used.
nag_matop_real_gen_matrix_fun_std (f01ek) and nag_matop_complex_gen_matrix_fun_std (f01fk) compute the matrix exponential, sine, cosine, sinh or cosh of a real and complex square matrix A$A$ respectively. If the matrix exponential is required then it is recommended that nag_matop_real_gen_matrix_exp (f01ec) or nag_matop_complex_gen_matrix_exp (f01fc) be used as they are, in general, more accurate than nag_matop_real_gen_matrix_fun_std (f01ek) and nag_matop_complex_gen_matrix_fun_std (f01fk). If estimates of the condition number of the matrix function are required then nag_matop_real_gen_matrix_cond_std (f01ja) and nag_matop_complex_gen_matrix_cond_std (f01ka) should be used.
nag_matop_real_gen_matrix_fun_num (f01el) and nag_matop_real_gen_matrix_fun_usd (f01em) compute the matrix function, f(A)$f\left(A\right)$, of a real square matrix. nag_matop_complex_gen_matrix_fun_num (f01fl) and nag_matop_complex_gen_matrix_fun_usd (f01fm) compute the matrix function of a complex square matrix. The derivatives of f$f$ are required for these computations. nag_matop_real_gen_matrix_fun_num (f01el) and nag_matop_complex_gen_matrix_fun_num (f01fl) use numerical differentiation to obtain the derivatives of f$f$. nag_matop_real_gen_matrix_fun_usd (f01em) and nag_matop_complex_gen_matrix_fun_usd (f01fm) use derivatives you have supplied. If estimates of the condition number of the matrix function are required and you are supplying derivatives of f$f$, then nag_matop_real_gen_matrix_cond_usd (f01jc) and nag_matop_complex_gen_matrix_cond_usd (f01kc) should be used. If estimates of the condition number are required but you are not supplying derivatives then nag_matop_real_gen_matrix_cond_num (f01jb) and nag_matop_complex_gen_matrix_cond_num (f01kb) should be used.
nag_matop_real_symm_matrix_fun (f01ef) and nag_matop_complex_herm_matrix_fun (f01ff) compute the matrix function, f(A)$f\left(A\right)$, of a real symmetric and complex Hermitian matrix A$A$ respectively. If the matrix is real symmetric or complex Hermitian then it is recommended that nag_matop_real_symm_matrix_fun (f01ef) or nag_matop_complex_herm_matrix_fun (f01ff) be used as they are more efficient and, in general, more accurate than nag_matop_real_gen_matrix_fun_num (f01el), nag_matop_real_gen_matrix_fun_usd (f01em), nag_matop_complex_gen_matrix_fun_num (f01fl) and nag_matop_complex_gen_matrix_fun_usd (f01fm).
nag_matop_real_gen_matrix_actexp (f01ga) and nag_matop_complex_gen_matrix_actexp (f01ha) compute the matrix function etAB${e}^{tA}B$ for explicitly stored dense real and complex matrices A$A$ and B$B$ respectively while nag_matop_real_gen_matrix_actexp_rcomm (f01gb) and nag_matop_complex_gen_matrix_actexp_rcomm (f01hb) compute the same using reverse communication. In the latter case, control is returned to you. You should calculate any required matrix-matrix products and then call the function again.

## Decision Trees

The decision trees show the functions in this chapter and in Chapter F04, Chapter F07 and Chapter F08 that should be used for inverting matrices of various types. They also show which function should be used to calculate various matrix functions.
(i) Matrix Inversion:

### Tree 1

 Is A$A$ an n$n$ by n$n$ matrix of rank n$n$? _yes Is A$A$ a real matrix? _yes see Tree 2 | no| | see Tree 3 no| see Tree 4

### Tree 2: Inverse of a real n by n matrix of full rank

 Is A$A$ a band matrix? _yes See Note 1. no| Is A$A$ symmetric? _yes Is A$A$ positive definite? _yes Do you want guaranteed accuracy? (See Note 2) _yes nag_matop_real_symm_posdef_inv (f01ab) | | no| | | Is one triangle of A$A$ stored as a linear array? _yes nag_lapack_dpptrf (f07gd) and nag_lapack_dpptri (f07gj) | | no| | | nag_matop_real_symm_posdef_inv_noref (f01ad) or nag_lapack_dpotrf (f07fd) and nag_lapack_dpotri (f07fj) | no| | Is one triangle of A$A$ stored as a linear array? _yes nag_lapack_dsptrf (f07pd) and nag_lapack_dsptri (f07pj) | no| | nag_lapack_dsytrf (f07md) and nag_lapack_dsytri (f07mj) no| Is A$A$ triangular? _yes Is A$A$ stored as a linear array? _yes nag_lapack_dtptri (f07uj) | no| | nag_lapack_dtrtri (f07tj) no| Do you want guaranteed accuracy? (See Note 2) _yes nag_linsys_real_square_solve_ref (f04ae) no| nag_lapack_dgetrf (f07ad) and nag_lapack_dgetri (f07aj)

### Tree 3: Inverse of a complex n by n matrix of full rank

 Is A$A$ a band matrix? _yes See Note 1. no| Is A$A$ Hermitian? _yes Is A$A$ positive definite? _yes Is one triangle of A$A$ stored as a linear array? _yes nag_lapack_zpptrf (f07gr) and nag_lapack_zpptri (f07gw) | | no| | | nag_lapack_zpotrf (f07fr) and nag_lapack_zpotri (f07fw) | no| | Is one triangle A$A$ stored as a linear array? _yes nag_lapack_zhptrf (f07pr) and nag_lapack_zhptri (f07pw) | no| | nag_lapack_zhetrf (f07mr) and nag_lapack_zhetri (f07mw) no| Is A$A$ symmetric? _yes Is one triangle of A$A$ stored as a linear array? _yes nag_lapack_zsptrf (f07qr) and nag_lapack_zsptri (f07qw) | no| | nag_lapack_zsytrf (f07nr) and nag_lapack_zsytri (f07nw) no| Is A$A$ triangular? _yes Is A$A$ stored as a linear array? _yes nag_lapack_ztptri (f07uw) | no| | nag_lapack_ztrtri (f07tw) no| nag_lapack_zgesv (f07an) or nag_lapack_zgetrf (f07ar) and nag_lapack_zgetri (f07aw)

### Tree 4: Pseudo-inverses

 Is A$A$ a complex matrix? _yes Is A$A$ of full rank? _yes Is A$A$ an m$m$ by n$n$ matrix with m < n$m? _yes nag_matop_complex_gen_rq (f01rj) and nag_matop_complex_gen_rq_formq (f01rk) | | no| | | nag_lapack_zgeqrf (f08as) and nag_lapack_zunmqr (f08au) or nag_lapack_zungqr (f08at) | no| | nag_lapack_zgesvd (f08kp) no| Is A$A$ of full rank? _yes Is A$A$ an m$m$ by n$n$ matrix with m < n$m? _yes nag_matop_real_gen_rq (f01qj) and nag_matop_real_gen_rq_formq (f01qk) | no| | nag_lapack_dgeqrf (f08ae) and nag_lapack_dormqr (f08ag) or nag_lapack_dorgqr (f08af) no| Is A$A$ an m$m$ by n$n$ matrix with m < n$m? _yes nag_lapack_dgesvd (f08kb) no| Is reliability more important than efficiency? _yes nag_lapack_dgesvd (f08kb) no| nag_matop_real_gen_pseudinv (f01bl)
Note 1: the inverse of a band matrix A$A$ does not in general have the same shape as A$A$, and no functions are provided specifically for finding such an inverse. The matrix must either be treated as a full matrix, or the equations AX = B$AX=B$ must be solved, where B$B$ has been initialized to the identity matrix I$I$. In the latter case, see the decision trees in Section [Decision Trees] in the F04 Chapter Introduction.
Note 2: by ‘guaranteed accuracy’ we mean that the accuracy of the inverse is improved by use of the iterative refinement technique using additional precision.
(ii) Matrix Factorizations: see the decision trees in Section [Decision Trees] in the F02 and F04 Chapter Introductions.
(iii) Matrix Arithmetic and Manipulation: not appropriate.
(iv) Matrix Functions:

### Tree 5: Matrix functions f(A)$f\left(A\right)$ of an n by n real matrix A$A$

 Is etAB${e}^{tA}B$ required? _yes Is A$A$ stored in dense format? _yes nag_matop_real_gen_matrix_actexp (f01ga) | no| | nag_matop_real_gen_matrix_actexp_rcomm (f01gb) no| Is A$A$ real symmetric? _yes Is eA${e}^{A}$ required? _yes nag_matop_real_symm_matrix_exp (f01ed) | no| | nag_matop_real_symm_matrix_fun (f01ef) no| Is cos(A)$\mathrm{cos}\left(A\right)$ or cosh(A)$\mathrm{cosh}\left(A\right)$ or sin(A)$\mathrm{sin}\left(A\right)$ or sinh(A)$\mathrm{sinh}\left(A\right)$ required? _yes Is the condition number of the matrix function required? _yes nag_matop_real_gen_matrix_cond_std (f01ja) | no| | nag_matop_real_gen_matrix_fun_std (f01ek) no| Is log(A)$\mathrm{log}\left(A\right)$ required? _yes Is the condition number of the matrix logarithm required? _yes nag_matop_real_gen_matrix_cond_std (f01ja) | no| | nag_matop_real_gen_matrix_log (f01ej) no| Is exp(A)$\mathrm{exp}\left(A\right)$ required? _yes Is the condition number of the matrix exponential required? _yes nag_matop_real_gen_matrix_cond_std (f01ja) | no| | nag_matop_real_gen_matrix_exp (f01ec) no| f(A)$f\left(A\right)$ will be computed. Will derivatives of f$f$ be supplied by the user? _yes Is the condition number of the matrix function required? _yes nag_matop_real_gen_matrix_cond_usd (f01jc) | no| | nag_matop_real_gen_matrix_fun_usd (f01em) no| Is the condition number of the matrix function required? _yes nag_matop_real_gen_matrix_cond_num (f01jb) no| nag_matop_real_gen_matrix_fun_num (f01el)

### Tree 6: Matrix functions f(A)$f\left(A\right)$ of an n by n complex matrix A$A$

 Is etAB${e}^{tA}B$ required? _yes Is A$A$ stored in dense format? _yes nag_matop_complex_gen_matrix_actexp (f01ha) | no| | nag_matop_complex_gen_matrix_actexp_rcomm (f01hb) no| Is A$A$ complex Hermitian? _yes Is eA${e}^{A}$ required? _yes nag_matop_complex_herm_matrix_exp (f01fd) | no| | nag_matop_complex_herm_matrix_fun (f01ff) no| Is cos(A)$\mathrm{cos}\left(A\right)$ or cosh(A)$\mathrm{cosh}\left(A\right)$ or sin(A)$\mathrm{sin}\left(A\right)$ or sinh(A)$\mathrm{sinh}\left(A\right)$ required? _yes Is the condition number of the matrix function required? _yes nag_matop_complex_gen_matrix_cond_std (f01ka) | no| | nag_matop_complex_gen_matrix_fun_std (f01fk) no| Is log(A)$\mathrm{log}\left(A\right)$ required? _yes Is the condition number of the matrix logarithm required? _yes nag_matop_complex_gen_matrix_cond_std (f01ka) | no| | nag_matop_complex_gen_matrix_log (f01fj) no| Is exp(A)$\mathrm{exp}\left(A\right)$ required? _yes Is the condition number of the matrix exponential required? _yes nag_matop_complex_gen_matrix_cond_std (f01ka) | no| | nag_matop_complex_gen_matrix_exp (f01fc) no| f(A)$f\left(A\right)$ will be computed. Will derivatives of f$f$ be supplied by the user? _yes Is the condition number of the matrix function required? _yes nag_matop_complex_gen_matrix_cond_usd (f01kc) | no| | nag_matop_complex_gen_matrix_fun_usd (f01fm) no| Is the condition number of the matrix function required? _yes nag_matop_complex_gen_matrix_cond_num (f01kb) no| nag_matop_complex_gen_matrix_fun_num (f01fl)

## Functionality Index

 Action of the matrix exponential on a complex matrix nag_matop_complex_gen_matrix_actexp (f01ha)
 Action of the matrix exponential on a complex matrix (reverse communication) nag_matop_complex_gen_matrix_actexp_rcomm (f01hb)
 Action of the matrix exponential on a real matrix nag_matop_real_gen_matrix_actexp (f01ga)
 Action of the matrix exponential on a real matrix (reverse communication) nag_matop_real_gen_matrix_actexp_rcomm (f01gb)
 Inversion (also see Chapter F07),
 real m by n matrix,
 pseudo-inverse nag_matop_real_gen_pseudinv (f01bl)
 real symmetric positive definite matrix,
 accurate inverse nag_matop_real_symm_posdef_inv (f01ab)
 Matrix Arithmetic and Manipulation,
 matrix multiplication nag_matop_real_gen_matmul (f01ck)
 matrix storage conversion,
 full to packed triangular storage,
 complex matrices nag_matop_ztrttp (f01vb)
 real matrices nag_matop_dtrttp (f01va)
 full to Rectangular Full Packed storage,
 complex matrix nag_matop_ztrttf (f01vf)
 real matrix nag_matop_dtrttf (f01ve)
 packed band  ↔  rectangular storage, special provision for diagonal
 complex matrices nag_matop_complex_band_pack (f01zd)
 real matrices nag_matop_real_band_pack (f01zc)
 packed triangular to full storage,
 complex matrices nag_matop_ztpttr (f01vd)
 real matrices nag_matop_dtpttr (f01vc)
 packed triangular to Rectangular Full Packed storage,
 complex matrices nag_matop_ztpttf (f01vk)
 real matrices nag_matop_dtpttf (f01vj)
 packed triangular  ↔  square storage, special provision for diagonal
 complex matrices nag_matop_complex_tri_pack (f01zb)
 real matrices nag_matop_real_tri_pack (f01za)
 Rectangular Full Packed to full storage,
 complex matrices nag_matop_ztfttr (f01vh)
 real matrices nag_matop_dtfttr (f01vg)
 Rectangular Full Packed to packed triangular storage,
 complex matrices nag_matop_ztfttp (f01vm)
 real matrices nag_matop_dtfttp (f01vl)
 matrix subtraction,
 matrix transpose nag_matop_real_gen_trans_inplace (f01cr)
 Matrix function,
 complex Hermitian n by n matrix,
 matrix exponential nag_matop_complex_herm_matrix_exp (f01fd)
 matrix function nag_matop_complex_herm_matrix_fun (f01ff)
 complex n by n matrix,
 condition number for a matrix exponential, logarithm, sine, cosine, sinh or cosh nag_matop_complex_gen_matrix_cond_std (f01ka)
 condition number for a matrix function, using numerical differentiation nag_matop_complex_gen_matrix_cond_num (f01kb)
 condition number for a matrix function, using user-supplied derivatives nag_matop_complex_gen_matrix_cond_usd (f01kc)
 matrix exponential nag_matop_complex_gen_matrix_exp (f01fc)
 matrix exponential, sine, cosine, sinh or cosh nag_matop_complex_gen_matrix_fun_std (f01fk)
 matrix function, using numerical differentiation nag_matop_complex_gen_matrix_fun_num (f01fl)
 matrix function, using user-supplied derivatives nag_matop_complex_gen_matrix_fun_usd (f01fm)
 matrix logarithm nag_matop_complex_gen_matrix_log (f01fj)
 real n by n matrix,
 condition number for a matrix function, using numerical differentiation nag_matop_real_gen_matrix_cond_num (f01jb)
 condition number for a matrix function, using user-supplied derivatives nag_matop_real_gen_matrix_cond_usd (f01jc)
 condition number for the matrix exponential, logarithm, sine, cosine, sinh or cosh nag_matop_real_gen_matrix_cond_std (f01ja)
 matrix exponential nag_matop_real_gen_matrix_exp (f01ec)
 matrix exponential, sine, cosine, sinh or cosh nag_matop_real_gen_matrix_fun_std (f01ek)
 matrix function, using numerical differentiation nag_matop_real_gen_matrix_fun_num (f01el)
 matrix function, using user-supplied derivatives nag_matop_real_gen_matrix_fun_usd (f01em)
 matrix logarithm nag_matop_real_gen_matrix_log (f01ej)
 real symmetric n by n matrix,
 matrix exponential nag_matop_real_symm_matrix_exp (f01ed)
 matrix function nag_matop_real_symm_matrix_fun (f01ef)
 Matrix Transformations,
 complex matrix, form unitary matrix nag_matop_complex_gen_rq_formq (f01rk)
 complex m by n(m ≤ n) matrix,
 RQ factorization nag_matop_complex_gen_rq (f01rj)
 complex upper trapezoidal matrix,
 RQ factorization nag_matop_complex_trapez_rq (f01rg)
 eigenproblem Ax = λBx, A, B banded,
 reduction to standard symmetric problem nag_matop_real_symm_posdef_geneig (f01bv)
 real almost block-diagonal matrix,
 LU factorization nag_matop_real_gen_blkdiag_lu (f01lh)
 real band symmetric positive definite matrix,
 ULDLTUT factorization nag_matop_real_symm_posdef_fac (f01bu)
 variable bandwidth, LDLT factorization nag_matop_real_vband_posdef_fac (f01mc)
 real matrix,
 form orthogonal matrix nag_matop_real_gen_rq_formq (f01qk)
 real m by n(m  ≤  n) matrix,
 RQ factorization nag_matop_real_gen_rq (f01qj)
 real sparse matrix,
 factorization nag_matop_real_gen_sparse_lu (f01br)
 factorization, known sparsity pattern nag_matop_real_gen_sparse_lu_reuse (f01bs)
 real upper trapezoidal matrix,
 RQ factorization nag_matop_real_trapez_rq (f01qg)
 tridiagonal matrix,
 LU factorization nag_matop_real_gen_tridiag_lu (f01le)

## References

Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Higham N J (2008) Functions of Matrices: Theory and Computation SIAM, Philadelphia, PA, USA
Wilkinson J H (1965) The Algebraic Eigenvalue Problem Oxford University Press, Oxford
Wilkinson J H (1977) Some recent advances in numerical linear algebra The State of the Art in Numerical Analysis (ed D A H Jacobs) Academic Press
Wilkinson J H and Reinsch C (1971) Handbook for Automatic Computation II, Linear Algebra Springer–Verlag